-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v0.2.0' into main
- Loading branch information
Showing
48 changed files
with
3,031 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Usage: | ||
# 1. Copy this file as `.env` into your project | ||
# 2. Adapt the information below with the your personal data. | ||
# | ||
# The file `.env` is ignored by git. Note: DO NOT COMMIT your personal data. | ||
export K8S_CLUSTER_ROOT=/home/jsprey/Documents/GIT/k3ces | ||
export WATCH_NAMESPACE=$(shell kubectl config view --minify -o jsonpath='{..namespace}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ RUN make compile-generic | |
FROM gcr.io/distroless/static:nonroot | ||
LABEL maintainer="[email protected]" \ | ||
NAME="k8s-service-discovery" \ | ||
VERSION="0.1.0" | ||
VERSION="0.2.0" | ||
|
||
WORKDIR / | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
# Set these to the desired values | ||
ARTIFACT_ID=k8s-service-discovery | ||
VERSION=0.1.0 | ||
VERSION=0.2.0 | ||
|
||
GOTAG?=1.17.7 | ||
MAKEFILES_VERSION=5.0.0 | ||
|
||
# Image URL to use all building/pushing image targets | ||
## Image URL to use all building/pushing image targets | ||
IMAGE_DEV=${K3CES_REGISTRY_URL_PREFIX}/${ARTIFACT_ID}:${VERSION} | ||
IMAGE=cloudogu/${ARTIFACT_ID}:${VERSION} | ||
GOTAG?=1.17.7 | ||
MAKEFILES_VERSION=6.0.1 | ||
|
||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.23 | ||
K8S_INTEGRATION_TEST_DIR=${TARGET_DIR}/k8s-integration-test | ||
K8S_RESOURCE_YAML=${TARGET_DIR}/${ARTIFACT_ID}_${VERSION}.yaml | ||
DEFAULT_NAMESPACE?="$(shell kubectl config view | grep namespace | head -n 1 | sed "s/^.*namespace: //g")" | ||
|
||
# make sure to create a statically linked binary otherwise it may quit with | ||
# "exec user process caused: no such file or directory" | ||
GO_BUILD_FLAGS=-mod=vendor -a -tags netgo,osusergo $(LDFLAGS) -o $(BINARY) | ||
# remove DWARF symbol table and strip other symbols to shave ~13 MB from binary | ||
ADDITIONAL_LDFLAGS=-extldflags -static -w -s | ||
ADDITIONAL_CLEAN=dist-clean | ||
|
||
.DEFAULT_GOAL:=help | ||
K8S_RESOURCE_DIR=${WORKDIR}/k8s | ||
K8S_WARP_CONFIG_RESOURCE_YAML=${K8S_RESOURCE_DIR}/k8s-ces-warp-config.yaml | ||
K8S_WARP_MENU_JSON_YAML=${K8S_RESOURCE_DIR}/k8s-ces-menu-json.yaml | ||
|
||
include build/make/variables.mk | ||
|
||
ADDITIONAL_CLEAN=dist-clean | ||
PRE_COMPILE=generate vet | ||
|
||
include build/make/self-update.mk | ||
include build/make/dependencies-gomod.mk | ||
include build/make/build.mk | ||
|
@@ -37,27 +25,12 @@ include build/make/static-analysis.mk | |
include build/make/clean.mk | ||
include build/make/digital-signature.mk | ||
|
||
K8S_RUN_PRE_TARGETS=setup-etcd-port-forward | ||
PRE_COMPILE=generate vet | ||
K8S_PRE_GENERATE_TARGETS=k8s-create-temporary-resource generate-warp-config generate-menu-json | ||
|
||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# This is a requirement for 'setup-envtest.sh' in the test target. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
##@ EcoSystem | ||
|
||
.PHONY: build | ||
build: docker-build image-import k8s-apply ## Builds a new version of the setup and deploys it into the K8s-EcoSystem. | ||
|
||
##@ Development (without go container) | ||
|
||
${STATIC_ANALYSIS_DIR}/report-govet.out: ${SRC} $(STATIC_ANALYSIS_DIR) | ||
@go vet ./... | tee $@ | ||
|
||
.PHONY: vet | ||
vet: ${STATIC_ANALYSIS_DIR}/report-govet.out ## Run go vet against code. | ||
include build/make/k8s-controller.mk | ||
|
||
##@ Kubernetes Controller | ||
|
||
.PHONY: manifests | ||
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
|
@@ -69,95 +42,20 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and | |
@echo "Auto-generate deepcopy functions..." | ||
@$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
$(K8S_INTEGRATION_TEST_DIR): | ||
@mkdir -p $@ | ||
|
||
.PHONY: k8s-integration-test | ||
k8s-integration-test: $(K8S_INTEGRATION_TEST_DIR) manifests generate vet envtest ## Run k8s integration tests. | ||
@echo "Running k8s integration tests..." | ||
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -tags=k8s_integration ./... -coverprofile ${K8S_INTEGRATION_TEST_DIR}/report-k8s-integration.out | ||
|
||
##@ Build | ||
|
||
.PHONY: build-controller | ||
build-controller: ${SRC} compile ## Builds the controller Go binary. | ||
|
||
.PHONY: run | ||
run: manifests generate vet ## Run a controller from your host. | ||
go run ./main.go | ||
|
||
##@ Release | ||
|
||
.PHONY: controller-release | ||
controller-release: ## Interactively starts the release workflow. | ||
@echo "Starting git flow release..." | ||
@build/make/release.sh controller-tool | ||
|
||
##@ Docker | ||
|
||
.PHONY: docker-build | ||
docker-build: ${SRC} ## Builds the docker image of the k8s-ces-setup `cloudogu/k8s-ces-setup:version`. | ||
@echo "Building docker image of dogu..." | ||
DOCKER_BUILDKIT=1 docker build . -t ${IMAGE} | ||
|
||
${K8S_CLUSTER_ROOT}/image.tar: check-k8s-cluster-root-env-var | ||
# Saves the `cloudogu/k8s-ces-setup:version` image into a file into the K8s root path to be available on all nodes. | ||
docker save ${IMAGE} -o ${K8S_CLUSTER_ROOT}/image.tar | ||
|
||
.PHONY: image-import | ||
image-import: ${K8S_CLUSTER_ROOT}/image.tar | ||
# Imports the currently available image `cloudogu/k8s-ces-setup:version` into the K8s cluster for all nodes. | ||
@echo "Import docker image of dogu into all K8s nodes..." | ||
@cd ${K8S_CLUSTER_ROOT} && \ | ||
for node in $$(vagrant status --machine-readable | grep "state,running" | awk -F',' '{print $$2}'); \ | ||
do \ | ||
echo "...$${node}"; \ | ||
vagrant ssh $${node} -- -t "sudo k3s ctr images import /vagrant/image.tar"; \ | ||
done; | ||
@echo "Done." | ||
rm ${K8S_CLUSTER_ROOT}/image.tar | ||
|
||
.PHONY: check-k8s-cluster-root-env-var | ||
check-k8s-cluster-root-env-var: | ||
@echo "Checking if env var K8S_CLUSTER_ROOT is set..." | ||
@bash -c export -p | grep K8S_CLUSTER_ROOT | ||
@echo "Done." | ||
|
||
##@ Deployment | ||
|
||
ifndef ignore-not-found | ||
ignore-not-found = false | ||
endif | ||
|
||
${K8S_RESOURCE_YAML}: ${TARGET_DIR} manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE} | ||
$(KUSTOMIZE) build config/default > ${K8S_RESOURCE_YAML} | ||
|
||
.PHONY: k8s-generate | ||
k8s-generate: ${K8S_RESOURCE_YAML} ## Create required k8s resources in ./dist/... | ||
@echo "Generating new kubernetes resources..." | ||
|
||
.PHONY: k8s-apply | ||
k8s-apply: k8s-generate ## Deploy controller to the K8s cluster specified in ~/.kube/config. | ||
cat ${K8S_RESOURCE_YAML} | sed "s/{{ .Namespace }}/${DEFAULT_NAMESPACE}/" | kubectl apply -f - | ||
## Local Development | ||
|
||
.PHONY: k8s-delete | ||
k8s-delete: k8s-generate ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. | ||
cat ${K8S_RESOURCE_YAML} | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
.PHONY: setup-etcd-port-forward | ||
setup-etcd-port-forward: | ||
kubectl port-forward etcd-0 4001:2379 & | ||
|
||
##@ Download Kubernetes Utility Tools | ||
.PHONY: generate-warp-config | ||
generate-warp-config: | ||
@echo "---" >> $(K8S_RESOURCE_TEMP_YAML) | ||
@cat $(K8S_WARP_CONFIG_RESOURCE_YAML) >> $(K8S_RESOURCE_TEMP_YAML) | ||
|
||
CONTROLLER_GEN = $(UTILITY_BIN_PATH)/controller-gen | ||
.PHONY: controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
.PHONY: generate-menu-json | ||
generate-menu-json: | ||
@echo "---" >> $(K8S_RESOURCE_TEMP_YAML) | ||
@cat $(K8S_WARP_MENU_JSON_YAML) >> $(K8S_RESOURCE_TEMP_YAML) | ||
|
||
KUSTOMIZE = $(UTILITY_BIN_PATH)/kustomize | ||
.PHONY: kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
ENVTEST = $(UTILITY_BIN_PATH)/setup-envtest | ||
.PHONY: envtest | ||
envtest: ## Download envtest-setup locally if necessary. | ||
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# This script can be used to build and deploy kubernetes controllers. It is required to implement the controller | ||
# specific targets `manifests` and `generate`: | ||
# | ||
# Examples: | ||
# | ||
#.PHONY: manifests | ||
#manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
# @echo "Generate manifests..." | ||
# @$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
# | ||
#.PHONY: generate | ||
#generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
# @echo "Auto-generate deepcopy functions..." | ||
# @$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
|
||
# This script required the k8s.mk script | ||
include $(WORKDIR)/build/make/k8s.mk | ||
|
||
## Variables | ||
|
||
# Contains the artifact yaml used as | ||
K8S_RESOURCE_TEMP_YAML=${TARGET_DIR}/${ARTIFACT_ID}_${VERSION}.yaml | ||
|
||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# This is a requirement for 'setup-envtest.sh' in the test target. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
# make sure to create a statically linked binary otherwise it may quit with | ||
# "exec user process caused: no such file or directory" | ||
GO_BUILD_FLAGS=-mod=vendor -a -tags netgo,osusergo $(LDFLAGS) -o $(BINARY) | ||
|
||
# remove DWARF symbol table and strip other symbols to shave ~13 MB from binary | ||
ADDITIONAL_LDFLAGS=-extldflags -static -w -s | ||
|
||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.23 | ||
K8S_INTEGRATION_TEST_DIR=${TARGET_DIR}/k8s-integration-test | ||
|
||
##@ K8s - EcoSystem | ||
|
||
.PHONY: build | ||
build: k8s-delete image-import k8s-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem. | ||
|
||
##@ Release | ||
|
||
.PHONY: controller-release | ||
controller-release: ## Interactively starts the release workflow. | ||
@echo "Starting git flow release..." | ||
@build/make/release.sh controller-tool | ||
|
||
##@ K8s - Development | ||
|
||
.PHONY: build-controller | ||
build-controller: ${SRC} compile ## Builds the controller Go binary. | ||
|
||
# Allows to perform tasks before locally running the controller | ||
K8S_RUN_PRE_TARGETS ?= | ||
.PHONY: run | ||
run: manifests generate vet $(K8S_RUN_PRE_TARGETS) ## Run a controller from your host. | ||
go run -ldflags "-X main.Version=$(VERSION)" ./main.go | ||
|
||
##@ K8s - Integration test with envtest | ||
|
||
$(K8S_INTEGRATION_TEST_DIR): | ||
@mkdir -p $@ | ||
|
||
.PHONY: k8s-integration-test | ||
k8s-integration-test: $(K8S_INTEGRATION_TEST_DIR) manifests generate vet envtest ## Run k8s integration tests. | ||
@echo "Running K8s integration tests..." | ||
@KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -tags=k8s_integration ./... -coverprofile ${K8S_INTEGRATION_TEST_DIR}/report-k8s-integration.out | ||
|
||
##@ K8s - Controller Resource | ||
|
||
# The pre generation script creates a K8s resource yaml containing generated manager yaml. | ||
.PHONY: k8s-create-temporary-resource | ||
k8s-create-temporary-resource: ${TARGET_DIR} manifests kustomize | ||
@echo "Generating temporary k8s resources $(K8S_RESOURCE_TEMP_YAML)..." | ||
cd $(WORKDIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE) | ||
$(KUSTOMIZE) build config/default > $(K8S_RESOURCE_TEMP_YAML) | ||
@echo "Done." | ||
|
||
##@ K8s - Download Kubernetes Utility Tools | ||
|
||
CONTROLLER_GEN = $(UTILITY_BIN_PATH)/controller-gen | ||
.PHONY: controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
||
KUSTOMIZE = $(UTILITY_BIN_PATH)/kustomize | ||
.PHONY: kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
ENVTEST = $(UTILITY_BIN_PATH)/setup-envtest | ||
.PHONY: envtest | ||
envtest: ## Download envtest-setup locally if necessary. | ||
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
# Variables | ||
|
||
# Path to the dogu json of the dogu | ||
DOGU_JSON_FILE=$(WORKDIR)/dogu.json | ||
DOGU_JSON_DEV_FILE=${TARGET_DIR}/dogu.json | ||
# Name of the dogu is extracted from the dogu.json | ||
ARTIFACT_ID=$(shell yq -e ".Name" $(DOGU_JSON_FILE) | sed "s|.*/||g") | ||
# Namespace of the dogu is extracted from the dogu.json | ||
ARTIFACT_NAMESPACE=$(shell yq -e ".Name" $(DOGU_JSON_FILE) | sed "s|/.*||g") | ||
# Namespace of the dogu is extracted from the dogu.json | ||
VERSION=$(shell yq -e ".Version" $(DOGU_JSON_FILE)) | ||
# Image of the dogu is extracted from the dogu.json | ||
IMAGE=$(shell yq -e ".Image" $(DOGU_JSON_FILE)):$(VERSION) | ||
IMAGE_DEV_WITHOUT_TAG=$(shell yq -e ".Image" $(DOGU_JSON_FILE) | sed "s|registry\.cloudogu\.com\(.\+\)|${K3CES_REGISTRY_URL_PREFIX}\1|g") | ||
IMAGE_DEV=${IMAGE_DEV_WITHOUT_TAG}:${VERSION} | ||
|
||
include $(WORKDIR)/build/make/k8s.mk | ||
|
||
##@ K8s - EcoSystem | ||
|
||
.PHONY: build | ||
build: k8s-delete image-import install-dogu-descriptor k8s-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem. | ||
|
||
##@ K8s - Dogu - Resource | ||
|
||
# The additional k8s yaml files | ||
K8S_RESOURCE_PRODUCTIVE_FOLDER ?= $(WORKDIR)/k8s | ||
K8S_RESOURCE_PRODUCTIVE_YAML ?= $(K8S_RESOURCE_PRODUCTIVE_FOLDER)/$(ARTIFACT_ID).yaml | ||
K8S_RESOURCE_DOGU_CR_TEMPLATE_YAML ?= $(WORKDIR)/build/make/k8s-dogu.tpl | ||
# The pre generation script creates a k8s resource yaml containing the dogu crd and the content from the k8s folder. | ||
.PHONY: k8s-create-temporary-resource | ||
k8s-create-temporary-resource: | ||
@echo "Generating temporary K8s resources $(K8S_RESOURCE_TEMP_YAML)..." | ||
@rm -f $(K8S_RESOURCE_TEMP_YAML) | ||
@test -f $(K8S_RESOURCE_PRODUCTIVE_YAML) && (cp $(K8S_RESOURCE_PRODUCTIVE_YAML) $(K8S_RESOURCE_TEMP_YAML)) || (touch $(K8S_RESOURCE_TEMP_YAML)) | ||
@echo "---" >> $(K8S_RESOURCE_TEMP_YAML) | ||
@sed "s|NAMESPACE|$(ARTIFACT_NAMESPACE)|g" $(K8S_RESOURCE_DOGU_CR_TEMPLATE_YAML) | sed "s|NAME|$(ARTIFACT_ID)|g" | sed "s|VERSION|$(VERSION)|g" >> $(K8S_RESOURCE_TEMP_YAML) | ||
@echo "Done." | ||
|
||
##@ K8s - Dogu | ||
|
||
.PHONY: install-dogu-descriptor | ||
install-dogu-descriptor: ## Installs a configmap with current dogu.json into the cluster. | ||
@echo "Generate configmap from dogu.json..." | ||
|
||
@jq ".Image=\"${IMAGE_DEV_WITHOUT_TAG}\"" ${DOGU_JSON_FILE} > ${DOGU_JSON_DEV_FILE} | ||
|
||
@kubectl create configmap "$(ARTIFACT_ID)-descriptor" --from-file=$(DOGU_JSON_DEV_FILE) --dry-run=client -o yaml | kubectl apply -f - | ||
@echo "Done." |
Oops, something went wrong.