fix: gracefully handle missing AKS cluster during postprovision hook#7501
fix: gracefully handle missing AKS cluster during postprovision hook#7501jongio wants to merge 2 commits intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the AKS service target’s lifecycle hook behavior so that postprovision no longer fails fatally when an AKS cluster isn’t present yet (common in multi-phase provisioning), while keeping predeploy strict to avoid masking real deployment-time issues.
Changes:
- Add
postprovision-specific “graceful skip” behavior insetK8sContext()when the AKS target resource is missing/empty or Kubernetes context setup fails. - Extract a
skipPostprovisionK8sSetup()helper to consolidate the warning-and-continue logic. - Add new AKS service target tests covering postprovision skip scenarios and ensuring predeploy still fails when appropriate.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cli/azd/pkg/project/service_target_aks.go | Implements postprovision-specific skip logic and a helper for warning/continue behavior. |
| cli/azd/pkg/project/service_target_aks_test.go | Adds table-driven tests for postprovision skipping, happy-path coverage, and a predeploy regression guard. |
When infrastructure doesn't include AKS resources, the postprovision lifecycle hook in the AKS service target fails fatally trying to set up the Kubernetes context. This is expected in multi-phase provisioning workflows where AKS gets provisioned later. Modified setK8sContext() to detect the postprovision event and skip gracefully (with a user-visible warning) instead of failing when: - GetTargetResource returns an error (resource not found) - Target resource has an empty name (SupportsDelayedProvisioning) - Cluster credentials are unavailable (ensureClusterContext fails) - Namespace creation fails (ensureNamespace fails) The predeploy event path is unchanged and still fails fatally, ensuring deployment-time errors are not masked. Extracted skipPostprovisionK8sSetup() helper to eliminate repeated warning/log/return-nil pattern across all four skip points. Fixes Azure#3272 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- skipPostprovisionK8sSetup now checks ctx.Err() before returning nil to avoid swallowing context cancellation/timeouts (Ctrl+C) - Added Test_Postprovision_Skips_When_Namespace_Fails covering the ensureNamespace failure path during postprovision Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
783293b to
bbea4d8
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Summary
Fixes #3272
When infrastructure doesn't include AKS resources, the
postprovisionlifecycle hook in the AKS service target fails fatally trying to set up the Kubernetes context. This is expected in multi-phase provisioning workflows where AKS gets provisioned later.Changes
cli/azd/pkg/project/service_target_aks.gosetK8sContext()to detect thepostprovisionevent and skip gracefully (with a user-visible warning) instead of failing when:GetTargetResourcereturns an error (resource not found)SupportsDelayedProvisioning)ensureClusterContextfails)ensureNamespacefails)skipPostprovisionK8sSetup()helper to consolidate the repeated warning/log/return-nil patternpredeployevent path is unchanged and still fails fatally — deployment-time errors are not maskedcli/azd/pkg/project/service_target_aks_test.goTest_Postprovision_GracefulSkipwith 3 sub-tests:SkipsWhenResourceNotProvisioned— empty target resource nameSkipsWhenGetTargetResourceFails— resource group not foundSkipsWhenCredentialsFail— 401 from credential retrievalTest_Postprovision_Succeeds_When_Cluster_Available— happy path verifying normal flow when cluster existsTest_Predeploy_Still_Fails_When_Cluster_Not_Found— regression guard ensuring predeploy still errorscreateAksServiceTargetWithResourceManagerhelper for custom resource manager injectionTesting
All 8 AKS-related tests pass (3 existing + 5 new), zero regressions.