From 223119b62d8770f000e5bc6b46d5a1cec1fb0b9b Mon Sep 17 00:00:00 2001 From: Piotr Ryba <55996264+prryb@users.noreply.github.com> Date: Wed, 28 Apr 2021 14:23:00 +0200 Subject: [PATCH] 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-" and that broke the comparison function and resulted in an infinite loop. --- pkg/configuration/base/reconciler.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/configuration/base/reconciler.go b/pkg/configuration/base/reconciler.go index e314ad08..431aec8a 100644 --- a/pkg/configuration/base/reconciler.go +++ b/pkg/configuration/base/reconciler.go @@ -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 func (r *JenkinsBaseConfigurationReconciler) compareVolumes(actualPod corev1.Pod) bool { - var withoutServiceAccount []corev1.Volume + var toCompare []corev1.Volume for _, volume := range actualPod.Spec.Volumes { - if !strings.HasPrefix(volume.Name, actualPod.Spec.ServiceAccountName) { - withoutServiceAccount = append(withoutServiceAccount, volume) + // filter out service account + if strings.HasPrefix(volume.Name, actualPod.Spec.ServiceAccountName) { + continue } + + // hotfix for k8s 1.21 - filter out kube-api-access- + const kubeAPIAccessPrefix = "kube-api-access-" + if strings.HasPrefix(volume.Name, kubeAPIAccessPrefix) { + continue + } + + toCompare = append(toCompare, volume) } return reflect.DeepEqual( append(resources.GetJenkinsMasterPodBaseVolumes(r.Configuration.Jenkins), r.Configuration.Jenkins.Spec.Master.Volumes...), - withoutServiceAccount, + toCompare, ) }