Skip to content

add Azure Workload Identity support to kubevirt-datamover controller - #2362

Open
sseago wants to merge 1 commit into
openshift:oadp-devfrom
sseago:azure-sts
Open

add Azure Workload Identity support to kubevirt-datamover controller#2362
sseago wants to merge 1 commit into
openshift:oadp-devfrom
sseago:azure-sts

Conversation

@sseago

@sseago sseago commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Why the changes were made

For Azure Workload Identity, the same AZURE env vars we're adding to the Velero deployment also need to be added to the KDM controller.

migtools/kubevirt-datamover-controller#98

How to test the changes made

In an Azure STS cluster, the following env vars should be added to the KDM controller

$ oc exec deployment/oadp-kubevirt-datamover-controller-manager -n openshift-adp -- env | grep AZURE
AZURE_CLIENT_ID=...
AZURE_FEDERATED_TOKEN_FILE=/var/run/secrets/openshift/serviceaccount/token
AZURE_TENANT_ID=...

Summary by CodeRabbit

  • New Features
    • Added support for Azure Workload Identity in the KubeVirt DataMover.
    • Deployments can now use configured workload identity credentials when the required Azure settings are available.
    • Existing DataMover deployments are updated consistently to apply the identity configuration.

…oller

Co-authored-by: aider (gemini/gemini-3.1-pro-preview) <aider@aider.chat>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The KubeVirt DataMover controller now supports Azure Workload Identity STS configuration. It adds the configured Secret reference when all required Azure environment variables are present, during both container creation and reconciliation.

Changes

Azure Workload Identity support

