Skip to content

Commit 97129d0

Browse files
jlpetterssontekton-robot
authored andcommitted
Omit cleaning up the Affinity Assistant if disabled
This commit introduces a check if the Assistant is disabled, and only cleanup the Assistant if disabled
1 parent 3cf297a commit 97129d0

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

pkg/reconciler/pipelinerun/affinity_assistant.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ func getClaimName(w v1beta1.WorkspaceBinding, ownerReference metav1.OwnerReferen
8383
return ""
8484
}
8585

86-
func (c *Reconciler) cleanupAffinityAssistants(pr *v1beta1.PipelineRun) error {
86+
func (c *Reconciler) cleanupAffinityAssistants(ctx context.Context, pr *v1beta1.PipelineRun) error {
87+
88+
// omit cleanup if the feature is disabled
89+
if c.isAffinityAssistantDisabled(ctx) {
90+
return nil
91+
}
92+
8793
var errs []error
8894
for _, w := range pr.Spec.Workspaces {
8995
if w.PersistentVolumeClaim != nil || w.VolumeClaimTemplate != nil {

pkg/reconciler/pipelinerun/affinity_assistant_test.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestCreateAndDeleteOfAffinityAssistant(t *testing.T) {
6767
t.Errorf("unexpected error when retrieving StatefulSet: %v", err)
6868
}
6969

70-
err = c.cleanupAffinityAssistants(testPipelineRun)
70+
err = c.cleanupAffinityAssistants(context.Background(), testPipelineRun)
7171
if err != nil {
7272
t.Errorf("unexpected error from cleanupAffinityAssistants: %v", err)
7373
}
@@ -146,6 +146,50 @@ func TestThatAffinityAssistantNameIsNoLongerThan53(t *testing.T) {
146146
}
147147
}
148148

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+
149193
func TestDisableAffinityAssistant(t *testing.T) {
150194
for _, tc := range []struct {
151195
description string

pkg/reconciler/pipelinerun/pipelinerun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, pr *v1beta1.PipelineRun)
168168
logger.Errorf("Failed to delete PVC for PipelineRun %s: %v", pr.Name, err)
169169
return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err)
170170
}
171-
if err := c.cleanupAffinityAssistants(pr); err != nil {
171+
if err := c.cleanupAffinityAssistants(ctx, pr); err != nil {
172172
logger.Errorf("Failed to delete StatefulSet for PipelineRun %s: %v", pr.Name, err)
173173
return c.finishReconcileUpdateEmitEvents(ctx, pr, before, err)
174174
}

0 commit comments

Comments
 (0)