From f98c8328d56473d7aa5440853d135f8a090bbac7 Mon Sep 17 00:00:00 2001 From: Tommi Hovi Date: Mon, 18 Sep 2023 16:51:23 +0300 Subject: [PATCH] fix: eventsource: deterministic volume/volumeMount order The order was non-deterministic earlier and this caused the controller to change the deployment on every reconcile until it the order happened to be same twice in a row. --- controllers/eventsource/resource.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/eventsource/resource.go b/controllers/eventsource/resource.go index 5159b39453..61397a3e44 100644 --- a/controllers/eventsource/resource.go +++ b/controllers/eventsource/resource.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "sort" "github.com/imdario/mergo" "go.uber.org/zap" @@ -268,6 +269,14 @@ func buildDeployment(args *AdaptorArgs, eventBus *eventbusv1alpha1.EventBus) (*a volumeMounts = append(volumeMounts, volCofigMapMounts...) volumes = append(volumes, volConfigMaps...) + // Order volumes and volumemounts based on name to make the order deterministic + sort.Slice(volumes, func(i, j int) bool { + return volumes[i].Name < volumes[j].Name + }) + sort.Slice(volumeMounts, func(i, j int) bool { + return volumeMounts[i].Name < volumeMounts[j].Name + }) + deploymentSpec.Template.Spec.Containers[0].Env = append(deploymentSpec.Template.Spec.Containers[0].Env, env...) deploymentSpec.Template.Spec.Containers[0].VolumeMounts = append(deploymentSpec.Template.Spec.Containers[0].VolumeMounts, volumeMounts...) deploymentSpec.Template.Spec.Volumes = append(deploymentSpec.Template.Spec.Volumes, volumes...)