Layer / File(s) Summary
Configure manager container environment
internal/controller/kubevirt_datamover_controller.go
The controller detects the required Azure client, tenant, and subscription settings, builds an optional EnvFrom Secret reference, and applies it to new and existing manager containers.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: shubham-pampattiwar

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the purpose, links the related issue, and provides a concrete Azure STS verification command.
Title check ✅ Passed The title clearly and concisely describes the main change: Azure Workload Identity support for the KubeVirt DataMover controller.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The PR changes only the controller; no test files or Ginkgo titles changed. Related titles use static descriptive strings.
Test Structure And Quality ✅ Passed The PR changes only production code and modifies no Ginkgo test files; therefore the test-structure and quality requirements are not applicable to this diff.
Microshift Test Compatibility ✅ Passed The pull request changes only the controller implementation and adds no new Ginkgo e2e tests, so MicroShift test compatibility is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The commit modifies only the controller implementation; it adds no test files or Ginkgo declarations, so no SNO compatibility assumption is introduced.
Topology-Aware Scheduling Compatibility ✅ Passed The controller diff only adds Azure EnvFrom handling; it adds no node selectors, affinity, topology spread, tolerations, PDB, replica-count, or rollout scheduling constraints.
Ote Binary Stdout Contract ✅ Passed The PR changes only reconciliation code; no OTE binary or openshift-tests integration exists, and no process-level stdout write was added.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The pull request changes only the controller implementation. No Ginkgo e2e tests or external network calls were added, so this check is not applicable.
No-Weak-Crypto ✅ Passed The patch only checks Azure configuration presence and adds a Kubernetes Secret reference; it introduces no weak crypto, custom crypto, or secret/token comparison.
Container-Privileges ✅ Passed The PR only adds Azure SecretEnvSource wiring. It adds no privileged, host namespace, SYS_ADMIN, or root settings; KDM uses RunAsNonRoot and allowPrivilegeEscalation=false.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds only a generic status log. It does not log Azure IDs, tokens, secret contents, hostnames, or customer data; the secret is referenced through EnvFrom.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from Joeavaikath and kaovilai August 6, 2026 23:08
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/controller/kubevirt_datamover_controller.go`:
- Around line 183-196: Update the KubeVirt DataMover Pod template construction
alongside the Azure workload identity envFrom setup to include an annotation
derived from the referenced Azure Secret’s resource version or content hash.
Ensure this annotation changes whenever the Secret changes, triggering
Deployment rollout and fresh environment values in existing Pods; add coverage
for Azure identity rotation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f8995c80-9d6b-4396-ae53-79d4b276049b

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6f637 and 50677f3.

📒 Files selected for processing (1)
  • internal/controller/kubevirt_datamover_controller.go

Comment on lines +183 to +196
// Add Azure workload identity environment variables if configured
var envFrom []corev1.EnvFromSource
azureClientID := os.Getenv(stsflow.ClientIDEnvKey)
if azureClientID != "" && os.Getenv(stsflow.TenantIDEnvKey) != "" && os.Getenv(stsflow.SubscriptionIDEnvKey) != "" {
envFrom = append(envFrom, corev1.EnvFromSource{
SecretRef: &corev1.SecretEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: stsflow.AzureWorkloadIdentitySecretName,
},
},
})
r.Log.Info("Added Azure workload identity secret reference to KubeVirt DataMover container")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 8 \
  'ReconcileAzureWorkloadIdentitySecret|AzureWorkloadIdentitySecretName|AZURE_(CLIENT_ID|TENANT_ID|FEDERATED_TOKEN_FILE)|EnvFrom|ResourceVersion|resource-version|revision|sha256' \
  --glob '*.go' .

Repository: openshift/oadp-operator

Length of output: 50380


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- target controller outline ---'
ast-grep outline internal/controller/kubevirt_datamover_controller.go
echo '--- target controller relevant symbols ---'
rg -n -C 12 'AzureWorkloadIdentitySecretName|ClientIDEnvKey|TenantIDEnvKey|SubscriptionIDEnvKey|EnvFrom|DataMover|Deployment|Reconcile' internal/controller/kubevirt_datamover_controller.go
echo '--- STS reconciler symbols and secret updates ---'
rg -n -C 14 'ReconcileAzureWorkloadIdentitySecret|CreateOrUpdateSTSSecretWithClientsAndWait|AzureWorkloadIdentitySecretName|ClientIDEnvKey|TenantIDEnvKey|SubscriptionIDEnvKey|FEDERATED_TOKEN' pkg/credentials/stsflow internal/controller
echo '--- target controller tests and callers ---'
rg -n -C 10 'KubeVirt|DataMover|AzureWorkloadIdentity|EnvFrom|SecretRef' internal/controller/*test.go

Repository: openshift/oadp-operator

Length of output: 50380


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- target deployment construction ---'
sed -n '183,220p' internal/controller/kubevirt_datamover_controller.go
sed -n '260,340p' internal/controller/kubevirt_datamover_controller.go

echo '--- Azure STS controller ---'
wc -l internal/controller/stsflow.go
cat -n internal/controller/stsflow.go

echo '--- STS secret update implementation ---'
sed -n '85,145p' pkg/credentials/stsflow/stsflow.go
sed -n '224,330p' pkg/credentials/stsflow/stsflow.go

echo '--- all call sites for Azure STS reconciliation and KubeVirt reconciliation ---'
rg -n -C 8 'ReconcileAzureWorkloadIdentitySecret|STSStandardizedFlow|CreateOrUpdateSTSSecretWithClients|ReconcileKubevirtDatamoverController' --glob '*.go' .

Repository: openshift/oadp-operator

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- controller setup and owned-resource watches ---'
sed -n '55,135p' internal/controller/dataprotectionapplication_controller.go
rg -n -C 8 'Owns\(|For\(|Complete\(|SetupWithManager|Secret' internal/controller/dataprotectionapplication_controller.go

echo '--- KubeVirt controller tests for Azure envFrom and template changes ---'
rg -n -C 12 'CLIENTID|TENANTID|SUBSCRIPTIONID|AZURE|EnvFrom|Annotations|PodTemplate|ResourceVersion' internal/controller/kubevirt_datamover_controller_test.go

echo '--- source-level invariant probe ---'
python3 - <<'PY'
from pathlib import Path
p = Path("internal/controller/kubevirt_datamover_controller.go").read_text()
start = p.index("func ensureKubevirtDatamoverRequiredSpecs")
end = p.index("\nfunc ", start + 5)
fn = p[start:end]
checks = {
    "reads operator Azure environment": 'os.Getenv(stsflow.ClientIDEnvKey)' in fn,
    "references Azure Secret through EnvFrom": 'Name: stsflow.AzureWorkloadIdentitySecretName' in fn,
    "assigns EnvFrom to manager": 'kubevirtDatamoverContainer.EnvFrom = envFrom' in fn,
    "reads Secret resource version": '.ResourceVersion' in fn,
    "gets Secret from Kubernetes API": 'r.Get(' in fn,
    "adds Secret content revision": 'sha256' in fn or 'revision' in fn,
}
for name, value in checks.items():
    print(f"{name}: {value}")
PY

Repository: openshift/oadp-operator

Length of output: 25295


🌐 Web query:

Kubernetes official documentation Secret environment variables not updated automatically running container

💡 Result:

In Kubernetes, environment variables injected into a container from a Secret (or ConfigMap) are not updated automatically when the underlying Secret is modified [1][2]. These environment variables are only set when the Pod is created [1][3]. Because they are part of the process environment, they cannot be changed without terminating and recreating the container or the Pod [1][4]. If you need to update the values used by your application, you have the following options: 1. Perform a rolling update: The standard way to propagate changes is to trigger a rollout of the Deployment [1][4]. This can be done by running: kubectl rollout restart deployment This command replaces existing Pods with new ones that will pull the updated Secret values [1][5]. 2. Use Volumes instead of environment variables: If your application can be configured to read values from files, mounting the Secret as a volume is an alternative [6][2]. When a Secret is mounted as a volume, Kubernetes automatically updates the projected files (after a brief delay for kubelet synchronization), which allows many applications to detect the change and reload the configuration without requiring a Pod restart [4][2]. Note: Simply updating the Secret does not affect running Pods [1][4]. If you do not perform a rollout or recreate the Pods, the containers will continue to use the stale environment variable values from their initial startup [1][5].

Citations:


Add a rollout trigger for Azure Secret changes.

envFrom values are set only when the Pod starts. Secret updates enqueue DPA reconciliation, but the Deployment template keeps the same SecretRef, so existing KubeVirt DataMover Pods retain stale Azure identity values. Add a Secret resource-version or content-hash annotation to the Pod template and test Azure identity rotation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/controller/kubevirt_datamover_controller.go` around lines 183 - 196,
Update the KubeVirt DataMover Pod template construction alongside the Azure
workload identity envFrom setup to include an annotation derived from the
referenced Azure Secret’s resource version or content hash. Ensure this
annotation changes whenever the Secret changes, triggering Deployment rollout
and fresh environment values in existing Pods; add coverage for Azure identity
rotation.

Source: MCP tools

@weshayutin weshayutin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/LGTM

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shubham-pampattiwar, sseago, weshayutin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [shubham-pampattiwar,sseago]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 5b6f637 and 2 for PR HEAD 50677f3 in total

@shubham-pampattiwar

Copy link
Copy Markdown
Member

/cherry-pick oadp-1.6

@openshift-cherrypick-robot

Copy link
Copy Markdown
Contributor

@shubham-pampattiwar: once the present PR merges, I will cherry-pick it on top of oadp-1.6 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick oadp-1.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@sseago

sseago commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

/retest-required

@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown

@sseago: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/5.1-images 50677f3 link true /test 5.1-images
ci/prow/5.1-e2e-test-cli-aws 50677f3 link true /test 5.1-e2e-test-cli-aws
ci/prow/5.1-e2e-test-aws 50677f3 link true /test 5.1-e2e-test-aws
ci/prow/5.1-ci-index 50677f3 link true /test 5.1-ci-index
ci/prow/4.23-e2e-test-aws 50677f3 link false /test 4.23-e2e-test-aws

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants