Skip to content

Commit 2a21ee7

Browse files
feat: allow to ignore volumes during reconciliation
1 parent 8a66d65 commit 2a21ee7

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

api/v1alpha2/jenkins_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ type JenkinsMaster struct {
400400
// Defaults to 30 seconds.
401401
// +optional
402402
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
403+
404+
// IgnoredVolumes defines the list of volume names that should be excluded from processing or consideration.
405+
// +optional
406+
IgnoredVolumes []string `json:"ignoredVolumes,omitempty"`
403407
}
404408

405409
// Service defines Kubernetes service attributes

pkg/configuration/base/reconcile_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,47 @@ func TestCompareVolumes(t *testing.T) {
160160

161161
assert.True(t, got)
162162
})
163+
164+
t.Run("different - additional workspace identity volume", func(t *testing.T) {
165+
jenkins := &v1alpha2.Jenkins{
166+
Spec: v1alpha2.JenkinsSpec{
167+
Master: v1alpha2.JenkinsMaster{},
168+
},
169+
}
170+
pod := corev1.Pod{
171+
Spec: corev1.PodSpec{
172+
ServiceAccountName: "service-account-name",
173+
Volumes: append(resources.GetJenkinsMasterPodBaseVolumes(jenkins), corev1.Volume{Name: "azure-identity-token"}),
174+
},
175+
}
176+
reconciler := New(configuration.Configuration{Jenkins: jenkins}, client.JenkinsAPIConnectionSettings{})
177+
178+
got := reconciler.compareVolumes(pod)
179+
180+
assert.False(t, got)
181+
})
182+
183+
t.Run("additional workspace identity volume but ignored", func(t *testing.T) {
184+
jenkins := &v1alpha2.Jenkins{
185+
Spec: v1alpha2.JenkinsSpec{
186+
Master: v1alpha2.JenkinsMaster{
187+
IgnoredVolumes: []string{"azure-identity-token"},
188+
},
189+
},
190+
}
191+
pod := corev1.Pod{
192+
Spec: corev1.PodSpec{
193+
ServiceAccountName: "service-account-name",
194+
Volumes: append(resources.GetJenkinsMasterPodBaseVolumes(jenkins), corev1.Volume{Name: "azure-identity-token"}),
195+
},
196+
}
197+
reconciler := New(configuration.Configuration{Jenkins: jenkins}, client.JenkinsAPIConnectionSettings{})
198+
199+
got := reconciler.compareVolumes(pod)
200+
201+
assert.True(t, got)
202+
})
203+
163204
}
164205

165206
func TestJenkinsBaseConfigurationReconciler_verifyPlugins(t *testing.T) {

pkg/configuration/base/reconciler.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ func CompareContainerVolumeMounts(expected corev1.Container, actual corev1.Conta
294294
func (r *JenkinsBaseConfigurationReconciler) compareVolumes(actualPod corev1.Pod) bool {
295295
var toCompare []corev1.Volume
296296
for _, volume := range actualPod.Spec.Volumes {
297+
298+
if r.isVolumeIgnored(volume.Name) {
299+
continue
300+
}
301+
297302
// filter out service account
298303
if strings.HasPrefix(volume.Name, actualPod.Spec.ServiceAccountName) {
299304
continue
@@ -421,3 +426,13 @@ func (r *JenkinsBaseConfigurationReconciler) ensureBaseConfiguration(jenkinsClie
421426
})
422427
return reconcile.Result{Requeue: requeue}, err
423428
}
429+
430+
// isVolumeIgnored checks if the given volume name is in the list of ignored volumes
431+
func (r *JenkinsBaseConfigurationReconciler) isVolumeIgnored(volumeName string) bool {
432+
for _, ignoredVolume := range r.Jenkins.Spec.Master.IgnoredVolumes {
433+
if ignoredVolume == volumeName {
434+
return true
435+
}
436+
}
437+
return false
438+
}

0 commit comments

Comments
 (0)