Skip to content

Commit f74977e

Browse files
authored
[Bugfix] Checksum compatibility (#591)
1 parent 3d16713 commit f74977e

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type DeploymentSpec struct {
8383
Metrics MetricsSpec `json:"metrics"`
8484
Lifecycle LifecycleSpec `json:"lifecycle,omitempty"`
8585

86-
ID ServerIDGroupSpec `json:"id"`
86+
ID *ServerIDGroupSpec `json:"id,omitempty"`
8787

8888
Single ServerGroupSpec `json:"single"`
8989
Agents ServerGroupSpec `json:"agents"`
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package v1
24+
25+
import (
26+
"testing"
27+
28+
"github.com/stretchr/testify/require"
29+
)
30+
31+
type checksumCompareCases []checksumCompareCase
32+
33+
type checksumCompareCase struct {
34+
name string
35+
36+
spec DeploymentSpec
37+
checksum string
38+
}
39+
40+
func runChecksumCompareCases(t *testing.T, cases checksumCompareCases) {
41+
for _, c := range cases {
42+
t.Run(c.name, func(t *testing.T) {
43+
runChecksumCompareCase(t, c)
44+
})
45+
}
46+
}
47+
48+
func runChecksumCompareCase(t *testing.T, c checksumCompareCase) {
49+
s, err := c.spec.Checksum()
50+
require.NoError(t, err)
51+
52+
require.Equalf(t, c.checksum, s, "Checksum od ArangoDeployment mismatch")
53+
}
54+
55+
func TestImmutableSpec(t *testing.T) {
56+
cases := checksumCompareCases{
57+
{
58+
name: "Default case - from 1.0.3",
59+
spec: DeploymentSpec{},
60+
checksum: "a164088b280d72c177c2eafdab7a346fb296264b70c06329b776c506925bb54e",
61+
},
62+
}
63+
64+
runChecksumCompareCases(t, cases)
65+
}

pkg/apis/deployment/v1/server_id_group_spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ type ServerIDGroupSpec struct {
3939
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
4040
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
4141
}
42+
43+
func (s *ServerIDGroupSpec) Get() ServerIDGroupSpec {
44+
if s != nil {
45+
return *s
46+
}
47+
48+
return ServerIDGroupSpec{}
49+
}

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/images.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (i *ImageUpdatePod) GetRole() string {
271271
func (i *ImageUpdatePod) Init(pod *core.Pod) {
272272
terminationGracePeriodSeconds := int64((time.Second * 30).Seconds())
273273
pod.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
274-
pod.Spec.PriorityClassName = i.spec.ID.PriorityClassName
274+
pod.Spec.PriorityClassName = i.spec.ID.Get().PriorityClassName
275275
}
276276

277277
func (i *ImageUpdatePod) GetImagePullSecrets() []string {
@@ -316,9 +316,9 @@ func (i *ImageUpdatePod) GetTolerations() []core.Toleration {
316316
TimeSpan: time.Second * 5,
317317
}
318318

319-
tolerations := make([]core.Toleration, 0, 3+len(i.spec.ID.Tolerations))
319+
tolerations := make([]core.Toleration, 0, 3+len(i.spec.ID.Get().Tolerations))
320320

321-
if idTolerations := i.spec.ID.Tolerations; len(idTolerations) > 0 {
321+
if idTolerations := i.spec.ID.Get().Tolerations; len(idTolerations) > 0 {
322322
for _, toleration := range idTolerations {
323323
tolerations = k8sutil.AddTolerationIfNotFound(tolerations, toleration)
324324
}
@@ -339,7 +339,7 @@ func (i *ImageUpdatePod) IsDeploymentMode() bool {
339339
}
340340

341341
func (i *ImageUpdatePod) GetNodeSelector() map[string]string {
342-
return i.spec.ID.NodeSelector
342+
return i.spec.ID.Get().NodeSelector
343343
}
344344

345345
func (i *ImageUpdatePod) GetServiceAccountName() string {
@@ -367,15 +367,15 @@ func (i *ImageUpdatePod) GetPodAntiAffinity() *core.PodAntiAffinity {
367367

368368
pod.AppendPodAntiAffinityDefault(i, &a)
369369

370-
pod.MergePodAntiAffinity(&a, i.spec.ID.AntiAffinity)
370+
pod.MergePodAntiAffinity(&a, i.spec.ID.Get().AntiAffinity)
371371

372372
return pod.ReturnPodAntiAffinityOrNil(a)
373373
}
374374

375375
func (i *ImageUpdatePod) GetPodAffinity() *core.PodAffinity {
376376
a := core.PodAffinity{}
377377

378-
pod.MergePodAffinity(&a, i.spec.ID.Affinity)
378+
pod.MergePodAffinity(&a, i.spec.ID.Get().Affinity)
379379

380380
return pod.ReturnPodAffinityOrNil(a)
381381
}
@@ -385,7 +385,7 @@ func (i *ImageUpdatePod) GetNodeAffinity() *core.NodeAffinity {
385385

386386
pod.AppendNodeSelector(&a)
387387

388-
pod.MergeNodeAffinity(&a, i.spec.ID.NodeAffinity)
388+
pod.MergeNodeAffinity(&a, i.spec.ID.Get().NodeAffinity)
389389

390390
return pod.ReturnNodeAffinityOrNil(a)
391391
}

0 commit comments

Comments
 (0)