Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort agent config in configmap #16

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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