Skip to content

Commit f172196

Browse files
author
Naadir Jeewa
committed
flavorgen: Adds a generator for clusterctl template flavors
Signed-off-by: Naadir Jeewa <jeewan@vmware.com>
1 parent 93ffc39 commit f172196

33 files changed

+1149
-566
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ out/
5757

5858
# Ignore Goland files
5959
.idea/
60+
61+
.build
62+
.tiltbuild

Makefile

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SHELL := /usr/bin/env bash
2020

2121
.DEFAULT_GOAL := help
2222

23+
VERSION ?= $(shell cat clusterctl-settings.json | jq .config.nextVersion -r)
24+
2325
# Use GOPROXY environment variable if set
2426
GOPROXY := $(shell go env GOPROXY)
2527
ifeq (,$(strip $(GOPROXY)))
@@ -31,8 +33,9 @@ export GOPROXY
3133
export GO111MODULE := on
3234

3335
# Directories
34-
BIN_DIR := bin
35-
TOOLS_DIR := hack/tools
36+
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
37+
BIN_DIR := $(ROOT_DIR)/bin
38+
TOOLS_DIR := $(ROOT_DIR)/hack/tools
3639
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
3740

3841
# Binaries
@@ -51,6 +54,35 @@ CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
5154
WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook
5255
RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
5356
GC_KIND ?= true
57+
RELEASE_DIR := out
58+
BUILD_DIR := .build
59+
OVERRIDES_DIR := $(HOME)/.cluster-api/overrides/infrastructure-vsphere/$(VERSION)
60+
61+
# Architecture variables
62+
ARCH ?= amd64
63+
ALL_ARCH = amd64 arm arm64 ppc64le s390x
64+
65+
# Common docker variables
66+
IMAGE_NAME ?= manager
67+
PULL_POLICY ?= Always
68+
# Hosts running SELinux need :z added to volume mounts
69+
SELINUX_ENABLED := $(shell cat /sys/fs/selinux/enforce 2> /dev/null || echo 0)
70+
71+
ifeq ($(SELINUX_ENABLED),1)
72+
DOCKER_VOL_OPTS?=:z
73+
endif
74+
75+
76+
# Release docker variables
77+
RELEASE_REGISTRY := gcr.io/cluster-api-provider-vsphere/release
78+
RELEASE_CONTROLLER_IMG := $(RELEASE_REGISTRY)/$(IMAGE_NAME)
79+
80+
# Development Docker variables
81+
DEV_REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
82+
DEV_CONTROLLER_IMG ?= $(DEV_REGISTRY)/vsphere-$(IMAGE_NAME)
83+
DEV_TAG ?= dev
84+
DEV_MANIFEST_IMG := $(DEV_CONTROLLER_IMG)-$(ARCH)
85+
5486

5587
## --------------------------------------
5688
## Help
@@ -74,7 +106,7 @@ e2e-image: ## Build the e2e manager image
74106
.PHONY: e2e
75107
e2e: e2e-image
76108
e2e: ## Run e2e tests
77-
time ginkgo -v ./test/e2e -- --e2e.config="$(abspath test/e2e/e2e.conf)" --e2e.teardownKind=$(GC_KIND)
109+
time ginkgo -v ./test/e2e -- --e2e.config="$(abspath test/e2e/e2e.conf)" --e2e.teardownKind=$(GC_KIND) $(E2E_ARGS)
78110

79111
## --------------------------------------
80112
## Binaries
@@ -122,7 +154,7 @@ lint-go-full: lint-go ## Run slower linters to detect possible issues
122154

123155
.PHONY: lint-markdown
124156
lint-markdown: ## Lint the project's markdown
125-
docker run --rm -v "$$(pwd)":/build gcr.io/cluster-api-provider-vsphere/extra/mdlint:0.17.0 -- /md/lint -i vendor -i contrib/haproxy/openapi .
157+
docker run --rm -v "$$(pwd)":/build$(DOCKER_VOL_OPTS) gcr.io/cluster-api-provider-vsphere/extra/mdlint:0.17.0 -- /md/lint -i vendor -i contrib/haproxy/openapi .
126158

127159
.PHONY: lint-shell
128160
lint-shell: ## Lint the project's shell scripts
@@ -179,24 +211,79 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
179211
## Release
180212
## --------------------------------------
181213

