From 82f73a3c4e95d034f0c8a9ea9d57149a6b09c9d7 Mon Sep 17 00:00:00 2001 From: khewonc <39867936+khewonc@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:58:57 -0500 Subject: [PATCH] Add md5 hash logging and fix glob pattern --- controllers/datadogagent/feature/cspm/feature.go | 4 +++- controllers/datadogagent/feature/cws/feature.go | 4 +++- .../datadogagent/feature/kubernetesstatecore/feature.go | 5 ++++- .../datadogagent/feature/orchestratorexplorer/feature.go | 4 +++- controllers/datadogagent/override/dependencies.go | 4 ++-- controllers/datadogagent/override/podtemplatespec.go | 8 +++++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/controllers/datadogagent/feature/cspm/feature.go b/controllers/datadogagent/feature/cspm/feature.go index 933899695..49580aad2 100644 --- a/controllers/datadogagent/feature/cspm/feature.go +++ b/controllers/datadogagent/feature/cspm/feature.go @@ -83,6 +83,8 @@ func (f *cspmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req hash, err := comparison.GenerateMD5ForSpec(f.customConfig) if err != nil { f.logger.Error(err, "couldn't generate hash for cspm custom benchmarks config") + } else { + f.logger.V(2).Info("built cspm custom benchmarks from custom config", "hash", hash) } f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.CSPMIDType) @@ -150,7 +152,7 @@ func (f *cspmFeature) ManageDependencies(managers feature.ResourceManagers, comp if cm != nil { // Add md5 hash annotation for custom config if f.customConfigAnnotationKey != "" && f.customConfigAnnotationValue != "" { - annotations := object.MergeAnnotationsLabels(f.logger, cm.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "") + annotations := object.MergeAnnotationsLabels(f.logger, cm.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "*") cm.SetAnnotations(annotations) } diff --git a/controllers/datadogagent/feature/cws/feature.go b/controllers/datadogagent/feature/cws/feature.go index 079fac817..fc30f8405 100644 --- a/controllers/datadogagent/feature/cws/feature.go +++ b/controllers/datadogagent/feature/cws/feature.go @@ -74,6 +74,8 @@ func (f *cwsFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ hash, err := comparison.GenerateMD5ForSpec(f.customConfig) if err != nil { f.logger.Error(err, "couldn't generate hash for cws custom policies config") + } else { + f.logger.V(2).Info("built cws custom policies from custom config", "hash", hash) } f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.CWSIDType) @@ -135,7 +137,7 @@ func (f *cwsFeature) ManageDependencies(managers feature.ResourceManagers, compo if cm != nil { // Add md5 hash annotation for custom config if f.customConfigAnnotationKey != "" && f.customConfigAnnotationValue != "" { - annotations := object.MergeAnnotationsLabels(f.logger, cm.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "") + annotations := object.MergeAnnotationsLabels(f.logger, cm.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "*") cm.SetAnnotations(annotations) } diff --git a/controllers/datadogagent/feature/kubernetesstatecore/feature.go b/controllers/datadogagent/feature/kubernetesstatecore/feature.go index c7fe561f8..9901e380b 100644 --- a/controllers/datadogagent/feature/kubernetesstatecore/feature.go +++ b/controllers/datadogagent/feature/kubernetesstatecore/feature.go @@ -79,6 +79,8 @@ func (f *ksmFeature) Configure(dda *v2alpha1.DatadogAgent) feature.RequiredCompo hash, err := comparison.GenerateMD5ForSpec(f.customConfig) if err != nil { f.logger.Error(err, "couldn't generate hash for ksm core custom config") + } else { + f.logger.V(2).Info("built ksm core from custom config", "hash", hash) } f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.KubernetesStateCoreIDType) @@ -141,8 +143,9 @@ func (f *ksmFeature) ManageDependencies(managers feature.ResourceManagers, compo return err } if configCM != nil { + // Add md5 hash annotation for custom config if f.customConfigAnnotationKey != "" && f.customConfigAnnotationValue != "" { - annotations := object.MergeAnnotationsLabels(f.logger, configCM.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "") + annotations := object.MergeAnnotationsLabels(f.logger, configCM.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "*") configCM.SetAnnotations(annotations) } if err := managers.Store().AddOrUpdate(kubernetes.ConfigMapKind, configCM); err != nil { diff --git a/controllers/datadogagent/feature/orchestratorexplorer/feature.go b/controllers/datadogagent/feature/orchestratorexplorer/feature.go index ac9cd96c7..4492c3b22 100644 --- a/controllers/datadogagent/feature/orchestratorexplorer/feature.go +++ b/controllers/datadogagent/feature/orchestratorexplorer/feature.go @@ -83,6 +83,8 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req hash, err := comparison.GenerateMD5ForSpec(f.customConfig) if err != nil { f.logger.Error(err, "couldn't generate hash for orchestrator explorer custom config") + } else { + f.logger.V(2).Info("built orchestrator explorer from custom config", "hash", hash) } f.customConfigAnnotationValue = hash f.customConfigAnnotationKey = object.GetChecksumAnnotationKey(feature.OrchestratorExplorerIDType) @@ -159,7 +161,7 @@ func (f *orchestratorExplorerFeature) ManageDependencies(managers feature.Resour if configCM != nil { // Add md5 hash annotation for custom config if f.customConfigAnnotationKey != "" && f.customConfigAnnotationValue != "" { - annotations := object.MergeAnnotationsLabels(f.logger, configCM.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "") + annotations := object.MergeAnnotationsLabels(f.logger, configCM.GetAnnotations(), map[string]string{f.customConfigAnnotationKey: f.customConfigAnnotationValue}, "*") configCM.SetAnnotations(annotations) } if err := managers.Store().AddOrUpdate(kubernetes.ConfigMapKind, configCM); err != nil { diff --git a/controllers/datadogagent/override/dependencies.go b/controllers/datadogagent/override/dependencies.go index 895ba35a0..0a0369fd2 100644 --- a/controllers/datadogagent/override/dependencies.go +++ b/controllers/datadogagent/override/dependencies.go @@ -86,7 +86,7 @@ func overrideCustomConfigs(logger logr.Logger, manager feature.ResourceManagers, logger.Error(err, "couldn't generate hash for custom config", "filename", fileName) } annotationKey := object.GetChecksumAnnotationKey(string(fileName)) - annotations := object.MergeAnnotationsLabels(logger, cm.GetAnnotations(), map[string]string{annotationKey: hash}, "") + annotations := object.MergeAnnotationsLabels(logger, cm.GetAnnotations(), map[string]string{annotationKey: hash}, "*") cm.SetAnnotations(annotations) if cm != nil { @@ -112,7 +112,7 @@ func overrideExtraConfigs(logger logr.Logger, manager feature.ResourceManagers, logger.Error(err, "couldn't generate hash for extra custom config") } annotationKey := object.GetChecksumAnnotationKey(configMapName) - annotations := object.MergeAnnotationsLabels(logger, cm.GetAnnotations(), map[string]string{annotationKey: hash}, "") + annotations := object.MergeAnnotationsLabels(logger, cm.GetAnnotations(), map[string]string{annotationKey: hash}, "*") cm.SetAnnotations(annotations) if cm != nil { diff --git a/controllers/datadogagent/override/podtemplatespec.go b/controllers/datadogagent/override/podtemplatespec.go index 24fec9435..20c38611e 100644 --- a/controllers/datadogagent/override/podtemplatespec.go +++ b/controllers/datadogagent/override/podtemplatespec.go @@ -66,6 +66,8 @@ func PodTemplateSpec(logger logr.Logger, manager feature.PodTemplateManagers, ov hash, err := comparison.GenerateMD5ForSpec(override.ExtraConfd) if err != nil { logger.Error(err, "couldn't generate hash for extra confd custom config") + } else { + logger.V(2).Info("built extra confd from custom config", "hash", hash) } annotationKey := object.GetChecksumAnnotationKey(v2alpha1.ExtraConfdConfigMapName) manager.Annotation().AddAnnotation(annotationKey, hash) @@ -80,7 +82,9 @@ func PodTemplateSpec(logger logr.Logger, manager feature.PodTemplateManagers, ov // Add md5 hash annotation for custom config hash, err := comparison.GenerateMD5ForSpec(override.ExtraChecksd) if err != nil { - logger.Error(err, "couldn't generate hash for extra checks custom config") + logger.Error(err, "couldn't generate hash for extra checksd custom config") + } else { + logger.V(2).Info("built extra checksd from custom config", "hash", hash) } annotationKey := object.GetChecksumAnnotationKey(v2alpha1.ExtraChecksdConfigMapName) manager.Annotation().AddAnnotation(annotationKey, hash) @@ -172,6 +176,8 @@ func overrideCustomConfigVolumes(logger logr.Logger, manager feature.PodTemplate hash, err := comparison.GenerateMD5ForSpec(customConfig) if err != nil { logger.Error(err, "couldn't generate hash for custom config", "filename", fileName) + } else { + logger.V(2).Info("built file from custom config", "filename", fileName, "hash", hash) } annotationKey := object.GetChecksumAnnotationKey(string(fileName)) manager.Annotation().AddAnnotation(annotationKey, hash)