Skip to content

Commit dbf64ad

Browse files
committed
Refactor Azure workload identity implementation in Velero: comment out label and annotation handling, update environment variable checks in tests
Signed-off-by: Tiger Kaovilai <[email protected]>
1 parent 93d08f3 commit dbf64ad

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

internal/controller/velero_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,20 +2560,23 @@ func TestDPAReconciler_buildVeleroDeploymentWithAzureWorkloadIdentity(t *testing
25602560
t.Errorf("Expected %s secret reference in envFrom", stsflow.AzureWorkloadIdentitySecretName)
25612561
}
25622562

2563-
// Also check that AZURE_CLIENT_ID env var is set
2564-
foundEnvVar := false
2563+
// Check that Azure environment variables are set
2564+
foundClientIDEnvVar := false
2565+
foundTokenFileEnvVar := false
25652566
for _, container := range tt.veleroDeployment.Spec.Template.Spec.Containers {
25662567
if container.Name == common.Velero {
25672568
for _, env := range container.Env {
25682569
if env.Name == "AZURE_CLIENT_ID" && env.Value == "test-client-id" {
2569-
foundEnvVar = true
2570-
break
2570+
foundClientIDEnvVar = true
2571+
}
2572+
if env.Name == "AZURE_FEDERATED_TOKEN_FILE" && env.Value == "/var/run/secrets/openshift/serviceaccount/token" {
2573+
foundTokenFileEnvVar = true
25712574
}
25722575
}
25732576
break
25742577
}
25752578
}
2576-
if !foundEnvVar {
2579+
if !foundClientIDEnvVar {
25772580
t.Errorf("Expected AZURE_CLIENT_ID environment variable to be set")
25782581
}
25792582
} else {

pkg/credentials/stsflow/stsflow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/apimachinery/pkg/types"
1414
"k8s.io/client-go/kubernetes"
15+
1516
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
1617
// to ensure that exec-entrypoint and run can make use of them.
1718
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -320,7 +321,7 @@ func AnnotateVeleroServiceAccountForAzureWithClient(setupLog logr.Logger, client
320321
// The annotation instructs the Workload Identity webhook to inject the AZURE_CLIENT_ID environment variable.
321322
// Since we're manually setting the environment variable in the deployment, this is just a precaution.
322323
// See: https://azure.github.io/azure-workload-identity/docs/topics/service-account-labels-and-annotations.html#service-account
323-
sa.Annotations["azure.workload.identity/client-id"] = clientID
324+
// sa.Annotations["azure.workload.identity/client-id"] = clientID
324325

325326
// Apply the patch
326327
if err := clientInstance.Patch(context.Background(), sa, client.MergeFrom(originalSA)); err != nil {

pkg/credentials/stsflow/stsflow_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func TestAnnotateVeleroServiceAccountForAzure(t *testing.T) {
492492
},
493493
expectError: false,
494494
expectedAnnotations: map[string]string{
495-
"azure.workload.identity/client-id": testClientID,
495+
// Annotation is commented out in implementation
496496
},
497497
},
498498
{
@@ -509,8 +509,8 @@ func TestAnnotateVeleroServiceAccountForAzure(t *testing.T) {
509509
},
510510
expectError: false,
511511
expectedAnnotations: map[string]string{
512-
"azure.workload.identity/client-id": testClientID,
513-
"existing-annotation": "existing-value",
512+
// Annotation is commented out in implementation, only existing annotations should remain
513+
"existing-annotation": "existing-value",
514514
},
515515
},
516516
{
@@ -629,7 +629,8 @@ AZURE_CLOUD_NAME=AzurePublicCloud
629629
Namespace: testNamespace,
630630
}, saResult)
631631
assert.NoError(t, err)
632-
assert.Equal(t, clientID, saResult.Annotations["azure.workload.identity/client-id"])
632+
// Annotation is commented out in implementation, so we shouldn't check for it
633+
// assert.Equal(t, clientID, saResult.Annotations["azure.workload.identity/client-id"])
633634
})
634635

635636
t.Run("Azure secret creation continues even if service account annotation fails", func(t *testing.T) {

0 commit comments

Comments
 (0)