Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/deployment/v1/deployment_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type DeploymentSpec struct {
Metrics MetricsSpec `json:"metrics"`
Lifecycle LifecycleSpec `json:"lifecycle,omitempty"`

ID ServerIDGroupSpec `json:"id"`
ID *ServerIDGroupSpec `json:"id,omitempty"`

Single ServerGroupSpec `json:"single"`
Agents ServerGroupSpec `json:"agents"`
Expand Down
65 changes: 65 additions & 0 deletions pkg/apis/deployment/v1/immutable_checksum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Adam Janikowski
//

package v1

import (
"testing"

"github.com/stretchr/testify/require"
)

type checksumCompareCases []checksumCompareCase

type checksumCompareCase struct {
name string

spec DeploymentSpec
checksum string
}

func runChecksumCompareCases(t *testing.T, cases checksumCompareCases) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
runChecksumCompareCase(t, c)
})
}
}

func runChecksumCompareCase(t *testing.T, c checksumCompareCase) {
s, err := c.spec.Checksum()
require.NoError(t, err)

require.Equalf(t, c.checksum, s, "Checksum od ArangoDeployment mismatch")
}

func TestImmutableSpec(t *testing.T) {
cases := checksumCompareCases{
{
name: "Default case - from 1.0.3",
spec: DeploymentSpec{},
checksum: "a164088b280d72c177c2eafdab7a346fb296264b70c06329b776c506925bb54e",
},
}

runChecksumCompareCases(t, cases)
}
8 changes: 8 additions & 0 deletions pkg/apis/deployment/v1/server_id_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ type ServerIDGroupSpec struct {
// NodeAffinity specified additional nodeAffinity settings in ArangoDB Pod definitions
NodeAffinity *core.NodeAffinity `json:"nodeAffinity,omitempty"`
}

func (s *ServerIDGroupSpec) Get() ServerIDGroupSpec {
if s != nil {
return *s
}

return ServerIDGroupSpec{}
}
6 changes: 5 additions & 1 deletion pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/deployment/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (i *ImageUpdatePod) GetRole() string {
func (i *ImageUpdatePod) Init(pod *core.Pod) {
terminationGracePeriodSeconds := int64((time.Second * 30).Seconds())
pod.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
pod.Spec.PriorityClassName = i.spec.ID.PriorityClassName
pod.Spec.PriorityClassName = i.spec.ID.Get().PriorityClassName
}

func (i *ImageUpdatePod) GetImagePullSecrets() []string {
Expand Down Expand Up @@ -316,9 +316,9 @@ func (i *ImageUpdatePod) GetTolerations() []core.Toleration {
TimeSpan: time.Second * 5,
}

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

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

func (i *ImageUpdatePod) GetNodeSelector() map[string]string {
return i.spec.ID.NodeSelector
return i.spec.ID.Get().NodeSelector
}

func (i *ImageUpdatePod) GetServiceAccountName() string {
Expand Down Expand Up @@ -367,15 +367,15 @@ func (i *ImageUpdatePod) GetPodAntiAffinity() *core.PodAntiAffinity {

pod.AppendPodAntiAffinityDefault(i, &a)

pod.MergePodAntiAffinity(&a, i.spec.ID.AntiAffinity)
pod.MergePodAntiAffinity(&a, i.spec.ID.Get().AntiAffinity)

return pod.ReturnPodAntiAffinityOrNil(a)
}

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

pod.MergePodAffinity(&a, i.spec.ID.Affinity)
pod.MergePodAffinity(&a, i.spec.ID.Get().Affinity)

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

pod.AppendNodeSelector(&a)

pod.MergeNodeAffinity(&a, i.spec.ID.NodeAffinity)
pod.MergeNodeAffinity(&a, i.spec.ID.Get().NodeAffinity)

return pod.ReturnNodeAffinityOrNil(a)
}
Expand Down