Skip to content

Commit

Permalink
Merge pull request Mirantis#243 from a13x5/azure-dev-make-targets
Browse files Browse the repository at this point in the history
Add azure related make targets
  • Loading branch information
Kshatrix authored Sep 3, 2024
2 parents 10a3c4f + 9f53970 commit 9fa7b3c
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 22 deletions.
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: hmc.mirantis.com/v1alpha1
kind: Deployment
metadata:
name: aws-dev
namespace: ${NAMESPACE}
spec:
template: aws-standalone-cp
config:
Expand All @@ -10,8 +11,6 @@ spec:
controlPlaneNumber: 1
workersNumber: 1
controlPlane:
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
worker:
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
25 changes: 25 additions & 0 deletions config/dev/azure-credentials.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions config/dev/azure-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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}"
39 changes: 31 additions & 8 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <deployment-name>-kubeconfig -o=jsonpath={.data.value} | base64 -d > kubeconfig
Expand Down

0 comments on commit 9fa7b3c

Please sign in to comment.