Skip to content

Commit f6bb564

Browse files
committed
feat: enable easier flavor creation
1 parent ce5074a commit f6bb564

19 files changed

+1213
-280
lines changed

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export GO111MODULE=on
3434
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
3535
TOOLS_DIR := hack/tools
3636
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
37+
TEMPLATES_DIR := $(ROOT_DIR)/templates
3738
BIN_DIR := bin
3839
RELEASE_NOTES_BIN := bin/release-notes
3940

@@ -69,6 +70,8 @@ RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac
6970
# Allow overriding the imagePullPolicy
7071
PULL_POLICY ?= Always
7172

73+
CLUSTER_TEMPLATE ?= cluster-template.yaml
74+
7275
## --------------------------------------
7376
## Help
7477
## --------------------------------------
@@ -165,6 +168,7 @@ modules: ## Runs go mod to ensure proper vendoring.
165168
generate: ## Generate code
166169
$(MAKE) generate-go
167170
$(MAKE) generate-manifests
171+
$(MAKE) generate-flavors
168172

169173
.PHONY: generate-go
170174
generate-go: $(CONTROLLER_GEN) $(MOCKGEN) $(CONVERSION_GEN) ## Runs Go related generate targets
@@ -191,6 +195,10 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
191195
output:rbac:dir=$(RBAC_ROOT) \
192196
rbac:roleName=manager-role
193197

198+
.PHONY: generate-flavors ## Generate template flavors
199+
generate-flavors: $(KUSTOMIZE)
200+
./hack/gen-flavors.sh
201+
194202
## --------------------------------------
195203
## Docker
196204
## --------------------------------------
@@ -260,11 +268,16 @@ release: clean-release ## Builds and push container images using the latest git
260268
$(MAKE) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG)
261269
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
262270
$(MAKE) release-manifests
271+
$(MAKE) release-templates
263272

264273
.PHONY: release-manifests
265274
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) ## Builds the manifests to publish with a release
266275
kustomize build config > $(RELEASE_DIR)/infrastructure-components.yaml
267276

277+
.PHONY: release-templates
278+
release-templates: $(RELEASE_DIR)
279+
cp templates/cluster-template* $(RELEASE_DIR)/
280+
268281
.PHONY: release-binary
269282
release-binary: $(RELEASE_DIR)
270283
docker run \
@@ -327,7 +340,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST)
327340
.PHONY: create-workload-cluster
328341
create-workload-cluster: $(KUSTOMIZE) $(ENVSUBST)
329342
# Create workload Cluster.
330-
$(KUSTOMIZE) build templates | $(ENVSUBST) | kubectl apply -f -
343+
$(ENVSUBST) < $(TEMPLATES_DIR)/$(CLUSTER_TEMPLATE) | kubectl apply -f -
331344

332345
# Wait for the kubeconfig to become available.
333346
timeout 300 bash -c "while ! kubectl get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"

hack/create-dev-cluster.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export AZURE_CONTROL_PLANE_MACHINE_TYPE="${CONTROL_PLANE_MACHINE_TYPE:-Standard_
4343
export AZURE_NODE_MACHINE_TYPE="${NODE_MACHINE_TYPE:-Standard_D2s_v3}"
4444
export WORKER_MACHINE_COUNT=${WORKER_MACHINE_COUNT:-2}
4545
export KUBERNETES_VERSION="${KUBERNETES_VERSION:-v1.17.4}"
46+
export TEMPLATE_PATH="${TEMPLATE_PATH:-cluster-template.yaml}"
4647

4748
# Generate SSH key.
4849
SSH_KEY_FILE=${SSH_KEY_FILE:-""}

hack/gen-flavors.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2014 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
#set -o verbose
21+
22+
root=$(dirname "${BASH_SOURCE[0]}")/..
23+
kustomize="${root}/hack/tools/bin/kustomize"
24+
flavors_dir="${root}/templates/flavors/"
25+
test_dir="${root}/templates/test/"
26+
27+
rm "${root}/templates/cluster-template"*
28+
find "${flavors_dir}"* -maxdepth 0 -type d -maxdepth 0 -print0 | xargs -0 -I {} basename {} | grep -v base | xargs -I {} sh -c "${kustomize} build ${flavors_dir}{} > ${root}/templates/cluster-template-{}.yaml"
29+
# move the default template to the default file expected by clusterctl
30+
mv "${root}/templates/cluster-template-default.yaml" "${root}/templates/cluster-template.yaml"
31+
32+
rm -f "${test_dir}cluster-template"*
33+
find "${test_dir}"* -maxdepth 0 -type d -maxdepth 0 -print0 | xargs -0 -I {} basename {} | xargs -I {} sh -c "${kustomize} build ${test_dir}{} > ${test_dir}cluster-template-{}.yaml"

scripts/ci-conformance.sh

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,6 @@ random-string() {
4040
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
4141
}
4242

43-
# generate manifests needed for creating the Azure cluster to run the tests
44-
add_kustomize_patch() {
45-
if ! grep -i -wq "patchesStrategicMerge" "templates/kustomization.yaml"; then
46-
echo "patchesStrategicMerge:" >> "templates/kustomization.yaml"
47-
fi
48-
if ! grep -i -wq "conformance-tags" "templates/kustomization.yaml"; then
49-
echo "- conformance-tags.yaml" >> "templates/kustomization.yaml"
50-
fi
51-
# Enable the bits to inject a script that can pull newer versions of kubernetes
52-
if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then
53-
if ! grep -i -wq "ci-version" "templates/kustomization.yaml"; then
54-
echo "- ci-version.yaml" >> "templates/kustomization.yaml"
55-
fi
56-
fi
57-
}
58-
5943
# build Kubernetes E2E binaries
6044
build_k8s() {
6145
# possibly enable bazel build caching before building kubernetes
@@ -85,6 +69,13 @@ build_k8s() {
8569
}
8670

8771
create_cluster() {
72+
# export cluster template which contains the manifests needed for creating the Azure cluster to run the tests
73+
if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then
74+
export CLUSTER_TEMPLATE="test/cluster-template-conformance-ci-version"
75+
else
76+
export CLUSTER_TEMPLATE="test/cluster-template-conformance"
77+
fi
78+
8879
export CLUSTER_NAME="capz-conformance-$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 6 ; echo '')"
8980
# Conformance test suite needs a cluster with at least 2 nodes
9081
export CONTROL_PLANE_MACHINE_COUNT=${CONTROL_PLANE_MACHINE_COUNT:-3}
@@ -163,7 +154,6 @@ mkdir -p "${ARTIFACTS}/logs"
163154

164155
# create cluster
165156
if [[ -z "${SKIP_CREATE_CLUSTER:-}" ]]; then
166-
add_kustomize_patch
167157
create_cluster
168158
fi
169159

0 commit comments

Comments
 (0)