Skip to content

Commit

Permalink
fix: eventsource: deterministic volume/volumeMount order
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Tommi Hovi <[email protected]>
  • Loading branch information
popsu committed Sep 18, 2023
1 parent 1d992bc commit 40d9ba0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/eventsource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"sort"

"github.com/imdario/mergo"
"go.uber.org/zap"
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 40d9ba0

Please sign in to comment.