Skip to content

Commit b06af49

Browse files
authored
Merge pull request #2209 from jackfrancis/e2e-external-cloud-provider-helm
e2e: use helm to install out-of-tree cloud-provider-azure
2 parents bd0b3d0 + f8c166d commit b06af49

18 files changed

+611
-1059
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ kind.kubeconfig
2929
minikube.kubeconfig
3030
kubeconfig
3131
!kubeconfig/
32+
*.kubeconfig
3233

3334
# ssh keys
3435
.ssh*

Makefile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ KUBECTL_VER := v1.22.4
108108
KUBECTL_BIN := kubectl
109109
KUBECTL := $(TOOLS_BIN_DIR)/$(KUBECTL_BIN)-$(KUBECTL_VER)
110110

111+
HELM_VER := v3.8.1
112+
HELM_BIN := helm
113+
HELM := $(TOOLS_BIN_DIR)/$(HELM_BIN)-$(HELM_VER)
114+
111115
YQ_VER := v4.14.2
112116
YQ_BIN := yq
113117
YQ := $(TOOLS_BIN_DIR)/$(YQ_BIN)-$(YQ_VER)
@@ -186,6 +190,7 @@ clean-bin: ## Remove all generated binaries.
186190
clean-temporary: ## Remove all temporary files and folders.
187191
rm -f minikube.kubeconfig
188192
rm -f kubeconfig
193+
rm -f *.kubeconfig
189194

190195
.PHONY: clean-release
191196
clean-release: ## Remove the release folder.
@@ -236,6 +241,9 @@ verify-tiltfile: ## Verify Tiltfile format.
236241

237242
##@ Development:
238243

244+
.PHONY: install-tools # populate hack/tools/bin
245+
install-tools: $(ENVSUBST) $(KUSTOMIZE) $(KUBECTL) $(HELM) $(GINKGO)
246+
239247
.PHONY: create-management-cluster
240248
create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) ## Create a management cluster.
241249
# Create kind management cluster.
@@ -545,7 +553,7 @@ release: clean-release ## Builds and push container images using the latest git
545553

546554
.PHONY: release-manifests
547555
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) ## Builds the manifests to publish with a release.
548-
kustomize build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
556+
$(KUSTOMIZE) build config/default > $(RELEASE_DIR)/infrastructure-components.yaml
549557

550558
.PHONY: release-templates
551559
release-templates: $(RELEASE_DIR)
@@ -616,7 +624,7 @@ test-cover: envs-test $(KUBECTL) $(KUBE_APISERVER) $(ETCD) ## Run tests with cod
616624
go tool cover -html=coverage.out -o coverage.html
617625

618626
.PHONY: test-e2e-run
619-
test-e2e-run: generate-e2e-templates $(ENVSUBST) $(KUSTOMIZE) $(KUBECTL) $(GINKGO) ## Run e2e tests.
627+
test-e2e-run: generate-e2e-templates install-tools ## Run e2e tests.
620628
$(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST) && \
621629
$(GINKGO) -v -trace -tags=e2e -focus="$(GINKGO_FOCUS)" -skip="$(GINKGO_SKIP)" -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) $(GINKGO_ARGS) ./test/e2e -- \
622630
-e2e.artifacts-folder="$(ARTIFACTS)" \
@@ -668,7 +676,7 @@ kind-create: $(KUBECTL) ## Create capz kind cluster if needed.
668676
./scripts/kind-with-registry.sh
669677

670678
.PHONY: tilt-up
671-
tilt-up: $(ENVSUBST) $(KUSTOMIZE) $(KUBECTL) kind-create ## Start tilt and build kind cluster if needed.
679+
tilt-up: install-tools kind-create ## Start tilt and build kind cluster if needed.
672680
EXP_CLUSTER_RESOURCE_SET=true EXP_AKS=true EXP_MACHINE_POOL=true tilt up
673681

674682
.PHONY: delete-cluster
@@ -698,6 +706,7 @@ release-notes: $(RELEASE_NOTES) ## Build a local copy of release notes.
698706
goapi-diff: $(GO_APIDIFF) ## Build a local copy of go api-diff.
699707
ginkgo: $(GINKGO) ## Build a local copy of ginkgo.
700708
kubectl: $(KUBECTL) ## Build a local copy of kubectl.
709+
helm: $(HELM) ## Build a local copy of helm.
701710
yq: $(YQ) ## Build a local copy of yq.
702711

703712
$(CONVERSION_VERIFIER): go.mod
@@ -740,12 +749,24 @@ $(KUBECTL): ## Build kubectl from tools folder.
740749
ln -sf $(KUBECTL) $(TOOLS_BIN_DIR)/$(KUBECTL_BIN)
741750
chmod +x $(KUBECTL) $(TOOLS_BIN_DIR)/$(KUBECTL_BIN)
742751

