internal/manifests/targetallocator/annotations.go (29 lines of code) (raw):

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package targetallocator import ( "crypto/sha256" "fmt" v1 "k8s.io/api/core/v1" "github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1" ) const configMapHashAnnotationKey = "amazon-cloudwatch-agent-target-allocator-config/hash" // Annotations returns the annotations for the TargetAllocator Pod. func Annotations(instance v1alpha1.AmazonCloudWatchAgent, configMap *v1.ConfigMap) map[string]string { // Make a copy of PodAnnotations to be safe annotations := make(map[string]string, len(instance.Spec.PodAnnotations)) for key, value := range instance.Spec.PodAnnotations { annotations[key] = value } if configMap != nil { cmHash := getConfigMapSHA(configMap) if cmHash != "" { annotations[configMapHashAnnotationKey] = getConfigMapSHA(configMap) } } return annotations } // getConfigMapSHA returns the hash of the content of the TA ConfigMap. func getConfigMapSHA(configMap *v1.ConfigMap) string { configString, ok := configMap.Data[targetAllocatorFilename] if !ok { return "" } h := sha256.Sum256([]byte(configString)) return fmt.Sprintf("%x", h) }