Skip to content

Commit 3a625a6

Browse files
committed
fix: detach managed serviceaccounts by owner
1 parent b7da935 commit 3a625a6

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

internal/controller/codercontrolplane_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,8 @@ func (r *CoderControlPlaneReconciler) detachManagedServiceAccounts(
534534
ctx,
535535
serviceAccounts,
536536
client.InNamespace(coderControlPlane.Namespace),
537-
client.MatchingLabels(controlPlaneLabels(coderControlPlane.Name)),
538537
); err != nil {
539-
return fmt.Errorf("list managed service accounts: %w", err)
538+
return fmt.Errorf("list service accounts for detachment: %w", err)
540539
}
541540

542541
for i := range serviceAccounts.Items {

internal/controller/codercontrolplane_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,9 @@ func TestReconcile_ServiceAccount(t *testing.T) {
22582258
Image: "test-serviceaccount:latest",
22592259
ServiceAccount: coderv1alpha1.ServiceAccountSpec{
22602260
Name: "test-serviceaccount-disable-detach-sa",
2261+
Labels: map[string]string{
2262+
"app.kubernetes.io/instance": "custom-instance-label",
2263+
},
22612264
},
22622265
},
22632266
}
@@ -2279,6 +2282,9 @@ func TestReconcile_ServiceAccount(t *testing.T) {
22792282
if err := k8sClient.Get(ctx, types.NamespacedName{Name: serviceAccountName, Namespace: cp.Namespace}, serviceAccount); err != nil {
22802283
t.Fatalf("get managed service account: %v", err)
22812284
}
2285+
if got := serviceAccount.Labels["app.kubernetes.io/instance"]; got != "custom-instance-label" {
2286+
t.Fatalf("expected reserved instance label override to be applied, got %q", got)
2287+
}
22822288
ownerReference := metav1.GetControllerOf(serviceAccount)
22832289
if ownerReference == nil || ownerReference.UID != cp.UID {
22842290
t.Fatalf("expected service account to be controller-owned before disableCreate=true, got %#v", ownerReference)

0 commit comments

Comments
 (0)