refactor: define and use struct for lifecycle-ignore
This commit is contained in:
parent
2a21ee7c2c
commit
dcf1b26122
|
|
@ -73,6 +73,21 @@ type JenkinsSpec struct {
|
||||||
|
|
||||||
// JenkinsAPISettings defines configuration used by the operator to gain admin access to the Jenkins API
|
// JenkinsAPISettings defines configuration used by the operator to gain admin access to the Jenkins API
|
||||||
JenkinsAPISettings JenkinsAPISettings `json:"jenkinsAPISettings"`
|
JenkinsAPISettings JenkinsAPISettings `json:"jenkinsAPISettings"`
|
||||||
|
|
||||||
|
// +optional
|
||||||
|
Lifecycle JenkinsLifecycle `json:"lifecycle,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JenkinsLifecycle struct {
|
||||||
|
// +optional
|
||||||
|
Ignore JenkinsLifecycleIgnore `json:"ignore,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JenkinsLifecycleIgnore struct {
|
||||||
|
IgnoredVolumes []string `json:"volumes,omitempty"`
|
||||||
|
IgnoredEnvs []string `json:"envs,omitempty"`
|
||||||
|
IgnoredAnnotations []string `json:"annotations,omitempty"`
|
||||||
|
IgnoredLabels []string `json:"labels,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthorizationStrategy defines authorization strategy of the operator for the Jenkins API
|
// AuthorizationStrategy defines authorization strategy of the operator for the Jenkins API
|
||||||
|
|
@ -404,6 +419,18 @@ type JenkinsMaster struct {
|
||||||
// IgnoredVolumes defines the list of volume names that should be excluded from processing or consideration.
|
// IgnoredVolumes defines the list of volume names that should be excluded from processing or consideration.
|
||||||
// +optional
|
// +optional
|
||||||
IgnoredVolumes []string `json:"ignoredVolumes,omitempty"`
|
IgnoredVolumes []string `json:"ignoredVolumes,omitempty"`
|
||||||
|
|
||||||
|
// IgnoredAnnotations specifies a list of annotation keys that should be ignored during configuration updates.
|
||||||
|
// +optional
|
||||||
|
IgnoredAnnotations []string `json:"ignoredAnnotations,omitempty"`
|
||||||
|
|
||||||
|
// IgnoredEnvVars defines the list of environment variable names that should be excluded from the Jenkins master pod.
|
||||||
|
// +optional
|
||||||
|
IgnoredEnvVars []string `json:"ignoredEnvVars,omitempty"`
|
||||||
|
|
||||||
|
// IgnoredLabels specifies the list of labels to be excluded from configuration or processing in the Jenkins master.
|
||||||
|
// +optional
|
||||||
|
IgnoredLabels []string `json:"ignoredLabels,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service defines Kubernetes service attributes
|
// Service defines Kubernetes service attributes
|
||||||
|
|
|
||||||
|
|
@ -182,11 +182,14 @@ func TestCompareVolumes(t *testing.T) {
|
||||||
|
|
||||||
t.Run("additional workspace identity volume but ignored", func(t *testing.T) {
|
t.Run("additional workspace identity volume but ignored", func(t *testing.T) {
|
||||||
jenkins := &v1alpha2.Jenkins{
|
jenkins := &v1alpha2.Jenkins{
|
||||||
|
|
||||||
Spec: v1alpha2.JenkinsSpec{
|
Spec: v1alpha2.JenkinsSpec{
|
||||||
Master: v1alpha2.JenkinsMaster{
|
Lifecycle: v1alpha2.JenkinsLifecycle{
|
||||||
|
Ignore: v1alpha2.JenkinsLifecycleIgnore{
|
||||||
IgnoredVolumes: []string{"azure-identity-token"},
|
IgnoredVolumes: []string{"azure-identity-token"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
pod := corev1.Pod{
|
pod := corev1.Pod{
|
||||||
Spec: corev1.PodSpec{
|
Spec: corev1.PodSpec{
|
||||||
|
|
@ -201,6 +204,30 @@ func TestCompareVolumes(t *testing.T) {
|
||||||
assert.True(t, got)
|
assert.True(t, got)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("additional multiple volumes added but ignored", func(t *testing.T) {
|
||||||
|
jenkins := &v1alpha2.Jenkins{
|
||||||
|
|
||||||
|
Spec: v1alpha2.JenkinsSpec{
|
||||||
|
Lifecycle: v1alpha2.JenkinsLifecycle{
|
||||||
|
Ignore: v1alpha2.JenkinsLifecycleIgnore{
|
||||||
|
IgnoredVolumes: []string{"volume-present", "volume-absent"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pod := corev1.Pod{
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
ServiceAccountName: "service-account-name",
|
||||||
|
Volumes: append(resources.GetJenkinsMasterPodBaseVolumes(jenkins), corev1.Volume{Name: "volume-present"}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
reconciler := New(configuration.Configuration{Jenkins: jenkins}, client.JenkinsAPIConnectionSettings{})
|
||||||
|
|
||||||
|
got := reconciler.compareVolumes(pod)
|
||||||
|
|
||||||
|
assert.True(t, got)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJenkinsBaseConfigurationReconciler_verifyPlugins(t *testing.T) {
|
func TestJenkinsBaseConfigurationReconciler_verifyPlugins(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,7 @@ func (r *JenkinsBaseConfigurationReconciler) ensureBaseConfiguration(jenkinsClie
|
||||||
|
|
||||||
// isVolumeIgnored checks if the given volume name is in the list of ignored volumes
|
// isVolumeIgnored checks if the given volume name is in the list of ignored volumes
|
||||||
func (r *JenkinsBaseConfigurationReconciler) isVolumeIgnored(volumeName string) bool {
|
func (r *JenkinsBaseConfigurationReconciler) isVolumeIgnored(volumeName string) bool {
|
||||||
for _, ignoredVolume := range r.Jenkins.Spec.Master.IgnoredVolumes {
|
for _, ignoredVolume := range r.Jenkins.Spec.Lifecycle.Ignore.IgnoredVolumes {
|
||||||
if ignoredVolume == volumeName {
|
if ignoredVolume == volumeName {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue