Skip to content

Commit

Permalink
Merge branch 'release/v0.13.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nhinze23 authored and cesmarvin committed Aug 31, 2023
2 parents 4fb7680 + 2f02635 commit f81caf6
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.13.1] - 2023-08-31
### Fixed
- [#34] Add label `app: ces` for all generated Kubernetes resources

### Added
- [#36] Add "k8s-etcd" as a dependency to the helm-chart

## [v0.13.0] - 2023-07-07
### Added
- [#32] Add Helm chart release process to project
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN make compile-generic
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="[email protected]" \
NAME="k8s-service-discovery" \
VERSION="0.13.0"
VERSION="0.13.1"

WORKDIR /

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Set these to the desired values
ARTIFACT_ID=k8s-service-discovery
VERSION=0.13.0
VERSION=0.13.1

## 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.20.3
MAKEFILES_VERSION=7.10.0
MAKEFILES_VERSION=7.13.0
LINT_VERSION?=v1.52.1

ADDITIONAL_CLEAN=dist-clean
Expand Down
4 changes: 2 additions & 2 deletions build/make/k8s-controller.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ K8S_INTEGRATION_TEST_DIR=${TARGET_DIR}/k8s-integration-test
##@ K8s - EcoSystem

.PHONY: build
build: image-import k8s-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.
build: k8s-helm-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.

##@ Release

Expand Down Expand Up @@ -83,7 +83,7 @@ k8s-integration-test: $(K8S_INTEGRATION_TEST_DIR) manifests generate envtest ##
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/controller-gen@v0.11.3)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0)

KUSTOMIZE = $(UTILITY_BIN_PATH)/kustomize
.PHONY: kustomize
Expand Down
2 changes: 1 addition & 1 deletion build/make/k8s-dogu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Dogu
metadata:
name: NAME
labels:
dogu: NAME
app: ces
spec:
name: NAMESPACE/NAME
version: VERSION
3 changes: 3 additions & 0 deletions build/make/k8s-helm-temp-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: replaceme
version: 0.0.0
62 changes: 48 additions & 14 deletions build/make/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ endif

BINARY_YQ = $(UTILITY_BIN_PATH)/yq
BINARY_HELM = $(UTILITY_BIN_PATH)/helm
BINARY_HELM_VERSION?=v3.12.0-dev.1.0.20230817154107-a749b663101d
BINARY_HELM_ADDITIONAL_PUSH_ARGS?=--plain-http
BINARY_HELM_ADDITIONAL_PACK_ARGS?=
BINARY_HELM_ADDITIONAL_UNINST_ARGS?=
BINARY_HELM_ADDITIONAL_UPGR_ARGS?=

# The productive tag of the image
IMAGE ?=
Expand All @@ -22,6 +27,8 @@ K8S_RESOURCE_TEMP_FOLDER ?= $(TARGET_DIR)/make/k8s
K8S_RESOURCE_TEMP_YAML ?= $(K8S_RESOURCE_TEMP_FOLDER)/$(ARTIFACT_ID)_$(VERSION).yaml
K8S_HELM_TARGET ?= $(K8S_RESOURCE_TEMP_FOLDER)/helm
K8S_HELM_RESSOURCES ?= k8s/helm
K8S_HELM_RELEASE_TGZ=${K8S_HELM_TARGET}/${ARTIFACT_ID}-${VERSION}.tgz
K8S_HELM_TARGET_DEP_DIR=charts

##@ K8s - Variables

Expand Down Expand Up @@ -79,9 +86,9 @@ k8s-apply: k8s-generate $(K8S_POST_GENERATE_TARGETS) ## Applies all generated K8
@kubectl apply -f $(K8S_RESOURCE_TEMP_YAML) --namespace=${NAMESPACE}

##@ K8s - Helm general

${K8S_HELM_RESSOURCES}/Chart.yaml: ${BINARY_HELM} ## Creates the Chart.yaml-template if missing
@echo "Create Chart.yaml..."
.PHONY: k8s-helm-init-chart
k8s-helm-init-chart: ${BINARY_HELM} ## Creates a Chart.yaml-template with zero values
@echo "Initialize ${K8S_HELM_RESSOURCES}/Chart.yaml..."
@mkdir -p ${K8S_HELM_RESSOURCES}/tmp/
@${BINARY_HELM} create ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}
@cp ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}/Chart.yaml ${K8S_HELM_RESSOURCES}/
Expand All @@ -90,17 +97,19 @@ ${K8S_HELM_RESSOURCES}/Chart.yaml: ${BINARY_HELM} ## Creates the Chart.yaml-temp
@sed -i 's/version: .*/version: 0.0.0-replaceme/' ${K8S_HELM_RESSOURCES}/Chart.yaml

