Commit e5cd73b
fix: gracefully handle missing AKS cluster during postprovision hook (Azure#7501)
* fix: gracefully handle missing AKS cluster during postprovision hook
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>
* address review: propagate ctx cancellation, add namespace failure test
- 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>
* refactor: address MQ review — typed constant, DRY helper, ctx cancellation test
- Replace magic string 'postprovision' with typed postProvisionEvent constant
- Extract postprovisionK8sError() helper to eliminate 4 identical if-blocks
- Add nil-guard on targetResource before calling ResourceName()
- Fix log.Printf double newline and redundant .Error() call
- Add Test_Postprovision_Propagates_Context_Cancellation to cover
the ctx.Err() safety valve in skipPostprovisionK8sSetup
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: address review feedback — event guards, constants, test assertions
- Route targetResource==nil through event-aware postprovisionK8sError
so predeploy doesn't silently skip (thread #1, High)
- Add preDeployEvent constant replacing raw "predeploy" strings for
consistency with postProvisionEvent (thread #2)
- Add console message assertions to graceful-skip tests verifying the
warning was actually emitted (thread #3)
- Add predeploy failure tests for credential and namespace error paths
confirming errors propagate for non-postprovision events (thread #4)
- Refactor createAksServiceTarget to delegate to
createAksServiceTargetWithResourceManager, eliminating ~40 lines of
duplication (thread #5)
- Add structured telemetry span (AksPostprovisionSkipEvent) to the
graceful-skip path for production monitoring (thread #6)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: address re-review - telemetry span, DRY assertions, ErrorContains
- Use span.End() with skip.reason attribute instead of EndWithStatus()
to avoid marking intentional skips as errors in telemetry dashboards
- Extract assertSkipWarningEmitted helper to deduplicate console
assertion blocks across two test functions
- Add ErrorContains assertion in Test_Predeploy_Fails_When_Credentials_Fail
for consistency with sibling namespace test
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: narrow postprovision graceful skip to not-found only
Address @weikanglim's feedback: limit the graceful skip path to
the explicit delayed-provisioning case (empty ResourceName) only.
GetTargetResource, ensureClusterContext, and ensureNamespace errors
now propagate during postprovision — real failures are no longer masked.
Removed postprovisionK8sError helper. Fixed gofmt import ordering.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6f0ed59 commit e5cd73b
3 files changed
Lines changed: 595 additions & 77 deletions
File tree
- cli/azd
- internal/tracing/events
- pkg/project
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
141 | 151 | | |
142 | 152 | | |
143 | 153 | | |
144 | | - | |
| 154 | + | |
145 | 155 | | |
146 | | - | |
| 156 | + | |
147 | 157 | | |
148 | 158 | | |
149 | 159 | | |
| |||
153 | 163 | | |
154 | 164 | | |
155 | 165 | | |
156 | | - | |
157 | | - | |
| 166 | + | |
| 167 | + | |
158 | 168 | | |
159 | 169 | | |
160 | 170 | | |
| |||
895 | 905 | | |
896 | 906 | | |
897 | 907 | | |
898 | | - | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
899 | 913 | | |
900 | 914 | | |
901 | 915 | | |
| |||
906 | 920 | | |
907 | 921 | | |
908 | 922 | | |
909 | | - | |
| 923 | + | |
| 924 | + | |
910 | 925 | | |
911 | 926 | | |
912 | 927 | | |
913 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
914 | 944 | | |
915 | | - | |
| 945 | + | |
| 946 | + | |
916 | 947 | | |
917 | 948 | | |
918 | 949 | | |
| |||
922 | 953 | | |
923 | 954 | | |
924 | 955 | | |
925 | | - | |
926 | | - | |
927 | | - | |
928 | | - | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
929 | 964 | | |
930 | 965 | | |
931 | 966 | | |
932 | 967 | | |
933 | 968 | | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
934 | 997 | | |
935 | 998 | | |
936 | 999 | | |
| |||
0 commit comments