#249 Improve checking the NodeSelector
This commit is contained in:
		
							parent
							
								
									8941f746b8
								
							
						
					
					
						commit
						ba122db1f6
					
				|  | @ -349,7 +349,7 @@ func (r *ReconcileJenkinsBaseConfiguration) createServiceAccount(meta metav1.Obj | |||
| 		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 { | ||||
| 			serviceAccount.Annotations[key] = value | ||||
| 		} | ||||
|  | @ -612,14 +612,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 && | ||||
| 		!compareAnnotations(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)) | ||||
|  | @ -781,7 +780,7 @@ func compareImagePullSecrets(expected, actual []corev1.LocalObjectReference) boo | |||
| 	return true | ||||
| } | ||||
| 
 | ||||
| func compareAnnotations(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 { | ||||
|  |  | |||
|  | @ -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) { | ||||
| 		expectedAnnotations := map[string]string{} | ||||
| 		actualAnnotations := map[string]string{} | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.True(t, got) | ||||
| 	}) | ||||
|  | @ -668,7 +668,7 @@ func TestComparePodAnnotations(t *testing.T) { | |||
| 		expectedAnnotations := map[string]string{"one": "two"} | ||||
| 		actualAnnotations := expectedAnnotations | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.True(t, got) | ||||
| 	}) | ||||
|  | @ -676,7 +676,7 @@ func TestComparePodAnnotations(t *testing.T) { | |||
| 		expectedAnnotations := map[string]string{"one": "two"} | ||||
| 		actualAnnotations := map[string]string{"one": "two", "three": "four"} | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.True(t, got) | ||||
| 	}) | ||||
|  | @ -684,7 +684,7 @@ func TestComparePodAnnotations(t *testing.T) { | |||
| 		expectedAnnotations := map[string]string{"one": "two"} | ||||
| 		actualAnnotations := map[string]string{"three": "four"} | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.False(t, got) | ||||
| 	}) | ||||
|  | @ -692,7 +692,7 @@ func TestComparePodAnnotations(t *testing.T) { | |||
| 		expectedAnnotations := map[string]string{"one": "two"} | ||||
| 		actualAnnotations := map[string]string{"one": "three"} | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.False(t, got) | ||||
| 	}) | ||||
|  | @ -700,7 +700,7 @@ func TestComparePodAnnotations(t *testing.T) { | |||
| 		expectedAnnotations := map[string]string{"one": "two", "missing": "something"} | ||||
| 		actualAnnotations := map[string]string{"one": "three"} | ||||
| 
 | ||||
| 		got := compareAnnotations(expectedAnnotations, actualAnnotations) | ||||
| 		got := compareMap(expectedAnnotations, actualAnnotations) | ||||
| 
 | ||||
| 		assert.False(t, got) | ||||
| 	}) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue