Skip to content

Commit

Permalink
Merge pull request #540 from devigned/template-flavors
Browse files Browse the repository at this point in the history
feat: enable easier flavor creation
  • Loading branch information
k8s-ci-robot authored Apr 21, 2020
2 parents 20d22ee + ac00b33 commit f960483
Show file tree
Hide file tree
Showing 19 changed files with 1,213 additions and 280 deletions.
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export GO111MODULE=on
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
TEMPLATES_DIR := $(ROOT_DIR)/templates
BIN_DIR := bin
RELEASE_NOTES_BIN := bin/release-notes

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

CLUSTER_TEMPLATE ?= cluster-template.yaml

## --------------------------------------
## Help
## --------------------------------------
Expand Down Expand Up @@ -165,6 +168,7 @@ modules: ## Runs go mod to ensure proper vendoring.
generate: ## Generate code
$(MAKE) generate-go
$(MAKE) generate-manifests
$(MAKE) generate-flavors

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

.PHONY: generate-flavors ## Generate template flavors
generate-flavors: $(KUSTOMIZE)
./hack/gen-flavors.sh

## --------------------------------------
## Docker
## --------------------------------------
Expand Down Expand Up @@ -260,11 +268,16 @@ release: clean-release ## Builds and push container images using the latest git
$(MAKE) set-manifest-image MANIFEST_IMG=$(PROD_REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(RELEASE_TAG)
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
$(MAKE) release-manifests
$(MAKE) release-templates

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

.PHONY: release-templates
release-templates: $(RELEASE_DIR)
cp templates/cluster-template* $(RELEASE_DIR)/

.PHONY: release-binary
release-binary: $(RELEASE_DIR)
docker run \
Expand Down Expand Up @@ -327,7 +340,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST)
.PHONY: create-workload-cluster
create-workload-cluster: $(KUSTOMIZE) $(ENVSUBST)
# Create workload Cluster.
$(KUSTOMIZE) build templates | $(ENVSUBST) | kubectl apply -f -
$(ENVSUBST) < $(TEMPLATES_DIR)/$(CLUSTER_TEMPLATE) | kubectl apply -f -

# Wait for the kubeconfig to become available.
timeout 300 bash -c "while ! kubectl get secrets | grep $(CLUSTER_NAME)-kubeconfig; do sleep 1; done"
Expand Down
1 change: 1 addition & 0 deletions hack/create-dev-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export AZURE_CONTROL_PLANE_MACHINE_TYPE="${CONTROL_PLANE_MACHINE_TYPE:-Standard_
export AZURE_NODE_MACHINE_TYPE="${NODE_MACHINE_TYPE:-Standard_D2s_v3}"
export WORKER_MACHINE_COUNT=${WORKER_MACHINE_COUNT:-2}
export KUBERNETES_VERSION="${KUBERNETES_VERSION:-v1.17.4}"
export TEMPLATE_PATH="${TEMPLATE_PATH:-cluster-template.yaml}"

# Generate SSH key.
SSH_KEY_FILE=${SSH_KEY_FILE:-""}
Expand Down
33 changes: 33 additions & 0 deletions hack/gen-flavors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
#set -o verbose

root=$(dirname "${BASH_SOURCE[0]}")/..
kustomize="${root}/hack/tools/bin/kustomize"
flavors_dir="${root}/templates/flavors/"
test_dir="${root}/templates/test/"

rm "${root}/templates/cluster-template"*
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"
# move the default template to the default file expected by clusterctl
mv "${root}/templates/cluster-template-default.yaml" "${root}/templates/cluster-template.yaml"

rm -f "${test_dir}cluster-template"*
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"
24 changes: 7 additions & 17 deletions scripts/ci-conformance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ random-string() {
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}

# generate manifests needed for creating the Azure cluster to run the tests
add_kustomize_patch() {
if ! grep -i -wq "patchesStrategicMerge" "templates/kustomization.yaml"; then
echo "patchesStrategicMerge:" >> "templates/kustomization.yaml"
fi
if ! grep -i -wq "conformance-tags" "templates/kustomization.yaml"; then
echo "- conformance-tags.yaml" >> "templates/kustomization.yaml"
fi
# Enable the bits to inject a script that can pull newer versions of kubernetes
if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then
if ! grep -i -wq "ci-version" "templates/kustomization.yaml"; then
echo "- ci-version.yaml" >> "templates/kustomization.yaml"
fi
fi
}

# build Kubernetes E2E binaries
build_k8s() {
# possibly enable bazel build caching before building kubernetes
Expand Down Expand Up @@ -85,6 +69,13 @@ build_k8s() {
}

create_cluster() {
# export cluster template which contains the manifests needed for creating the Azure cluster to run the tests
if [[ -n ${CI_VERSION:-} || -n ${USE_CI_ARTIFACTS:-} ]]; then
export CLUSTER_TEMPLATE="test/cluster-template-conformance-ci-version"
else
export CLUSTER_TEMPLATE="test/cluster-template-conformance"
fi

export CLUSTER_NAME="capz-conformance-$(head /dev/urandom | LC_ALL=C tr -dc a-z0-9 | head -c 6 ; echo '')"
# Conformance test suite needs a cluster with at least 2 nodes
export CONTROL_PLANE_MACHINE_COUNT=${CONTROL_PLANE_MACHINE_COUNT:-3}
Expand Down Expand Up @@ -163,7 +154,6 @@ mkdir -p "${ARTIFACTS}/logs"

# create cluster
if [[ -z "${SKIP_CREATE_CLUSTER:-}" ]]; then
add_kustomize_patch
create_cluster
fi

Expand Down
Loading

0 comments on commit f960483

Please sign in to comment.