#249 Improve checking the NodeSelector

This commit is contained in:
Tomasz Sęk 2020-01-20 22:02:38 +01:00
parent 8941f746b8
commit ba122db1f6
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
2 changed files with 11 additions and 12 deletions

View File

@ -349,7 +349,7 @@ func (r *ReconcileJenkinsBaseConfiguration) createServiceAccount(meta metav1.Obj
return stackerr.WithStack(err) return stackerr.WithStack(err)
} }
if !compareAnnotations(r.Configuration.Jenkins.Spec.ServiceAccount.Annotations, serviceAccount.Annotations) { if !compareMap(r.Configuration.Jenkins.Spec.ServiceAccount.Annotations, serviceAccount.Annotations) {
for key, value := range r.Configuration.Jenkins.Spec.ServiceAccount.Annotations { for key, value := range r.Configuration.Jenkins.Spec.ServiceAccount.Annotations {
serviceAccount.Annotations[key] = value serviceAccount.Annotations[key] = value
} }
@ -612,14 +612,13 @@ func (r *ReconcileJenkinsBaseConfiguration) checkForPodRecreation(currentJenkins
currentJenkinsMasterPod.Spec.ImagePullSecrets, r.Configuration.Jenkins.Spec.Master.ImagePullSecrets)) currentJenkinsMasterPod.Spec.ImagePullSecrets, r.Configuration.Jenkins.Spec.Master.ImagePullSecrets))
} }
if !reflect.DeepEqual(r.Configuration.Jenkins.Spec.Master.NodeSelector, currentJenkinsMasterPod.Spec.NodeSelector) { if !compareMap(r.Configuration.Jenkins.Spec.Master.NodeSelector, currentJenkinsMasterPod.Spec.NodeSelector) {
messages = append(messages, "Jenkins pod node selector has changed") messages = append(messages, "Jenkins pod node selector has changed")
verbose = append(verbose, fmt.Sprintf("Jenkins pod node selector has changed, actual '%+v' required '%+v'", verbose = append(verbose, fmt.Sprintf("Jenkins pod node selector has changed, actual '%+v' required '%+v'",
currentJenkinsMasterPod.Spec.NodeSelector, r.Configuration.Jenkins.Spec.Master.NodeSelector)) currentJenkinsMasterPod.Spec.NodeSelector, r.Configuration.Jenkins.Spec.Master.NodeSelector))
} }
if len(r.Configuration.Jenkins.Spec.Master.Annotations) > 0 && if !compareMap(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
!compareAnnotations(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
messages = append(messages, "Jenkins pod annotations have changed") messages = append(messages, "Jenkins pod annotations have changed")
verbose = append(verbose, fmt.Sprintf("Jenkins pod annotations have changed, actual '%+v' required '%+v'", verbose = append(verbose, fmt.Sprintf("Jenkins pod annotations have changed, actual '%+v' required '%+v'",
currentJenkinsMasterPod.ObjectMeta.Annotations, r.Configuration.Jenkins.Spec.Master.Annotations)) currentJenkinsMasterPod.ObjectMeta.Annotations, r.Configuration.Jenkins.Spec.Master.Annotations))
@ -781,7 +780,7 @@ func compareImagePullSecrets(expected, actual []corev1.LocalObjectReference) boo
return true return true
} }
func compareAnnotations(expected, actual map[string]string) bool { func compareMap(expected, actual map[string]string) bool {
for expectedKey, expectedValue := range expected { for expectedKey, expectedValue := range expected {
actualValue, found := actual[expectedKey] actualValue, found := actual[expectedKey]
if !found { if !found {

View File

@ -655,12 +655,12 @@ func Test_compareEnv(t *testing.T) {
}) })
} }
func TestComparePodAnnotations(t *testing.T) { func TestCompareMap(t *testing.T) {
t.Run("empty", func(t *testing.T) { t.Run("empty", func(t *testing.T) {
expectedAnnotations := map[string]string{} expectedAnnotations := map[string]string{}
actualAnnotations := map[string]string{} actualAnnotations := map[string]string{}
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.True(t, got) assert.True(t, got)
}) })
@ -668,7 +668,7 @@ func TestComparePodAnnotations(t *testing.T) {
expectedAnnotations := map[string]string{"one": "two"} expectedAnnotations := map[string]string{"one": "two"}
actualAnnotations := expectedAnnotations actualAnnotations := expectedAnnotations
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.True(t, got) assert.True(t, got)
}) })
@ -676,7 +676,7 @@ func TestComparePodAnnotations(t *testing.T) {
expectedAnnotations := map[string]string{"one": "two"} expectedAnnotations := map[string]string{"one": "two"}
actualAnnotations := map[string]string{"one": "two", "three": "four"} actualAnnotations := map[string]string{"one": "two", "three": "four"}
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.True(t, got) assert.True(t, got)
}) })
@ -684,7 +684,7 @@ func TestComparePodAnnotations(t *testing.T) {
expectedAnnotations := map[string]string{"one": "two"} expectedAnnotations := map[string]string{"one": "two"}
actualAnnotations := map[string]string{"three": "four"} actualAnnotations := map[string]string{"three": "four"}
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.False(t, got) assert.False(t, got)
}) })
@ -692,7 +692,7 @@ func TestComparePodAnnotations(t *testing.T) {
expectedAnnotations := map[string]string{"one": "two"} expectedAnnotations := map[string]string{"one": "two"}
actualAnnotations := map[string]string{"one": "three"} actualAnnotations := map[string]string{"one": "three"}
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.False(t, got) assert.False(t, got)
}) })
@ -700,7 +700,7 @@ func TestComparePodAnnotations(t *testing.T) {
expectedAnnotations := map[string]string{"one": "two", "missing": "something"} expectedAnnotations := map[string]string{"one": "two", "missing": "something"}
actualAnnotations := map[string]string{"one": "three"} actualAnnotations := map[string]string{"one": "three"}
got := compareAnnotations(expectedAnnotations, actualAnnotations) got := compareMap(expectedAnnotations, actualAnnotations)
assert.False(t, got) assert.False(t, got)
}) })