mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-09-30 13:15:52 +02:00
#249 Improve checking the NodeSelector
(cherry picked from commit ba122db1f6)
This commit is contained in:
@@ -534,14 +534,13 @@ func (r *ReconcileJenkinsBaseConfiguration) checkForPodRecreation(currentJenkins
|
||||
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")
|
||||
verbose = append(verbose, fmt.Sprintf("Jenkins pod node selector has changed, actual '%+v' required '%+v'",
|
||||
currentJenkinsMasterPod.Spec.NodeSelector, r.Configuration.Jenkins.Spec.Master.NodeSelector))
|
||||
}
|
||||
|
||||
if len(r.Configuration.Jenkins.Spec.Master.Annotations) > 0 &&
|
||||
!comparePodAnnotations(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
|
||||
if !compareMap(r.Configuration.Jenkins.Spec.Master.Annotations, currentJenkinsMasterPod.ObjectMeta.Annotations) {
|
||||
messages = append(messages, "Jenkins pod annotations have changed")
|
||||
verbose = append(verbose, fmt.Sprintf("Jenkins pod annotations have changed, actual '%+v' required '%+v'",
|
||||
currentJenkinsMasterPod.ObjectMeta.Annotations, r.Configuration.Jenkins.Spec.Master.Annotations))
|
||||
@@ -676,7 +675,7 @@ func compareImagePullSecrets(expected, actual []corev1.LocalObjectReference) boo
|
||||
return true
|
||||
}
|
||||
|
||||
func comparePodAnnotations(expected, actual map[string]string) bool {
|
||||
func compareMap(expected, actual map[string]string) bool {
|
||||
for expectedKey, expectedValue := range expected {
|
||||
actualValue, found := actual[expectedKey]
|
||||
if !found {
|
||||
|
||||
@@ -648,12 +648,12 @@ func Test_compareEnv(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestComparePodAnnotations(t *testing.T) {
|
||||
func TestCompareMap(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{}
|
||||
actualAnnotations := map[string]string{}
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
@@ -661,7 +661,7 @@ func TestComparePodAnnotations(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{"one": "two"}
|
||||
actualAnnotations := expectedAnnotations
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
@@ -669,7 +669,7 @@ func TestComparePodAnnotations(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{"one": "two"}
|
||||
actualAnnotations := map[string]string{"one": "two", "three": "four"}
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
@@ -677,7 +677,7 @@ func TestComparePodAnnotations(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{"one": "two"}
|
||||
actualAnnotations := map[string]string{"three": "four"}
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.False(t, got)
|
||||
})
|
||||
@@ -685,7 +685,7 @@ func TestComparePodAnnotations(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{"one": "two"}
|
||||
actualAnnotations := map[string]string{"one": "three"}
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.False(t, got)
|
||||
})
|
||||
@@ -693,7 +693,7 @@ func TestComparePodAnnotations(t *testing.T) {
|
||||
expectedAnnotations := map[string]string{"one": "two", "missing": "something"}
|
||||
actualAnnotations := map[string]string{"one": "three"}
|
||||
|
||||
got := comparePodAnnotations(expectedAnnotations, actualAnnotations)
|
||||
got := compareMap(expectedAnnotations, actualAnnotations)
|
||||
|
||||
assert.False(t, got)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user