.PHONY: k8s-helm-delete
k8s-helm-delete: ${BINARY_HELM} ## Uninstalls the current helm chart.
k8s-helm-delete: ${BINARY_HELM} check-k8s-namespace-env-var ## Uninstalls the current helm chart.
@echo "Uninstall helm chart"
@${BINARY_HELM} uninstall ${ARTIFACT_ID}
@${BINARY_HELM} uninstall ${ARTIFACT_ID} --namespace=${NAMESPACE} ${BINARY_HELM_ADDITIONAL_UNINST_ARGS} || true

.PHONY: k8s-helm-generate-chart
k8s-helm-generate-chart: ${K8S_HELM_RESSOURCES}/Chart.yaml $(K8S_RESOURCE_TEMP_FOLDER) ## Generates the final helm chart.
k8s-helm-generate-chart: ${K8S_HELM_TARGET}/Chart.yaml k8s-helm-create-temp-dependencies ## Generates the final helm chart.

${K8S_HELM_TARGET}/Chart.yaml: $(K8S_RESOURCE_TEMP_FOLDER)
@echo "Generate helm chart..."
@rm -drf ${K8S_HELM_TARGET} # delete folder, so Chart.yaml is newly created from template
@rm -drf ${K8S_HELM_TARGET} # delete folder, so the chart is newly created.
@mkdir -p ${K8S_HELM_TARGET}/templates
@cp $(K8S_RESOURCE_TEMP_YAML) ${K8S_HELM_TARGET}/templates
@cp ${K8S_HELM_RESSOURCES}/Chart.yaml ${K8S_HELM_TARGET}
@cp -r ${K8S_HELM_RESSOURCES}/** ${K8S_HELM_TARGET}
@sed -i 's/appVersion: "0.0.0-replaceme"/appVersion: "${VERSION}"/' ${K8S_HELM_TARGET}/Chart.yaml
@sed -i 's/version: 0.0.0-replaceme/version: ${VERSION}/' ${K8S_HELM_TARGET}/Chart.yaml

Expand All @@ -110,23 +119,48 @@ k8s-helm-generate-chart: ${K8S_HELM_RESSOURCES}/Chart.yaml $(K8S_RESOURCE_TEMP_F
k8s-helm-generate: k8s-generate k8s-helm-generate-chart ## Generates the final helm chart with dev-urls.

.PHONY: k8s-helm-apply
k8s-helm-apply: ${BINARY_HELM} image-import k8s-helm-generate $(K8S_POST_GENERATE_TARGETS) ## Generates and installs the helm chart.
k8s-helm-apply: ${BINARY_HELM} check-k8s-namespace-env-var image-import k8s-helm-generate $(K8S_POST_GENERATE_TARGETS) ## Generates and installs the helm chart.
@echo "Apply generated helm chart"
@${BINARY_HELM} upgrade -i ${ARTIFACT_ID} ${K8S_HELM_TARGET}
@${BINARY_HELM} upgrade -i ${ARTIFACT_ID} ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_UPGR_ARGS} --namespace ${NAMESPACE}

.PHONY: k8s-helm-reinstall
k8s-helm-reinstall: k8s-helm-delete k8s-helm-apply ## Uninstalls the current helm chart and reinstalls it.

##@ K8s - Helm release targets

.PHONY: k8s-helm-generate-release
k8s-helm-generate-release: $(K8S_PRE_GENERATE_TARGETS) k8s-helm-generate-chart ## Generates the final helm chart with release urls.
k8s-helm-generate-release: ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml ## Generates the final helm chart with release urls.

${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml: $(K8S_PRE_GENERATE_TARGETS) ${K8S_HELM_TARGET}/Chart.yaml
@sed -i "s/'{{ .Namespace }}'/'{{ .Release.Namespace }}'/" ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml

.PHONY: k8s-helm-package-release
k8s-helm-package-release: ${BINARY_HELM} k8s-helm-generate-release $(K8S_POST_GENERATE_TARGETS) ## Generates and packages the helm chart with release urls.
k8s-helm-package-release: ${BINARY_HELM} k8s-helm-delete-existing-tgz ${K8S_HELM_RELEASE_TGZ} ## Generates and packages the helm chart with release urls.

.PHONY: k8s-helm-delete-existing-tgz
k8s-helm-delete-existing-tgz: ## Remove an existing Helm package.
# remove
@rm -f ${K8S_HELM_RELEASE_TGZ}*

${K8S_HELM_RELEASE_TGZ}: ${BINARY_HELM} ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml k8s-helm-generate-chart $(K8S_POST_GENERATE_TARGETS) ## Generates and packages the helm chart with release urls.
@echo "Package generated helm chart"
@${BINARY_HELM} package ${K8S_HELM_TARGET} -d ${K8S_HELM_TARGET}
@${BINARY_HELM} package ${K8S_HELM_TARGET} -d ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_PACK_ARGS}

.PHONY: k8s-helm-create-temp-dependencies
k8s-helm-create-temp-dependencies: ${K8S_HELM_TARGET}/Chart.yaml
# we use helm dependencies internally but never use them as "official" dependency because the namespace may differ
# instead we create empty dependencies to satisfy the helm package call and delete the whole directory from the chart.tgz later-on.
@echo "Create helm temp dependencies (if they exist)"
@for dep in `yq -e '.dependencies[].name // ""' ${K8S_HELM_TARGET}/Chart.yaml`; do \
mkdir -p ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep} ; \
sed "s|replaceme|$${dep}|g" $(BUILD_DIR)/make/k8s-helm-temp-chart.yaml > ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep}/Chart.yaml ; \
done

.PHONY: chart-import
chart-import: check-all-vars check-k8s-artifact-id k8s-helm-generate-chart k8s-helm-package-release image-import ## Imports the currently available image into the cluster-local registry.
@echo "Import ${K8S_HELM_RELEASE_TGZ} into K8s cluster ${K3CES_REGISTRY_URL_PREFIX}..."
@${BINARY_HELM} push ${K8S_HELM_RELEASE_TGZ} oci://${K3CES_REGISTRY_URL_PREFIX}/k8s ${BINARY_HELM_ADDITIONAL_PUSH_ARGS}
@echo "Done."

##@ K8s - Docker

Expand Down Expand Up @@ -172,4 +206,4 @@ ${BINARY_YQ}: $(UTILITY_BIN_PATH) ## Download yq locally if necessary.
$(call go-get-tool,$(BINARY_YQ),github.com/mikefarah/yq/[email protected])

${BINARY_HELM}: $(UTILITY_BIN_PATH) ## Download helm locally if necessary.
$(call go-get-tool,$(BINARY_HELM),helm.sh/helm/v3/cmd/helm@latest)
$(call go-get-tool,$(BINARY_HELM),helm.sh/helm/v3/cmd/helm@${BINARY_HELM_VERSION})
5 changes: 3 additions & 2 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
namePrefix: k8s-service-discovery-

# Labels to add to all resources and selectors.
#commonLabels:
# someName: someValue
commonLabels:
app: ces
app.kubernetes.io/name: k8s-service-discovery

bases:
- ../rbac
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ kind: Kustomization
images:
- name: controller
newName: cloudogu/k8s-service-discovery
newTag: 0.13.0
newTag: 0.13.1
7 changes: 7 additions & 0 deletions k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ version: 0.0.0-replaceme
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.0-replaceme"

dependencies:
# For k8s-etcd it is important to include "prerelease"-versions like "3.5.7-4", so there must be a "-0" after the patch-version.
# see https://helm.sh/docs/chart_best_practices/dependencies/#prerelease-versions for more information
- name: "k8s-etcd"
version: "^3.5.x-0"
condition: false

0 comments on commit f81caf6

Please sign in to comment.