Skip to content

Commit

Permalink
CCXDEV-12194: read configmap during configmap observer init (openshif…
Browse files Browse the repository at this point in the history
…t#864)

* read configmap during configmap observer init

* fix logging
  • Loading branch information
tremes authored and rluders committed Nov 29, 2023
1 parent 0116d3e commit 29f4f36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pkg/config/configobserver/configmapobserver.go
Expand Up @@ -40,7 +40,7 @@ type ConfigMapObserver struct {
listeners map[chan struct{}]struct{}
}

func NewConfigMapObserver(kubeConfig *rest.Config,
func NewConfigMapObserver(ctx context.Context, kubeConfig *rest.Config,
eventRecorder events.Recorder,
kubeInformer v1helpers.KubeInformersForNamespaces) (ConfigMapInformer, error) {
cmInformer := kubeInformer.InformersFor(insightsNamespaceName).Core().V1().ConfigMaps().Informer()
Expand All @@ -60,6 +60,17 @@ func NewConfigMapObserver(kubeConfig *rest.Config,
ToController("ConfigController", eventRecorder)

ctrl.Controller = factoryCtrl
cm, err := getConfigMap(ctx, kubeClient)
if err != nil {
klog.Warningf("Cannot get the configuration config map: %v. Default configuration is used.", err)
return ctrl, nil
}
insightsConfig, err := readConfigAndDecode(cm)
if err != nil {
klog.Warningf("Failed to read the configuration during start: %v. Default configuration is used.", err)
return ctrl, nil
}
ctrl.insightsConfig = insightsConfig
return ctrl, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/operator.go
Expand Up @@ -152,7 +152,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
}

kubeInf := v1helpers.NewKubeInformersForNamespaces(kubeClient, "openshift-insights")
configMapObserver, err := configobserver.NewConfigMapObserver(gatherKubeConfig, controller.EventRecorder, kubeInf)
configMapObserver, err := configobserver.NewConfigMapObserver(ctx, gatherKubeConfig, controller.EventRecorder, kubeInf)
if err != nil {
return err
}
Expand Down

0 comments on commit 29f4f36

Please sign in to comment.