Skip to content

Commit

Permalink
Add md5 hash logging and fix glob pattern (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
khewonc authored and levan-m committed Mar 23, 2023
1 parent 9867c46 commit 05e01c4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion controllers/datadogagent/feature/cspm/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion controllers/datadogagent/feature/cws/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions controllers/datadogagent/override/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion controllers/datadogagent/override/podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(cmName)
manager.Annotation().AddAnnotation(annotationKey, hash)
Expand All @@ -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(cmName)
manager.Annotation().AddAnnotation(annotationKey, hash)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 05e01c4

Please sign in to comment.