Skip to content

Commit

Permalink
Add NOOBAA_LOG_LEVEL to the agent pod
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
liranmauda committed Aug 11, 2024
1 parent 82b79ff commit ec773dc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions deploy/internal/pod-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/backingstore/backingstore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ec773dc

Please sign in to comment.