Skip to content

Commit 5a680ad

Browse files
committed
Fix default sync interval
The sync default sync interval was changed to 12 hours, but there is also a CLI option that also configures the sync interval. The OLMConfig reconcile code did not properly handle the value coming in via the CLI, and changing the sync interval from the default without an OLMConfig value specified. The CLI option now changes the default sync interval, when the OLMConfig is not present. The 12h default sync interval is used when neither the CLI nor the OLMConfig is specified. The OLMConfig reconcile code now uses the CLI option as the default. Signed-off-by: Todd Short <[email protected]>
1 parent 108d6db commit 5a680ad

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

deploy/chart/templates/_packageserver.deployment-spec.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ spec:
4747
{{- if .Values.debug }}
4848
- --debug
4949
{{- end }}
50+
{{- if .Values.package.interval }}
51+
- --interval
52+
- {{ .Values.package.interval }}
53+
{{- end }}
5054
{{- if .Values.package.commandArgs }}
5155
- {{ .Values.package.commandArgs }}
5256
{{- end }}

pkg/package-server/server/server.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewCommandStartPackageServer(ctx context.Context, defaults *PackageServerOp
5252
}
5353

5454
flags := cmd.Flags()
55-
flags.DurationVar(&defaults.SyncInterval, "interval", defaults.SyncInterval, "interval at which to re-sync CatalogSources")
55+
flags.DurationVar(&defaults.DefaultSyncInterval, "interval", defaults.DefaultSyncInterval, "default interval at which to re-sync CatalogSources")
5656
flags.StringVar(&defaults.GlobalNamespace, "global-namespace", defaults.GlobalNamespace, "Name of the namespace where the global CatalogSources are located")
5757
flags.StringVar(&defaults.Kubeconfig, "kubeconfig", defaults.Kubeconfig, "path to the kubeconfig used to connect to the Kubernetes API server and the Kubelets (defaults to in-cluster config)")
5858
flags.BoolVar(&defaults.Debug, "debug", defaults.Debug, "use debug log level")
@@ -71,8 +71,9 @@ type PackageServerOptions struct {
7171
Authorization *genericoptions.DelegatingAuthorizationOptions
7272
Features *genericoptions.FeatureOptions
7373

74-
GlobalNamespace string
75-
SyncInterval time.Duration
74+
GlobalNamespace string
75+
DefaultSyncInterval time.Duration
76+
CurrentSyncInterval time.Duration
7677

7778
Kubeconfig string
7879
RegistryAddr string
@@ -95,7 +96,8 @@ func NewPackageServerOptions(out, errOut io.Writer) *PackageServerOptions {
9596
Authorization: genericoptions.NewDelegatingAuthorizationOptions(),
9697
Features: genericoptions.NewFeatureOptions(),
9798

98-
SyncInterval: DefaultWakeupInterval,
99+
DefaultSyncInterval: DefaultWakeupInterval,
100+
CurrentSyncInterval: DefaultWakeupInterval,
99101

100102
DisableAuthForTesting: false,
101103
Debug: false,
@@ -249,20 +251,25 @@ func (o *PackageServerOptions) Run(ctx context.Context) error {
249251
return err
250252
}
251253

252-
// Grab the Sync config
254+
// Use the interval from the CLI as default
255+
if o.CurrentSyncInterval != o.DefaultSyncInterval {
256+
log.Infof("CLI argument changed default from '%v' to '%v'", o.CurrentSyncInterval, o.DefaultSyncInterval)
257+
o.CurrentSyncInterval = o.DefaultSyncInterval
258+
}
259+
// Use the interval from the OLMConfig
253260
cfg, err := crClient.OperatorsV1().OLMConfigs().Get(ctx, "cluster", metav1.GetOptions{})
254261
if err != nil {
255262
log.Warnf("Error retrieving Interval from OLMConfig: '%v'", err)
256263
} else {
257264
if cfg.Spec.Features != nil && cfg.Spec.Features.PackageServerSyncInterval != nil {
258-
o.SyncInterval = cfg.Spec.Features.PackageServerSyncInterval.Duration
259-
log.Infof("Retrieved Interval from OLMConfig: '%v'", o.SyncInterval.String())
265+
o.CurrentSyncInterval = cfg.Spec.Features.PackageServerSyncInterval.Duration
266+
log.Infof("Retrieved Interval from OLMConfig: '%v'", o.CurrentSyncInterval.String())
260267
} else {
261-
log.Infof("Defaulting Interval to '%v'", DefaultWakeupInterval)
268+
log.Infof("Defaulting Interval to '%v'", o.DefaultSyncInterval)
262269
}
263270
}
264271

265-
sourceProvider, err := provider.NewRegistryProvider(ctx, crClient, queueOperator, o.SyncInterval, o.GlobalNamespace)
272+
sourceProvider, err := provider.NewRegistryProvider(ctx, crClient, queueOperator, o.CurrentSyncInterval, o.GlobalNamespace)
266273
if err != nil {
267274
return err
268275
}
@@ -294,13 +301,13 @@ func (op *Operator) syncOLMConfig(obj interface{}) error {
294301
}
295302
// restart the pod on change
296303
if olmConfig.Spec.Features == nil || olmConfig.Spec.Features.PackageServerSyncInterval == nil {
297-
if op.options.SyncInterval != DefaultWakeupInterval {
298-
log.Warnf("Change to olmConfig: '%v' != default '%v'", op.options.SyncInterval, DefaultWakeupInterval)
304+
if op.options.CurrentSyncInterval != op.options.DefaultSyncInterval {
305+
log.Warnf("Change to olmConfig: '%v' != default '%v'", op.options.CurrentSyncInterval, op.options.DefaultSyncInterval)
299306
os.Exit(0)
300307
}
301308
} else {
302-
if op.options.SyncInterval != olmConfig.Spec.Features.PackageServerSyncInterval.Duration {
303-
log.Warnf("Change to olmConfig: old '%v' != new '%v'", op.options.SyncInterval, olmConfig.Spec.Features.PackageServerSyncInterval.Duration)
309+
if op.options.CurrentSyncInterval != olmConfig.Spec.Features.PackageServerSyncInterval.Duration {
310+
log.Warnf("Change to olmConfig: old '%v' != new '%v'", op.options.CurrentSyncInterval, olmConfig.Spec.Features.PackageServerSyncInterval.Duration)
304311
os.Exit(0)
305312
}
306313
}

test/e2e/e2e-bare-values.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ package:
2828
service:
2929
internalPort: 5443
3030
commandArgs: -test.coverprofile=/tmp/catalog-coverage.cov
31+
interval: 1h
3132

3233
e2e:
3334
image:

test/e2e/e2e-values.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package:
2424
pullPolicy: IfNotPresent
2525
service:
2626
internalPort: 5443
27+
interval: 1h
2728

2829
e2e:
2930
image:

0 commit comments

Comments
 (0)