182-
.PHONY: release-manifests
183-
release-manifests: ## Builds the manifests to publish with a release
214+
$(RELEASE_DIR):
215+
@mkdir -p $(RELEASE_DIR)
216+
217+
218+
$(BUILD_DIR):
219+
@mkdir -p $(BUILD_DIR)
220+
221+
$(OVERRIDES_DIR):
222+
@mkdir -p $(OVERRIDES_DIR)
223+
224+
.PHONY: dev-version-check
225+
dev-version-check:
184226
ifndef VERSION
185-
$(error VERSION is undefined)
227+
$(error VERSION must be set)
186228
endif
187-
@mkdir -p out
188-
cd config/manager/; ../../"$(KUSTOMIZE)" edit set image gcr.io/cluster-api-provider-vsphere/release/manager:"$(VERSION)"
189-
"$(KUSTOMIZE)" build config/default > out/infrastructure-components.yaml
229+
230+
.PHONY: release-version-check
231+
release-version-check:
232+
ifeq ($(VERSION), 0.0.0)
233+
$(error VERSION must be >0.0.0 for release)
234+
endif
235+
236+
.PHONY: release-manifests
237+
release-manifests:
238+
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(RELEASE_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)
239+
240+
.PHONY: release-overrides
241+
release-overrides:
242+
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(OVERRIDES_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)
243+
244+
.PHONY: dev-manifests
245+
dev-manifests:
246+
$(MAKE) manifests STAGE=dev MANIFEST_DIR=$(OVERRIDES_DIR) PULL_POLICY=Always IMAGE=$(DEV_CONTROLLER_IMG):$(DEV_TAG)
247+
248+
.PHONY: manifests
249+
manifests: $(STAGE)-version-check $(STAGE)-flavors $(MANIFEST_DIR) $(BUILD_DIR) $(KUSTOMIZE)
250+
rm -rf $(BUILD_DIR)/config
251+
cp -R config $(BUILD_DIR)
252+
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(BUILD_DIR)/config/manager/manager_pull_policy.yaml
253+
sed -i'' -e 's@image: .*@image: '"$(IMAGE)"'@' $(BUILD_DIR)/config/manager/manager_image_patch.yaml
254+
"$(KUSTOMIZE)" build $(BUILD_DIR)/config > $(MANIFEST_DIR)/infrastructure-components.yaml
255+
190256
## --------------------------------------
191257
## Cleanup / Verification
192258
## --------------------------------------
193259

260+
.PHONY: flavors
261+
flavors: $(FLAVOR_DIR)
262+
go run ./packaging/flavorgen -f multi-host > $(FLAVOR_DIR)/cluster-template.yaml
263+
264+
.PHONY: release-flavors ## Create release flavor manifests
265+
release-flavors: release-version-check
266+
$(MAKE) flavors FLAVOR_DIR=$(RELEASE_DIR)
267+
268+
.PHONY: dev-flavors ## Create release flavor manifests
269+
dev-flavors:
270+
$(MAKE) flavors FLAVOR_DIR=$(OVERRIDES_DIR)
271+
272+
.PHONY: overrides ## Generates flavors as clusterctl overrides
273+
overrides: version-check $(OVERRIDES_DIR)
274+
go run ./packaging/flavorgen -f multi-host > $(OVERRIDES_DIR)/cluster-template.yaml
275+
194276
.PHONY: clean
195277
clean: ## Run all the clean targets
196278
$(MAKE) clean-bin
197279
$(MAKE) clean-temporary
198280
$(MAKE) clean-release
199281
$(MAKE) clean-examples
282+
$(MAKE) clean-build
283+
284+
.PHONY: clean-build
285+
clean-build:
286+
rm -rf $(BUILD_DIR)
200287

201288
.PHONY: clean-bin
202289
clean-bin: ## Remove all generated binaries
@@ -238,3 +325,15 @@ verify-crds: ## Verifies the committed CRDs are up-to-date
238325
check: ## Verify and lint the project
239326
$(MAKE) verify
240327
$(MAKE) lint
328+
329+
## --------------------------------------
330+
## Docker
331+
## --------------------------------------
332+
333+
.PHONY: docker-build
334+
docker-build: ## Build the docker image for controller-manager
335+
docker build --pull --build-arg ARCH=$(ARCH) . -t $(DEV_CONTROLLER_IMG):$(DEV_TAG)
336+
337+
.PHONY: docker-push
338+
docker-push: ## Push the docker image
339+
docker push $(DEV_CONTROLLER_IMG):$(DEV_TAG)

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ Check out the [getting started guide](./docs/getting_started.md) for launching a
3131

3232
This provider's versions are compatible with the following versions of Cluster API:
3333

34-
||Cluster API v1alpha1 (v0.1)|Cluster API v1alpha2 (v0.2)|
35-
|---|:---:|:---:|
36-
| CAPV v1alpha1 (v0.3)|||
37-
| CAPV v1alpha1 (v0.4)|||
38-
| CAPV v1alpha2 (v0.5, master)|||
39-
40-
||Kubernetes 1.13|Kubernetes 1.14|Kubernetes 1.15|
41-
|-|:---:|:---:|:---:|
42-
| CAPV v1alpha1 (v0.3)||||
43-
| CAPV v1alpha1 (v0.4)||||
44-
| CAPV v1alpha2 (v0.5, master)||||
34+
| | Cluster API v1alpha1 (v0.1) | Cluster API v1alpha2 (v0.2) |
35+
| ---------------------------- | :-------------------------: | :-------------------------: |
36+
| CAPV v1alpha1 (v0.3) |||
37+
| CAPV v1alpha1 (v0.4) |||
38+
| CAPV v1alpha2 (v0.5, master) |||
39+
40+
| | Kubernetes 1.13 | Kubernetes 1.14 | Kubernetes 1.15 |
41+
| ---------------------------- | :-------------: | :-------------: | :-------------: |
42+
| CAPV v1alpha1 (v0.3) ||||
43+
| CAPV v1alpha1 (v0.4) ||||
44+
| CAPV v1alpha2 (v0.5, master) ||||
4545

