diff --git a/examples/lightrunjavaagent.yaml b/examples/lightrunjavaagent.yaml index 07ccb55..243d85c 100644 --- a/examples/lightrunjavaagent.yaml +++ b/examples/lightrunjavaagent.yaml @@ -30,7 +30,7 @@ spec: # platform - `linux/alpine` # agent version - first part of the tag (1.7.0) # init container sub-version - last part of the tag (init.0) - image: "lightruncom/k8s-operator-init-java-agent-linux:1.8.5-init.1" + image: "lightruncom/k8s-operator-init-java-agent-linux:latest" # Volume name in case you have some convention in the names sharedVolumeName: lightrun-agent-init # Mount path where volume will be parked. Various distributions may have it's limitations. @@ -56,7 +56,7 @@ spec: agentTags: - operator - example - - 1.8.5 + - latest # Agent name. If not provided, pod name will be used #agentName: "operator-test-agent" diff --git a/internal/controller/helpers.go b/internal/controller/helpers.go index 1d328d0..acee62d 100644 --- a/internal/controller/helpers.go +++ b/internal/controller/helpers.go @@ -3,6 +3,7 @@ package controller import ( "context" "hash/fnv" + "sort" "time" agentv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta" @@ -173,8 +174,15 @@ func removeString(slice []string, s string) (result []string) { func parseAgentConfig(config map[string]string) string { var cm_data string - for k, v := range config { - cm_data = cm_data + k + "=" + v + "\n" + var keys []string + // sort keys to preserve order in hash + for k := range config { + keys = append(keys, k) + } + sort.Strings(keys) + + for _, k := range keys { + cm_data = cm_data + k + "=" + config[k] + "\n" } return cm_data } diff --git a/internal/controller/lightrunjavaagent_controller_test.go b/internal/controller/lightrunjavaagent_controller_test.go index 78e4d3a..d0c9434 100644 --- a/internal/controller/lightrunjavaagent_controller_test.go +++ b/internal/controller/lightrunjavaagent_controller_test.go @@ -2,6 +2,7 @@ package controller import ( "context" + "fmt" "time" agentsv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta" @@ -34,7 +35,13 @@ var _ = Describe("LightrunJavaAgent controller", func() { agentCliFlags = "--lightrun_extra_class_path=" ) var containerSelector = []string{"app", "app2"} - var agentConfig map[string]string = map[string]string{"max_log_cpu_cost": "2"} + var agentConfig map[string]string = map[string]string{ + "max_log_cpu_cost": "2", + "some_config": "1", + "some_other_config": "2", + "some_yet_another_config": "1", + + } var agentTags []string = []string{"new_tag", "prod"} var secretData map[string]string = map[string]string{ "LIGHTRUN_KEY": "some_key", @@ -336,6 +343,11 @@ var _ = Describe("LightrunJavaAgent controller", func() { return flag == 2 }).Should(BeTrue()) }) + It("Should not change hash of the configmap in the deployment metadata", func() { + Eventually(func() bool { + return patchedDepl.Spec.Template.Annotations["lightrun.com/configmap-hash"] == fmt.Sprint(hash(cm.Data["config"]+cm.Data["metadata"])) + }).Should(BeTrue()) + }) It("Should add finalizer to first CRD", func() { Eventually(func() bool {