From ec773dc5c51e4f3933b663ae1e831e15ea62c062 Mon Sep 17 00:00:00 2001 From: liranmauda Date: Sun, 11 Aug 2024 13:26:30 +0300 Subject: [PATCH] Add NOOBAA_LOG_LEVEL to the agent pod - Add NOOBAA_LOG_LEVEL to the agent pod - Watching for changes in the noobaa-config on the backingstore reconciler - Updating the NOOBAA_LOG_LEVEL according to the config map Signed-off-by: liranmauda --- deploy/internal/pod-agent.yaml | 1 + pkg/backingstore/reconciler.go | 22 ++++++++++++++++++- pkg/bundle/deploy.go | 3 ++- .../backingstore/backingstore_controller.go | 10 +++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/deploy/internal/pod-agent.yaml b/deploy/internal/pod-agent.yaml index 20e4be92d..858206fbf 100644 --- a/deploy/internal/pod-agent.yaml +++ b/deploy/internal/pod-agent.yaml @@ -22,6 +22,7 @@ spec: - name: CONTAINER_PLATFORM value: KUBERNETES - name: AGENT_CONFIG + - name: NOOBAA_LOG_LEVEL command: ["/noobaa_init_files/noobaa_init.sh", "agent"] # Insert the relevant image for the agent ports: diff --git a/pkg/backingstore/reconciler.go b/pkg/backingstore/reconciler.go index c25339a06..4e2356b6f 100644 --- a/pkg/backingstore/reconciler.go +++ b/pkg/backingstore/reconciler.go @@ -81,6 +81,7 @@ type Reconciler struct { PodAgentTemplate *corev1.Pod PvcAgentTemplate *corev1.PersistentVolumeClaim ServiceAccount *corev1.ServiceAccount + CoreAppConfig *corev1.ConfigMap SystemInfo *nb.SystemInfo ExternalConnectionInfo *nb.ExternalConnectionInfo @@ -118,6 +119,7 @@ func NewReconciler( NooBaa: util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_noobaa_cr_yaml).(*nbv1.NooBaa), Secret: util.KubeObject(bundle.File_deploy_internal_secret_empty_yaml).(*corev1.Secret), ServiceAccount: util.KubeObject(bundle.File_deploy_service_account_yaml).(*corev1.ServiceAccount), + CoreAppConfig: util.KubeObject(bundle.File_deploy_internal_configmap_empty_yaml).(*corev1.ConfigMap), PodAgentTemplate: util.KubeObject(bundle.File_deploy_internal_pod_agent_yaml).(*corev1.Pod), PvcAgentTemplate: util.KubeObject(bundle.File_deploy_internal_pvc_agent_yaml).(*corev1.PersistentVolumeClaim), } @@ -126,11 +128,13 @@ func NewReconciler( r.BackingStore.Namespace = r.Request.Namespace r.NooBaa.Namespace = r.Request.Namespace r.ServiceAccount.Namespace = r.Request.Namespace + r.CoreAppConfig.Namespace = r.Request.Namespace // Set Names r.BackingStore.Name = r.Request.Name r.NooBaa.Name = options.SystemName r.ServiceAccount.Name = options.SystemName + r.CoreAppConfig.Name = "noobaa-config" // Set secret names to empty r.Secret.Namespace = "" @@ -928,7 +932,7 @@ func (r *Reconciler) CheckExternalConnection(connInfo *nb.CheckExternalConnectio case nb.ExternalConnectionInvalidCredentials: if time.Since(r.BackingStore.CreationTimestamp.Time) < 5*time.Minute { r.Logger.Infof("got invalid credentials. sometimes access keys take time to propagate inside AWS. requeuing for 5 minutes") - return fmt.Errorf("Got InvalidCredentials. requeue again") + return fmt.Errorf("got InvalidCredentials. requeue again") } fallthrough case nb.ExternalConnectionInvalidEndpoint: @@ -957,6 +961,10 @@ func (r *Reconciler) CheckExternalConnection(connInfo *nb.CheckExternalConnectio // ReconcilePool handles the pool using noobaa api func (r *Reconciler) ReconcilePool() error { + if !util.KubeCheck(r.CoreAppConfig) { + r.Logger.Warnf("Could not find NooBaa config map") + } + // TODO we only support creation here, but not updates - just for pvpool if r.PoolInfo != nil { if r.BackingStore.Spec.Type == nbv1.StoreTypePVPool { @@ -1160,6 +1168,16 @@ func (r *Reconciler) needUpdate(pod *corev1.Pod) bool { return true } } + + var noobaaLogEnv = "NOOBAA_LOG_LEVEL" + var configMapLogLevel = r.CoreAppConfig.Data[noobaaLogEnv] + noobaaLogEnvVar := util.GetEnvVariable(&c.Env, noobaaLogEnv) + + if (configMapLogLevel != noobaaLogEnvVar.Value) { + r.Logger.Warnf("NOOBAA_LOG_LEVEL Env variable change detected: (%v) on the config map (%v)", noobaaLogEnvVar.Value, configMapLogLevel) + return true + } + if c.Image != r.NooBaa.Status.ActualImage { r.Logger.Warnf("Change in Image detected: current image(%v) noobaa image(%v)", c.Image, r.NooBaa.Status.ActualImage) return true @@ -1268,6 +1286,8 @@ func (r *Reconciler) updatePodTemplate() error { Key: "AGENT_CONFIG", }, } + case "NOOBAA_LOG_LEVEL": + c.Env[j].Value = r.CoreAppConfig.Data["NOOBAA_LOG_LEVEL"] } } util.ReflectEnvVariable(&c.Env, "HTTP_PROXY") diff --git a/pkg/bundle/deploy.go b/pkg/bundle/deploy.go index 0700018cf..7df756542 100644 --- a/pkg/bundle/deploy.go +++ b/pkg/bundle/deploy.go @@ -4330,7 +4330,7 @@ spec: storage: 30Gi ` -const Sha256_deploy_internal_pod_agent_yaml = "208a74bcb0238999af0f70fcb6a92389d7cf960b94b469a2b7cfd62d06b66d6f" +const Sha256_deploy_internal_pod_agent_yaml = "7e3cfc034b4fc19567cdc429abaeb7726f69c728f5be360c15cb1a1951443d5d" const File_deploy_internal_pod_agent_yaml = `apiVersion: v1 kind: Pod @@ -4356,6 +4356,7 @@ spec: - name: CONTAINER_PLATFORM value: KUBERNETES - name: AGENT_CONFIG + - name: NOOBAA_LOG_LEVEL command: ["/noobaa_init_files/noobaa_init.sh", "agent"] # Insert the relevant image for the agent ports: diff --git a/pkg/controller/backingstore/backingstore_controller.go b/pkg/controller/backingstore/backingstore_controller.go index 40175b06b..4eb6ab640 100644 --- a/pkg/controller/backingstore/backingstore_controller.go +++ b/pkg/controller/backingstore/backingstore_controller.go @@ -50,6 +50,12 @@ func Add(mgr manager.Manager) error { Scheme: mgr.GetScheme(), } + // Predicate that filter events that noobaa is not their owner + filterForNoobaaOwnerPredicate := util.FilterForOwner{ + OwnerType: &nbv1.NooBaa{}, + Scheme: mgr.GetScheme(), + } + // Predicate that allows events that only change spec, labels or finalizers and will log any allowed events // This will stop infinite reconciles that triggered by status or irrelevant metadata changes backingStorePredicate := util.ComposePredicates( @@ -79,6 +85,10 @@ func Add(mgr manager.Manager) error { if err != nil { return err } + err = c.Watch(source.Kind(mgr.GetCache(), &corev1.ConfigMap{}), ownerHandler, &filterForNoobaaOwnerPredicate, &logEventsPredicate) + if err != nil { + return err + } // setting another handler to watch events on secrets that not necessarily owned by the Backingstore. // only one OwnerReference can be a controller see: