1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Bugfix] Checksum compatibility (#591)

This commit is contained in:
Adam Janikowski 2020-07-01 12:52:02 +02:00 committed by GitHub
parent 3d16713bbe
commit f74977e279
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 9 deletions

View file

@ -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"`

View file

@ -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)
}

View file

@ -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{}
}

View file

@ -343,7 +343,11 @@ func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
in.License.DeepCopyInto(&out.License)
in.Metrics.DeepCopyInto(&out.Metrics)
in.Lifecycle.DeepCopyInto(&out.Lifecycle)
in.ID.DeepCopyInto(&out.ID)
if in.ID != nil {
in, out := &in.ID, &out.ID
*out = new(ServerIDGroupSpec)
(*in).DeepCopyInto(*out)
}
in.Single.DeepCopyInto(&out.Single)
in.Agents.DeepCopyInto(&out.Agents)
in.DBServers.DeepCopyInto(&out.DBServers)

View file

@ -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 {
@ -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)
}
@ -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 {
@ -367,7 +367,7 @@ 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)
}
@ -375,7 +375,7 @@ func (i *ImageUpdatePod) GetPodAntiAffinity() *core.PodAntiAffinity {
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)
}
@ -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)
}