Skip kube-api-access Volume Comparison (#550)
* Skip kube-api-access volume comparison This hotfixes the incompatibility between the Operator and Kubernetes 1.21. Kubernetes 1.21 started adding a new volume named "kube-api-access-<random-suffix>" and that broke the comparison function and resulted in an infinite loop.
This commit is contained in:
		
							parent
							
								
									0d118bf046
								
							
						
					
					
						commit
						223119b62d
					
				|  | @ -289,16 +289,25 @@ func CompareContainerVolumeMounts(expected corev1.Container, actual corev1.Conta | ||||||
| 
 | 
 | ||||||
| // compareVolumes returns true if Jenkins pod and Jenkins CR volumes are the same
 | // compareVolumes returns true if Jenkins pod and Jenkins CR volumes are the same
 | ||||||
| func (r *JenkinsBaseConfigurationReconciler) compareVolumes(actualPod corev1.Pod) bool { | func (r *JenkinsBaseConfigurationReconciler) compareVolumes(actualPod corev1.Pod) bool { | ||||||
| 	var withoutServiceAccount []corev1.Volume | 	var toCompare []corev1.Volume | ||||||
| 	for _, volume := range actualPod.Spec.Volumes { | 	for _, volume := range actualPod.Spec.Volumes { | ||||||
| 		if !strings.HasPrefix(volume.Name, actualPod.Spec.ServiceAccountName) { | 		// filter out service account
 | ||||||
| 			withoutServiceAccount = append(withoutServiceAccount, volume) | 		if strings.HasPrefix(volume.Name, actualPod.Spec.ServiceAccountName) { | ||||||
|  | 			continue | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  | 		// hotfix for k8s 1.21 - filter out kube-api-access-<random-suffix>
 | ||||||
|  | 		const kubeAPIAccessPrefix = "kube-api-access-" | ||||||
|  | 		if strings.HasPrefix(volume.Name, kubeAPIAccessPrefix) { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		toCompare = append(toCompare, volume) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return reflect.DeepEqual( | 	return reflect.DeepEqual( | ||||||
| 		append(resources.GetJenkinsMasterPodBaseVolumes(r.Configuration.Jenkins), r.Configuration.Jenkins.Spec.Master.Volumes...), | 		append(resources.GetJenkinsMasterPodBaseVolumes(r.Configuration.Jenkins), r.Configuration.Jenkins.Spec.Master.Volumes...), | ||||||
| 		withoutServiceAccount, | 		toCompare, | ||||||
| 	) | 	) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue