Skip to content

Commit

Permalink
sort agent config in configmap (#16)
Browse files Browse the repository at this point in the history
* sort agent config in configmap
has to be sorted for consistent has in the deployment

* add test
  • Loading branch information
Leonid Podolinskiy authored Oct 3, 2023
1 parent 566f81f commit 2313e7b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/lightrunjavaagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"

Expand Down
12 changes: 10 additions & 2 deletions internal/controller/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"
"hash/fnv"
"sort"
"time"

agentv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 13 additions & 1 deletion internal/controller/lightrunjavaagent_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"fmt"
"time"

agentsv1beta "github.com/lightrun-platform/lightrun-k8s-operator/api/v1beta"
Expand Down Expand Up @@ -34,7 +35,13 @@ var _ = Describe("LightrunJavaAgent controller", func() {
agentCliFlags = "--lightrun_extra_class_path=<PATH_TO_JAR>"
)
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",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2313e7b

Please sign in to comment.