Skip to content

Commit 9c3a6be

Browse files
authored
fix: ensure helm.values yaml encoding is stable (#2542)
1 parent 14b2879 commit 9c3a6be

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

go/controller/internal/controller/servicedeployment_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ func (r *ServiceDeploymentReconciler) genServiceAttributes(ctx context.Context,
343343
LuaFolder: service.Spec.Helm.LuaFolder,
344344
Git: service.Spec.Helm.Git.Attributes(),
345345
}
346+
if len(attr.Helm.ValuesFiles) > 0 {
347+
sort.Slice(attr.Helm.ValuesFiles, func(i, j int) bool {
348+
return *attr.Helm.ValuesFiles[i] < *attr.Helm.ValuesFiles[j]
349+
})
350+
}
351+
346352
if service.Spec.Helm.Repository != nil {
347353
attr.Helm.Repository = &console.NamespacedName{
348354
Name: service.Spec.Helm.Repository.Name,

go/controller/internal/controller/servicedeployment_controller_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,50 @@ var _ = Describe("Merge Helm Values", Ordered, func() {
642642
max_connections: 202
643643
`))
644644
})
645+
646+
It("should successfully return sorted values", func() {
647+
test := struct {
648+
SecretRef *corev1.SecretReference
649+
Values *runtime.RawExtension
650+
}{
651+
Values: &runtime.RawExtension{
652+
Raw: []byte(`console:
653+
dashboard:
654+
enabled: false
655+
postgres:
656+
parameters:
657+
max_connections: 101
658+
m:
659+
c: 3
660+
a: 1
661+
b: 2`),
662+
},
663+
}
664+
665+
fakeConsoleClient := mocks.NewConsoleClientMock(mocks.TestingT)
666+
fakeConsoleClient.On("UseCredentials", mock.Anything, mock.Anything).Return("", nil)
667+
serviceReconciler := &controller.ServiceDeploymentReconciler{
668+
Client: k8sClient,
669+
Scheme: k8sClient.Scheme(),
670+
ConsoleClient: fakeConsoleClient,
671+
CredentialsCache: credentials.FakeNamespaceCredentialsCache(k8sClient),
672+
}
673+
674+
out, err := serviceReconciler.MergeHelmValues(ctx, test.SecretRef, test.Values)
675+
Expect(err).NotTo(HaveOccurred())
676+
Expect(*out).To(Equal(`console:
677+
dashboard:
678+
enabled: false
679+
postgres:
680+
parameters:
681+
max_connections: 101
682+
m:
683+
a: 1
684+
b: 2
685+
c: 3
686+
`))
687+
688+
})
645689
})
646690
})
647691

0 commit comments

Comments
 (0)