4646
**NOTE:** As the versioning for this project is tied to the versioning of Cluster API, future modifications to this policy may be made to more closely align with other providers in the Cluster API ecosystem.
4747

4848
## Kubernetes versions with published OVAs
4949

5050
Note: These OVAs are not updated for security fixes and it is recommended to always use the latest patch version for the Kubernetes version you wish to run. For production-like environments, it is highly recommended to build and use your own custom images.
5151

52-
| Kubernetes | CentOS 7 | Ubuntu 18.04 | Photon 3 |
53-
|:-:|:-:|:-:|:-:|
54-
| v1.15.10 | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/centos-7-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/centos-7-kube-v1.15.10.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/ubuntu-1804-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/ubuntu-1804-kube-v1.15.10.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/photon-3-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/photon-3-kube-v1.15.10.ova.sha256) |
55-
| v1.16.7 | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/centos-7-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/centos-7-kube-v1.16.7.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/ubuntu-1804-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/ubuntu-1804-kube-v1.16.7.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/photon-3-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/photon-3-kube-v1.16.7.ova.sha256) |
56-
| v1.17.4 | [ova](http://storage.googleapis.com/capv-images/release/v1.17.4/centos-7-kube-v1.17.4.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.4/centos-7-kube-v1.17.4.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.17.4/ubuntu-1804-kube-v1.17.4.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.4/ubuntu-1804-kube-v1.17.4.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.17.4/photon-3-kube-v1.17.4.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.4/photon-3-1804-kube-v1.17.4.ova.sha256) |
52+
| Kubernetes | CentOS 7 | Ubuntu 18.04 | Photon 3 |
53+
| :--------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
54+
| v1.15.10 | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/centos-7-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/centos-7-kube-v1.15.10.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/ubuntu-1804-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/ubuntu-1804-kube-v1.15.10.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.15.10/photon-3-kube-v1.15.10.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.15.10/photon-3-kube-v1.15.10.ova.sha256) |
55+
| v1.16.7 | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/centos-7-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/centos-7-kube-v1.16.7.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/ubuntu-1804-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/ubuntu-1804-kube-v1.16.7.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.16.7/photon-3-kube-v1.16.7.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.16.7/photon-3-kube-v1.16.7.ova.sha256) |
56+
| v1.17.3 | [ova](http://storage.googleapis.com/capv-images/release/v1.17.3/centos-7-kube-v1.17.3.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.3/centos-7-kube-v1.17.3.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.17.3/ubuntu-1804-kube-v1.17.3.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.3/ubuntu-1804-kube-v1.17.3.ova.sha256) | [ova](http://storage.googleapis.com/capv-images/release/v1.17.3/photon-3-kube-v1.17.3.ova), [sha256](http://storage.googleapis.com/capv-images/release/v1.17.3/photon-3-1804-kube-v1.17.3.ova.sha256) |
5757

5858
A full list of the published machine images for CAPV may be obtained with the following command:
5959

config/default/credentials.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: manager-bootstrap-credentials
5+
namespace: system
6+
type: Opaque
7+
stringData:
8+
username: ${VSPHERE_USERNAME}
9+
password: ${VSPHERE_PASSWORD}

config/default/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace: capv-system
66

77
resources:
88
- namespace.yaml
9+
- credentials.yaml
910
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml
1011
#- ../webhook
1112
# [CERTMANAGER] To enable cert-manager, uncomment next line. 'WEBHOOK' components are required.

config/default/manager_credentials_patch.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ spec:
1212
- name: VSPHERE_USERNAME
1313
valueFrom:
1414
secretKeyRef:
15-
name: capv-manager-bootstrap-credentials
15+
name: manager-bootstrap-credentials
1616
key: username
1717
- name: VSPHERE_PASSWORD
1818
valueFrom:
1919
secretKeyRef:
20-
name: capv-manager-bootstrap-credentials
20+
name: manager-bootstrap-credentials
2121
key: password
2222

config/manager/kustomization.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ resources:
44
- manager.yaml
55

66
patchesStrategicMerge:
7-
- manager_auth_proxy_patch.yaml
7+
- manager_auth_proxy_patch.yaml
8+
- manager_image_patch.yaml
9+
- manager_pull_policy.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- image: gcr.io/cluster-api-provider-vsphere/release/manager:latest
11+
name: manager
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
imagePullPolicy: IfNotPresent

config/webhook/kustomization.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ vars:
3636
kind: Service
3737
version: v1
3838
name: webhook-service
39-

0 commit comments

Comments
 (0)