752+
$(HELM): ## Put helm into tools folder.
753+
mkdir -p $(TOOLS_BIN_DIR)
754+
rm -f "$(TOOLS_BIN_DIR)/$(HELM_BIN)*"
755+
curl -fsSL -o $(TOOLS_BIN_DIR)/get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
756+
chmod 700 $(TOOLS_BIN_DIR)/get_helm.sh
757+
USE_SUDO=false HELM_INSTALL_DIR=$(TOOLS_BIN_DIR) DESIRED_VERSION=$(HELM_VER) BINARY_NAME=$(HELM_BIN)-$(HELM_VER) $(TOOLS_BIN_DIR)/get_helm.sh
758+
ln -sf $(HELM) $(TOOLS_BIN_DIR)/$(HELM_BIN)
759+
rm -f $(TOOLS_BIN_DIR)/get_helm.sh
760+
743761
.PHONY: $(ENVSUBST_BIN)
744762
$(ENVSUBST_BIN): $(ENVSUBST)
745763

746764
.PHONY: $(KUBECTL_BIN)
747765
$(KUBECTL_BIN): $(KUBECTL)
748766

767+
.PHONY: $(HELM_BIN)
768+
$(HELM_BIN): $(HELM)
769+
749770
.PHONY: $(GO_APIDIFF_BIN)
750771
$(GO_APIDIFF_BIN): $(GO_APIDIFF)
751772

Tiltfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
envsubst_cmd = "./hack/tools/bin/envsubst"
44
kubectl_cmd = "./hack/tools/bin/kubectl"
5+
helm_cmd = "./hack/tools/bin/helm"
56
tools_bin = "./hack/tools/bin"
67

78
#Add tools to path
@@ -331,9 +332,13 @@ def deploy_worker_templates(template, substitutions):
331332
yaml = yaml.replace("${" + substitution + "}", value)
332333

