Skip to content

Commit 2313e7b

Browse files
author
Leonid Podolinskiy
authored
sort agent config in configmap (#16)
* sort agent config in configmap has to be sorted for consistent has in the deployment * add test
1 parent 566f81f commit 2313e7b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

examples/lightrunjavaagent.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
# platform - `linux/alpine`
3131
# agent version - first part of the tag (1.7.0)
3232
# init container sub-version - last part of the tag (init.0)
33-
image: "lightruncom/k8s-operator-init-java-agent-linux:1.8.5-init.1"
33+
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
3434
# Volume name in case you have some convention in the names
3535
sharedVolumeName: lightrun-agent-init
3636
# Mount path where volume will be parked. Various distributions may have it's limitations.
@@ -56,7 +56,7 @@ spec:
5656
agentTags:
5757
- operator
5858
- example
59-
- 1.8.5
59+
- latest
6060
# Agent name. If not provided, pod name will be used
6161
#agentName: "operator-test-agent"
6262

internal/controller/helpers.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controller
33
import (
44
"context"
55
"hash/fnv"
6+
"sort"
67
"time"
78

89
agentv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta"
@@ -173,8 +174,15 @@ func removeString(slice []string, s string) (result []string) {
173174

174175
func parseAgentConfig(config map[string]string) string {
175176
var cm_data string
176-
for k, v := range config {
177-
cm_data = cm_data + k + "=" + v + "\n"
177+
var keys []string
178+
// sort keys to preserve order in hash
179+
for k := range config {
180+
keys = append(keys, k)
181+
}
182+
sort.Strings(keys)
183+
184+
for _, k := range keys {
185+
cm_data = cm_data + k + "=" + config[k] + "\n"
178186
}
179187
return cm_data
180188
}

internal/controller/lightrunjavaagent_controller_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controller
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

78
agentsv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta"
@@ -34,7 +35,13 @@ var _ = Describe("LightrunJavaAgent controller", func() {
3435
agentCliFlags = "--lightrun_extra_class_path=<PATH_TO_JAR>"
3536
)
3637
var containerSelector = []string{"app", "app2"}
37-
var agentConfig map[string]string = map[string]string{"max_log_cpu_cost": "2"}
38+
var agentConfig map[string]string = map[string]string{
39+
"max_log_cpu_cost": "2",
40+
"some_config": "1",
41+
"some_other_config": "2",
42+
"some_yet_another_config": "1",
43+
44+
}
3845
var agentTags []string = []string{"new_tag", "prod"}
3946
var secretData map[string]string = map[string]string{
4047
"LIGHTRUN_KEY": "some_key",
@@ -336,6 +343,11 @@ var _ = Describe("LightrunJavaAgent controller", func() {
336343
return flag == 2
337344
}).Should(BeTrue())
338345
})
346+
It("Should not change hash of the configmap in the deployment metadata", func() {
347+
Eventually(func() bool {
348+
return patchedDepl.Spec.Template.Annotations["lightrun.com/configmap-hash"] == fmt.Sprint(hash(cm.Data["config"]+cm.Data["metadata"]))
349+
}).Should(BeTrue())
350+
})
339351

340352
It("Should add finalizer to first CRD", func() {
341353
Eventually(func() bool {

0 commit comments

Comments
 (0)