Skip to content

Commit

Permalink
fix: sort etcd args to make them deterministic (#249)
Browse files Browse the repository at this point in the history
Fix non-deterministic order of etcd args.
fixes #248
  • Loading branch information
sircthulhu committed Jul 3, 2024
1 parent 7367339 commit ec7f117
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/controller/factory/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"math"
"slices"
"strconv"

"github.com/aenix-io/etcd-operator/internal/log"
Expand Down Expand Up @@ -334,6 +335,8 @@ func generateEtcdArgs(cluster *etcdaenixiov1alpha1.EtcdCluster) []string {
args = append(args, clientTlsSettings...)
args = append(args, autoCompactionSettings...)

slices.Sort(args)

return args
}

Expand Down
13 changes: 12 additions & 1 deletion internal/controller/factory/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package factory

import (
"slices"

"github.com/google/uuid"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -172,10 +174,19 @@ var _ = Describe("CreateOrUpdateStatefulSet handler", func() {
Expect(statefulSet.Spec.Template.ObjectMeta.Annotations).To(Equal(etcdcluster.Spec.PodTemplate.Annotations))
})

By("Checking the extraArgs", func() {
By("Checking the command", func() {
Expect(statefulSet.Spec.Template.Spec.Containers[0].Command).To(Equal(generateEtcdCommand()))
})

By("Checking the extraArgs", func() {
Expect(statefulSet.Spec.Template.Spec.Containers[0].Args).To(Equal(generateEtcdArgs(&etcdcluster)))
By("Checking args are sorted", func() {
argsClone := slices.Clone(statefulSet.Spec.Template.Spec.Containers[0].Args)
slices.Sort(argsClone)
Expect(statefulSet.Spec.Template.Spec.Containers[0].Args).To(Equal(argsClone))
})
})

By("Checking the readinessGates", func() {
Expect(statefulSet.Spec.Template.Spec.ReadinessGates).To(Equal(etcdcluster.Spec.PodTemplate.Spec.ReadinessGates))
})
Expand Down

0 comments on commit ec7f117

Please sign in to comment.