Skip to content

Commit

Permalink
Fix default sync interval
Browse files Browse the repository at this point in the history
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 <todd.short@me.com>
  • Loading branch information
tmshort committed Oct 5, 2023
1 parent 108d6db commit 5a680ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
4 changes: 4 additions & 0 deletions deploy/chart/templates/_packageserver.deployment-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ spec:
{{- if .Values.debug }}
- --debug
{{- end }}
{{- if .Values.package.interval }}
- --interval
- {{ .Values.package.interval }}
{{- end }}
{{- if .Values.package.commandArgs }}
- {{ .Values.package.commandArgs }}
{{- end }}
Expand Down
33 changes: 20 additions & 13 deletions pkg/package-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewCommandStartPackageServer(ctx context.Context, defaults *PackageServerOp
}

flags := cmd.Flags()
flags.DurationVar(&defaults.SyncInterval, "interval", defaults.SyncInterval, "interval at which to re-sync CatalogSources")
flags.DurationVar(&defaults.DefaultSyncInterval, "interval", defaults.DefaultSyncInterval, "default interval at which to re-sync CatalogSources")
flags.StringVar(&defaults.GlobalNamespace, "global-namespace", defaults.GlobalNamespace, "Name of the namespace where the global CatalogSources are located")
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)")
flags.BoolVar(&defaults.Debug, "debug", defaults.Debug, "use debug log level")
Expand All @@ -71,8 +71,9 @@ type PackageServerOptions struct {
Authorization *genericoptions.DelegatingAuthorizationOptions
Features *genericoptions.FeatureOptions

GlobalNamespace string
SyncInterval time.Duration
GlobalNamespace string
DefaultSyncInterval time.Duration
CurrentSyncInterval time.Duration

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

SyncInterval: DefaultWakeupInterval,
DefaultSyncInterval: DefaultWakeupInterval,
CurrentSyncInterval: DefaultWakeupInterval,

DisableAuthForTesting: false,
Debug: false,
Expand Down Expand Up @@ -249,20 +251,25 @@ func (o *PackageServerOptions) Run(ctx context.Context) error {
return err
}

// Grab the Sync config
// Use the interval from the CLI as default
if o.CurrentSyncInterval != o.DefaultSyncInterval {
log.Infof("CLI argument changed default from '%v' to '%v'", o.CurrentSyncInterval, o.DefaultSyncInterval)
o.CurrentSyncInterval = o.DefaultSyncInterval
}
// Use the interval from the OLMConfig
cfg, err := crClient.OperatorsV1().OLMConfigs().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
log.Warnf("Error retrieving Interval from OLMConfig: '%v'", err)
} else {
if cfg.Spec.Features != nil && cfg.Spec.Features.PackageServerSyncInterval != nil {
o.SyncInterval = cfg.Spec.Features.PackageServerSyncInterval.Duration
log.Infof("Retrieved Interval from OLMConfig: '%v'", o.SyncInterval.String())
o.CurrentSyncInterval = cfg.Spec.Features.PackageServerSyncInterval.Duration
log.Infof("Retrieved Interval from OLMConfig: '%v'", o.CurrentSyncInterval.String())
} else {
log.Infof("Defaulting Interval to '%v'", DefaultWakeupInterval)
log.Infof("Defaulting Interval to '%v'", o.DefaultSyncInterval)
}
}

sourceProvider, err := provider.NewRegistryProvider(ctx, crClient, queueOperator, o.SyncInterval, o.GlobalNamespace)
sourceProvider, err := provider.NewRegistryProvider(ctx, crClient, queueOperator, o.CurrentSyncInterval, o.GlobalNamespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -294,13 +301,13 @@ func (op *Operator) syncOLMConfig(obj interface{}) error {
}
// restart the pod on change
if olmConfig.Spec.Features == nil || olmConfig.Spec.Features.PackageServerSyncInterval == nil {
if op.options.SyncInterval != DefaultWakeupInterval {
log.Warnf("Change to olmConfig: '%v' != default '%v'", op.options.SyncInterval, DefaultWakeupInterval)
if op.options.CurrentSyncInterval != op.options.DefaultSyncInterval {
log.Warnf("Change to olmConfig: '%v' != default '%v'", op.options.CurrentSyncInterval, op.options.DefaultSyncInterval)
os.Exit(0)
}
} else {
if op.options.SyncInterval != olmConfig.Spec.Features.PackageServerSyncInterval.Duration {
log.Warnf("Change to olmConfig: old '%v' != new '%v'", op.options.SyncInterval, olmConfig.Spec.Features.PackageServerSyncInterval.Duration)
if op.options.CurrentSyncInterval != olmConfig.Spec.Features.PackageServerSyncInterval.Duration {
log.Warnf("Change to olmConfig: old '%v' != new '%v'", op.options.CurrentSyncInterval, olmConfig.Spec.Features.PackageServerSyncInterval.Duration)
os.Exit(0)
}
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e-bare-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package:
service:
internalPort: 5443
commandArgs: -test.coverprofile=/tmp/catalog-coverage.cov
interval: 1h

e2e:
image:
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package:
pullPolicy: IfNotPresent
service:
internalPort: 5443
interval: 1h

e2e:
image:
Expand Down

0 comments on commit 5a680ad

Please sign in to comment.