333334
yaml = yaml.replace('"', '\\"') # add escape character to double quotes in yaml
335+
flavor_name = os.path.basename(flavor)
336+
flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM'); CLUSTER_NAME=" + flavor.replace("windows", "win") + "-$RANDOM; make generate-flavors; echo \"" + yaml + "\" > ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f - && echo \"Cluster \'$CLUSTER_NAME\' created, don't forget to delete\""
337+
if "external-cloud-provider" in flavor_name:
338+
flavor_cmd += "; until " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig > /dev/null 2>&1; do sleep 5; done; " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig -o jsonpath={.data.value} | base64 --decode > ./${CLUSTER_NAME}.kubeconfig; chmod 600 ./${CLUSTER_NAME}.kubeconfig; until " + kubectl_cmd + " --kubeconfig=./${CLUSTER_NAME}.kubeconfig get nodes > /dev/null 2>&1; do sleep 5; done; " + helm_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME}"
334339
local_resource(
335-
name = os.path.basename(flavor),
336-
cmd = "RANDOM=$(bash -c 'echo $RANDOM'); CLUSTER_NAME=" + flavor.replace("windows", "win") + "-$RANDOM; make generate-flavors; echo \"" + yaml + "\" > ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f - && echo \"Cluster \'$CLUSTER_NAME\' created, don't forget to delete\"",
340+
name = flavor_name,
341+
cmd = flavor_cmd,
337342
auto_init = False,
338343
trigger_mode = TRIGGER_MODE_MANUAL,
339344
labels = ["flavors"],

docs/book/src/developers/kubernetes-developers.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,56 @@ export CLUSTER_TEMPLATE="test/dev/cluster-template-custom-builds.yaml"
3535

3636
## Testing the out-of-tree cloud provider
3737

38-
To test changes made to the [Azure cloud provider](https://github.com/kubernetes-sigs/cloud-provider-azure), first build and push images for cloud-controller-manager and/or cloud-node-manager from the root of the cloud-provider-azure repo.
38+
To test changes made to the [Azure cloud provider](https://github.com/kubernetes-sigs/cloud-provider-azure), first build and push images for cloud-controller-manager and/or cloud-node-manager from the branch of the cloud-provider-azure repo that the desired changes are in. Based on the repository, image name, and image tag you produce from your custom image build and push, set the appropriate environment variables below:
39+
40+
```bash
41+
$ export IMAGE_REGISTRY=docker.io/myusername
42+
$ export CCM_IMAGE_NAME=azure-cloud-controller-manager
43+
$ export CNM_IMAGE_NAME=azure-node-controller-manager
44+
$ export IMAGE_TAG=canary
45+
```
3946

4047
Then, use the `external-cloud-provider` flavor to create a cluster:
4148

4249
```bash
43-
AZURE_CLOUD_CONTROLLER_MANAGER_IMG=myrepo/my-ccm:v0.0.1 \
44-
AZURE_CLOUD_NODE_MANAGER_IMG=myrepo/my-cnm:v0.0.1 \
45-
CLUSTER_TEMPLATE=cluster-template-external-cloud-provider.yaml \
50+
$ export CLUSTER_NAME=my-cluster
51+
$ CLUSTER_TEMPLATE=cluster-template-external-cloud-provider.yaml \
4652
make create-workload-cluster
4753
```
54+
55+
Once your cluster deploys, you should receive the kubeconfig to the workload cluster. Set your `KUBECONFIG` environment variable to point to the kubeconfig file, then use the official cloud-provider-azure Helm chart to deploy the cloud-provider-azure components using your custom built images:
56+
57+
```bash
58+
$ helm install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME} \
59+
--set cloudControllerManager.imageRepository="${IMAGE_REGISTRY}" \
60+
--set cloudNodeManager.imageRepository="${IMAGE_REGISTRY}" \
61+
--set cloudControllerManager.imageName="${CCM_IMAGE_NAME}" \
62+
--set cloudNodeManager.imageName="${CNM_IMAGE_NAME}" \
63+
--set cloudControllerManager.imageTag="${IMAGE_TAG}" \
64+
--set cloudNodeManager.imageTag="${IMAGE_TAG}"
65+
```
66+
67+
The helm command above assumes that you want to test custom images of both cloud-controller-manager and cloud-node-manager. If you only wish to test one component, you may omit the other one referenced in the example above to produce the desired `helm install` command (for example, if you wish to only test a custom cloud-controller-manager image, omit the three `--set cloudNodeManager...` arguments above).
68+
69+
Once you have installed the components via Helm, you should see the relevant pods running in your test cluster under the `kube-system` namespace. To iteratively develop on this test cluster, you may manually edit the `cloud-controller-manager` Deployment resource, and/or the `cloud-node-manager` Daemonset resource delivered via `helm install`. Or you may issue follow-up `helm` commands with each test iteration. For example:
70+
71+
```bash
72+
$ export IMAGE_TAG=canaryv2
73+
$ helm upgrade --install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME} \
74+
--set cloudControllerManager.imageRepository="${IMAGE_REGISTRY}" \
75+
--set cloudNodeManager.imageRepository="${IMAGE_REGISTRY}" \
76+
--set cloudControllerManager.imageName="${CCM_IMAGE_NAME}" \
77+
--set cloudNodeManager.imageName="${CNM_IMAGE_NAME}" \
78+
--set cloudControllerManager.imageTag="${IMAGE_TAG}" \
79+
--set cloudNodeManager.imageTag="${IMAGE_TAG}"
80+
$ export IMAGE_TAG=canaryv3
81+
$ helm upgrade --install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME} \
82+
--set cloudControllerManager.imageRepository="${IMAGE_REGISTRY}" \
83+
--set cloudNodeManager.imageRepository="${IMAGE_REGISTRY}" \
84+
--set cloudControllerManager.imageName="${CCM_IMAGE_NAME}" \
85+
--set cloudNodeManager.imageName="${CNM_IMAGE_NAME}" \
86+
--set cloudControllerManager.imageTag="${IMAGE_TAG}" \
87+
--set cloudNodeManager.imageTag="${IMAGE_TAG}"
88+
```
89+
90+
Each successive `helm upgrade --install` command will release a new version of the chart, which will have the effect of replacing the Deployment and/or Daemonset image configurations (and thus replace the pods running in the cluster) with the new image version built and pushed for each test iteration.

docs/book/src/topics/cloud-provider-config.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ All cloud provider config values can be customized by creating the `${RESOURCE}-
7171

7272
To deploy a cluster using [external cloud provider](https://github.com/kubernetes-sigs/cloud-provider-azure), create a cluster configuration with the [external cloud provider template](https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-azure/main/templates/cluster-template-external-cloud-provider.yaml).
7373

74-
After deploying the cluster, you should eventually see a set of pods like the following in a `Running` state:
74+
After the cluster has provisioned, install the `cloud-provider-azure` components using the official helm chart:
75+
76+
```bash
77+
helm install --repo https://raw.githubusercontent.com/kubernetes-sigs/cloud-provider-azure/master/helm/repo cloud-provider-azure --generate-name --set infra.clusterName=${CLUSTER_NAME}
78+
```
79+
80+
The Helm chart will pick the right version of `cloud-controller-manager` and `cloud-node-manager` to work with the version of Kubernetes your cluster is running.
81+
82+
After running `helm install`, you should eventually see a set of pods like these in a `Running` state:
7583

7684
```bash
7785
kube-system cloud-controller-manager 1/1 Running 0 41s
@@ -81,6 +89,10 @@ kube-system cloud-node-manager-mfsdg
8189
kube-system cloud-node-manager-qrz74 1/1 Running 0 24s
8290
```
8391

92+
For more information see the official [`cloud-provider-azure` helm chart documentation](https://github.com/kubernetes-sigs/cloud-provider-azure/tree/master/helm/cloud-provider-azure).
93+
94+
If you're not familiar with using Helm to manage Kubernetes applications as packages, there's lots of good [Helm documentation on the official website](https://helm.sh/docs/).
95+
8496
## Storage Drivers
8597

8698
### Azure File CSI Driver

0 commit comments

Comments
 (0)