fix(infra-k8s): tunnel kubectl through az aks command invoke on Azure - #56
Open
daanpersoons wants to merge 1 commit into
Open
daanpersoons wants to merge 1 commit into
daanpersoons wants to merge 1 commit into
Conversation
Azure clusters are private, so their API server only resolves inside the
VNet. Since the vendor-agnostic infra-k8s actions call kubectl directly
from the runner, every Azure rollout fails with:
failed to download openapi: dial tcp: lookup
<cluster>.privatelink.westeurope.azmk8s.io: no such host
Restore the tunnelling that lived on the unmerged feature/azure-deployments
branch: render kustomize locally, then run kubectl on the cluster through
`az aks command invoke`. Other vendors keep calling kubectl directly.
Two fixes on top of the original implementation:
- `az aks command invoke` exits 0 even when the remote command failed (it
only prints `exitcode=N`), so a failing apply reported a green build.
Parse the JSON result and fail on a non-zero exitCode or a
provisioningState other than Succeeded.
- The image-based rollout piped kubectl into jq, which the run-command pod
cannot do. Capture the remote output and keep jq on the runner.
Inputs are now passed via env instead of interpolating ${{ }} into the
script body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every Azure k8s rollout has failed since the
infra-*@v1migration:The clusters are private — the API server only resolves inside the VNet, so a hosted
runner cannot reach it. The vendor-agnostic actions call
kubectldirectly from the runner.This worked before because the old Azure-specific workflow tunnelled every
kubectlthrough
az aks command invoke. That code only ever existed onfeature/azure-deployments,which was never merged into
main,v1orv2— it was a spike branch carrying aTEMP: point to branch workflowscommit, and consumers were pinned straight at it.When those consumers moved to
@v1, the tunnelling silently disappeared.Change
infra/k8s/applyandinfra/k8s/rolloutrender kustomize locally, then runkubectlon the cluster via
az aks command invokewhenvendor: azure. Other vendors areunchanged — DigitalOcean and Scaleway still call
kubectldirectly.Two bugs fixed relative to the original implementation:
az aks command invokereturns 0 even when the remotecommand failed — it only prints
exitcode=N(
azure-cli/command_modules/acs/custom.py:2795-2801). A failingkubectl applywouldhave reported a green build. The JSON result is now parsed and the step fails on a
non-zero
exitCodeor aprovisioningStateother thanSucceeded.kubectlintojq, which the run-command pod cannotdo. The remote output is captured and
jqstays on the runner.Inputs moved from
${{ }}interpolation intoenv:, so values can't be substitutedinto the script body.
Testing
az/kubectl: both vendor paths, all four rolloutbranches, remote-failure propagation,
provisioningState: Failed, and image matchingwith 0 and 1 hits. All pass.
bash -nclean on everyrun:body.k8s/environments/test) — green, with real changes applied (configmap ... created,deployment.apps/indaver-api configured).Requirements
The service principal needs
Microsoft.ContainerService/managedClusters/runcommand/actionand
.../commandResults/read(both in Azure Kubernetes Service Cluster User Role), andthe cluster must not have
--disable-run-command. Documented inDocs/infra-k8s-rollout.md.Note
v2has the identical gap and will need the same fix before anyone moves to it.