@@ -67,7 +67,7 @@ func TestCreateAndDeleteOfAffinityAssistant(t *testing.T) {
67
67
t .Errorf ("unexpected error when retrieving StatefulSet: %v" , err )
68
68
}
69
69
70
- err = c .cleanupAffinityAssistants (testPipelineRun )
70
+ err = c .cleanupAffinityAssistants (context . Background (), testPipelineRun )
71
71
if err != nil {
72
72
t .Errorf ("unexpected error from cleanupAffinityAssistants: %v" , err )
73
73
}
@@ -146,6 +146,50 @@ func TestThatAffinityAssistantNameIsNoLongerThan53(t *testing.T) {
146
146
}
147
147
}
148
148
149
+ // TestThatCleanupIsAvoidedIfAssistantIsDisabled tests that
150
+ // cleanup of Affinity Assistants is omitted when the
151
+ // Affinity Assistant is disabled
152
+ func TestThatCleanupIsAvoidedIfAssistantIsDisabled (t * testing.T ) {
153
+ testPipelineRun := & v1beta1.PipelineRun {
154
+ TypeMeta : metav1.TypeMeta {Kind : "PipelineRun" },
155
+ ObjectMeta : metav1.ObjectMeta {
156
+ Name : "test-pipelinerun" ,
157
+ },
158
+ Spec : v1beta1.PipelineRunSpec {
159
+ Workspaces : []v1beta1.WorkspaceBinding {{
160
+ Name : "test-workspace" ,
161
+ PersistentVolumeClaim : & corev1.PersistentVolumeClaimVolumeSource {
162
+ ClaimName : "myclaim" ,
163
+ },
164
+ }},
165
+ },
166
+ }
167
+
168
+ configMap := & corev1.ConfigMap {
169
+ ObjectMeta : metav1.ObjectMeta {Name : config .GetFeatureFlagsConfigName (), Namespace : system .GetNamespace ()},
170
+ Data : map [string ]string {
171
+ featureFlagDisableAffinityAssistantKey : "true" ,
172
+ },
173
+ }
174
+
175
+ fakeClientSet := fakek8s .NewSimpleClientset (
176
+ configMap ,
177
+ )
178
+
179
+ c := Reconciler {
180
+ KubeClientSet : fakeClientSet ,
181
+ Images : pipeline.Images {},
182
+ }
183
+ store := config .NewStore (logtesting .TestLogger (t ))
184
+ store .OnConfigChanged (configMap )
185
+
186
+ _ = c .cleanupAffinityAssistants (store .ToContext (context .Background ()), testPipelineRun )
187
+
188
+ if len (fakeClientSet .Actions ()) != 0 {
189
+ t .Errorf ("Expected 0 k8s client requests, did %d request" , len (fakeClientSet .Actions ()))
190
+ }
191
+ }
192
+
149
193
func TestDisableAffinityAssistant (t * testing.T ) {
150
194
for _ , tc := range []struct {
151
195
description string
0 commit comments