From 9f539709e8129e8131fee6bec23e62d76127a1e3 Mon Sep 17 00:00:00 2001 From: Aleksei Sizov Date: Mon, 2 Sep 2024 13:01:01 -0500 Subject: [PATCH] Add azure related make targets; minor makefile changes --- Makefile | 39 +++++++++++++------ .../{deployment.yaml => aws-deployment.yaml} | 3 +- config/dev/azure-credentials.yaml | 25 ++++++++++++ config/dev/azure-deployment.yaml | 22 +++++++++++ docs/dev.md | 39 +++++++++++++++---- 5 files changed, 106 insertions(+), 22 deletions(-) rename config/dev/{deployment.yaml => aws-deployment.yaml} (81%) create mode 100644 config/dev/azure-credentials.yaml create mode 100644 config/dev/azure-deployment.yaml diff --git a/Makefile b/Makefile index fd18a36ca..e00e49358 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ docker-push: ## Push docker image with the manager. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx docker-buildx: ## Build and push docker image for the manager for cross-platform support - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - $(CONTAINER_TOOL) buildx create --name project-v3-builder $(CONTAINER_TOOL) buildx use project-v3-builder @@ -191,6 +191,7 @@ KIND_NETWORK ?= kind REGISTRY_NAME ?= hmc-local-registry REGISTRY_PORT ?= 5001 REGISTRY_REPO ?= oci://127.0.0.1:$(REGISTRY_PORT)/charts +DEV_PROVIDER ?= aws AWS_CREDENTIALS=${AWS_B64ENCODED_CREDENTIALS} @@ -223,7 +224,7 @@ registry-deploy: .PHONY: registry-undeploy registry-undeploy: @if [ "$$($(CONTAINER_TOOL) ps -aq -f name=$(REGISTRY_NAME))" ]; then \ - echo "Removing local registry container $(REGISTRY_NAME)"; \ + echo "Removing local registry container $(REGISTRY_NAME)"; \ $(CONTAINER_TOOL) rm -f "$(REGISTRY_NAME)"; \ fi @@ -233,7 +234,7 @@ hmc-deploy: helm .PHONY: dev-deploy dev-deploy: ## Deploy HMC helm chart to the K8s cluster specified in ~/.kube/config. - make hmc-deploy HMC_VALUES=config/dev/hmc_values.yaml + $(MAKE) hmc-deploy HMC_VALUES=config/dev/hmc_values.yaml $(KUBECTL) rollout restart -n $(NAMESPACE) deployment/hmc-controller-manager .PHONY: dev-undeploy @@ -264,23 +265,30 @@ dev-push: docker-build helm-push dev-templates: templates-generate $(KUBECTL) -n $(NAMESPACE) apply -f templates/hmc-templates/files/templates -.PHONY: dev-aws -dev-aws: yq +.PHONY: dev-aws-creds +dev-aws-creds: yq @$(YQ) e ".stringData.AWS_B64ENCODED_CREDENTIALS = \"${AWS_CREDENTIALS}\"" config/dev/awscredentials.yaml | $(KUBECTL) -n $(NAMESPACE) apply -f - +.PHONY: dev-azure-creds +dev-azure-creds: envsubst + @NAMESPACE=$(NAMESPACE) $(ENVSUBST) -no-unset -i config/dev/azure-credentials.yaml | $(KUBECTL) apply -f - + .PHONY: dev-apply -dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-aws +dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates .PHONY: dev-destroy dev-destroy: kind-undeploy registry-undeploy -.PHONY: dev-aws-apply -dev-aws-apply: - $(KUBECTL) -n $(NAMESPACE) apply -f config/dev/deployment.yaml +.PHONY: dev-creds-apply +dev-creds-apply: dev-$(DEV_PROVIDER)-creds + +.PHONY: dev-provider-apply +dev-provider-apply: envsubst + @NAMESPACE=$(NAMESPACE) $(ENVSUBST) -no-unset -i config/dev/$(DEV_PROVIDER)-deployment.yaml | $(KUBECTL) apply -f - -.PHONY: dev-aws-destroy -dev-aws-destroy: - $(KUBECTL) -n $(NAMESPACE) delete -f config/dev/deployment.yaml +.PHONY: dev-provider-delete +dev-provider-delete: envsubst + @NAMESPACE=$(NAMESPACE) $(ENVSUBST) -no-unset -i config/dev/$(DEV_PROVIDER)-deployment.yaml | $(KUBECTL) delete -f - .PHONY: cli-install cli-install: clusterawsadm clusterctl @@ -313,6 +321,7 @@ YQ ?= $(LOCALBIN)/yq-$(YQ_VERSION) CLUSTERAWSADM ?= $(LOCALBIN)/clusterawsadm CLUSTERCTL ?= $(LOCALBIN)/clusterctl ADDLICENSE ?= $(LOCALBIN)/addlicense-$(ADDLICENSE_VERSION) +ENVSUBST ?= $(LOCALBIN)/envsubst-$(ENVSUBST_VERSION) ## Tool Versions CONTROLLER_TOOLS_VERSION ?= v0.14.0 @@ -324,6 +333,7 @@ YQ_VERSION ?= v4.44.2 CLUSTERAWSADM_VERSION ?= v2.5.2 CLUSTERCTL_VERSION ?= v1.7.3 ADDLICENSE_VERSION ?= v1.1.1 +ENVSUBST_VERSION ?= v1.4.2 .PHONY: controller-gen controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. @@ -388,6 +398,11 @@ addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary. $(ADDLICENSE): | $(LOCALBIN) $(call go-install-tool,$(ADDLICENSE),github.com/google/addlicense,${ADDLICENSE_VERSION}) +.PHONY: envsubst +envsubst: $(ENVSUBST) +$(ENVSUBST): | $(LOCALBIN) + $(call go-install-tool,$(ENVSUBST),github.com/a8m/envsubst/cmd/envsubst,${ENVSUBST_VERSION}) + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary (ideally with version) # $2 - package url which can be installed diff --git a/config/dev/deployment.yaml b/config/dev/aws-deployment.yaml similarity index 81% rename from config/dev/deployment.yaml rename to config/dev/aws-deployment.yaml index 58ba18e32..e40cc1d39 100644 --- a/config/dev/deployment.yaml +++ b/config/dev/aws-deployment.yaml @@ -2,6 +2,7 @@ apiVersion: hmc.mirantis.com/v1alpha1 kind: Deployment metadata: name: aws-dev + namespace: ${NAMESPACE} spec: template: aws-standalone-cp config: @@ -10,8 +11,6 @@ spec: controlPlaneNumber: 1 workersNumber: 1 controlPlane: - amiID: ami-02f3416038bdb17fb instanceType: t3.small worker: - amiID: ami-02f3416038bdb17fb instanceType: t3.small diff --git a/config/dev/azure-credentials.yaml b/config/dev/azure-credentials.yaml new file mode 100644 index 000000000..1043641d3 --- /dev/null +++ b/config/dev/azure-credentials.yaml @@ -0,0 +1,25 @@ +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: AzureClusterIdentity +metadata: + labels: + clusterctl.cluster.x-k8s.io/move-hierarchy: "true" + name: azure-cluster-identity + namespace: ${NAMESPACE} +spec: + allowedNamespaces: {} + clientID: "${AZURE_CLIENT_ID}" + clientSecret: + name: azure-cluster-identity-secret + namespace: ${NAMESPACE} + tenantID: "${AZURE_TENANT_ID}" + type: ServicePrincipal +--- +apiVersion: v1 +kind: Secret +metadata: + name: azure-cluster-identity-secret + namespace: ${NAMESPACE} +stringData: + clientSecret: "${AZURE_CLIENT_SECRET}" +type: Opaque diff --git a/config/dev/azure-deployment.yaml b/config/dev/azure-deployment.yaml new file mode 100644 index 000000000..ff6d8059b --- /dev/null +++ b/config/dev/azure-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: hmc.mirantis.com/v1alpha1 +kind: Deployment +metadata: + name: azure-dev + namespace: ${NAMESPACE} +spec: + template: azure-standalone-cp + config: + controlPlaneNumber: 1 + workersNumber: 1 + location: "westus" + subscriptionID: "${AZURE_SUBSCRIPTION_ID}" + controlPlane: + vmSize: Standard_A4_v2 + worker: + vmSize: Standard_A4_v2 + clusterIdentity: + name: azure-cluster-identity + namespace: ${NAMESPACE} + tenantID: "${AZURE_TENANT_ID}" + clientID: "${AZURE_CLIENT_ID}" + clientSecret: "${AZURE_CLIENT_SECRET}" diff --git a/docs/dev.md b/docs/dev.md index 279de0270..4112b0905 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -23,22 +23,45 @@ make cli-install Follow the instruction to configure AWS Provider: [AWS Provider Setup](aws/main.md#prepare-the-aws-infra-provider) +### Azure Provider Setup + +Follow the instruction on how to configure [Azure Provider](azure/main.md). + +Additionally to deploy dev cluster on Azure the following env variables should +be set before running deployment: + +- `AZURE_SUBSCRIPTION_ID` - Subscription ID +- `AZURE_TENANT_ID` - Service principal tenant ID +- `AZURE_CLIENT_ID` - Service principal App ID +- `AZURE_CLIENT_SECRET` - Service principal password + +More detailed description of these parameters can be found +[here](azure/cluster-parameters.md). + ## Deploy HMC -1. Configure your cluster parameters in `config/dev/deployment.yaml`: +Default provider which will be used to deploy cluster is AWS, if you want to use +another provider change `DEV_PROVIDER` variable with the name of provider before +running make (e.g. `export DEV_PROVIDER=azure`). + +1. Configure your cluster parameters in provider specific file + (for example `config/dev/aws-deployment.yaml` in case of AWS): * Configure the `name` of the deployment - * Change `amiID` and `instanceType` for control plane and worker machines + * Change instance type or size for control plane and worker machines * Specify the number of control plane and worker machines, etc -2. Run `make dev-apply` to deploy and configure management cluster +2. Run `make dev-apply` to deploy and configure management cluster. + +3. Wait a couple of minutes for management components to be up and running. -3. Wait a couple of minutes for management components to be up and running +4. Apply credentials for your provider by executing `make dev-creds-apply`. -4. Run `make dev-aws-apply` to deploy managed cluster on AWS with default configuration +5. Run `make dev-provider-apply` to deploy managed cluster on provider of your + choice with default configuration. -5. Wait for infrastructure to be provisioned and the cluster to be deployed. You may watch the process with the - `./bin/clusterctl describe` command. Example: +6. Wait for infrastructure to be provisioned and the cluster to be deployed. You + may watch the process with the `./bin/clusterctl describe` command. Example: ``` export KUBECONFIG=~/.kube/config @@ -54,7 +77,7 @@ export KUBECONFIG=~/.kube/config > ``` > This may help identify any potential issues with deployment of the AWS infrastructure. -6. Retrieve the `kubeconfig` of your managed cluster: +7. Retrieve the `kubeconfig` of your managed cluster: ``` kubectl --kubeconfig ~/.kube/config get secret -n hmc-system -kubeconfig -o=jsonpath={.data.value} | base64 -d > kubeconfig