Skip to content

Commit

Permalink
Merge branch 'release/v0.15.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kahoona77 authored and cesmarvin committed Dec 8, 2023
2 parents 8a391cc + 6ff392d commit f86305a
Show file tree
Hide file tree
Showing 47 changed files with 807 additions and 796 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.15.0] - 2023-12-08
### Added
- [#49] Patch-template for mirroring this component and its images into airgapped environments.
### Changed
- [#50] Remove kustomize and hold the operator yaml files in a single helm chart.

## [v0.14.4] - 2023-10-24
### Changed
- [#46] Update cesapp-lib to 0.12.2
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.14.4"
VERSION="0.15.0"

WORKDIR /

Expand Down
84 changes: 38 additions & 46 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!groovy

@Library(['github.com/cloudogu/ces-build-lib@1.67.0'])
@Library(['github.com/cloudogu/ces-build-lib@1.68.0'])
import com.cloudogu.ces.cesbuildlib.*

// Creating necessary git objects
Expand All @@ -21,6 +21,8 @@ repositoryName = "k8s-service-discovery"
project = "github.com/${repositoryOwner}/${repositoryName}"
registry = "registry.cloudogu.com"
registry_namespace = "k8s"
helmTargetDir = "target/k8s"
helmChartDir = "${helmTargetDir}/helm"

// Configuration of branches
productionReleaseBranch = "main"
Expand Down Expand Up @@ -61,14 +63,14 @@ node('docker') {
}

stage('Generate k8s Resources') {
make 'create-temporary-release-resources'
archiveArtifacts 'target/make/k8s/*.yaml'
make 'helm-generate'
archiveArtifacts "${helmTargetDir}/**/*"
}
}

stage("Lint k8s Resources") {
stageLintK8SResources()
}
stage("Lint helm") {
make 'helm-lint'
}
}

stage('SonarQube') {
stageStaticAnalysisSonarQube()
Expand All @@ -81,33 +83,33 @@ node('docker') {
k3d.startK3d()
}

def imageName
String controllerVersion = makefile.getVersion()
def imageName = ""
stage('Build & Push Image') {
imageName=k3d.buildAndPushToLocalRegistry("cloudogu/${repositoryName}", controllerVersion)
imageName = k3d.buildAndPushToLocalRegistry("cloudogu/${repositoryName}", controllerVersion)
}

GString sourceDeploymentYaml="target/make/k8s/${repositoryName}_${controllerVersion}.yaml"
GString sourceDeploymentYamlWithNamespace="target/make/k8s/${repositoryName}_${controllerVersion}_namespaced.yaml"

stage('Update development resources') {
sh "cat ${sourceDeploymentYaml} | sed \"s/{{ .Namespace }}/default/\" > ${sourceDeploymentYamlWithNamespace}"
docker.image('mikefarah/yq:4.22.1')
def repository = imageName.substring(0, imageName.lastIndexOf(":"))
docker.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/workdir -w /workdir") {
sh "yq -i '(select(.kind == \"Deployment\").spec.template.spec.containers[]|select(.name == \"manager\")).image=\"${imageName}\"' ${sourceDeploymentYamlWithNamespace}"
sh "STAGE=development IMAGE_DEV=${repository} make helm-values-replace-image-repo"
}
}

stage('Deploy Manager') {
k3d.kubectl("apply -f ${sourceDeploymentYamlWithNamespace}")
k3d.helm("install ${repositoryName} ${helmChartDir}")
}

stage('Wait for Ready Rollout') {
k3d.kubectl("--namespace default wait --for=condition=Ready pods --all")
}

stageAutomaticRelease()
} catch(Exception e) {
k3d.collectAndArchiveLogs()
throw e as java.lang.Throwable
} finally {
stage('Remove k3d cluster') {
k3d.deleteK3d()
Expand All @@ -125,17 +127,6 @@ void gitWithCredentials(String command) {
}
}

void stageLintK8SResources() {
String kubevalImage = "cytopia/kubeval:0.13"

docker
.image(kubevalImage)
.inside("-v ${WORKSPACE}/target/make/k8s:/data -t --entrypoint=")
{
sh "kubeval /data/${repositoryName}_${makefile.getVersion()}.yaml --ignore-missing-schemas"
}
}

void stageStaticAnalysisReviewDog() {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()

Expand Down Expand Up @@ -190,30 +181,31 @@ void stageAutomaticRelease() {
}
}

stage('Finish Release') {
gitflow.finishRelease(releaseVersion, productionReleaseBranch)
}

stage('Push to Registry') {
GString targetOperatorResourceYaml = "target/make/k8s/${repositoryName}_${controllerVersion}.yaml"

DoguRegistry registry = new DoguRegistry(this)
registry.pushK8sYaml(targetOperatorResourceYaml, repositoryName, "k8s", "${controllerVersion}")
stage('Sign Release') {
gpg.createSignature()
}

stage('Push Helm chart to Harbor') {
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}")
{
make 'helm-package-release'

withCredentials([usernamePassword(credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
sh ".bin/helm registry login ${registry} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"
sh ".bin/helm push target/make/k8s/helm/${repositoryName}-${controllerVersion}.tgz oci://${registry}/${registry_namespace}/"
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}")
{
// Package operator-chart
make 'helm-package'
archiveArtifacts "${helmTargetDir}/**/*"

// Push charts
withCredentials([usernamePassword(credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
sh ".bin/helm registry login ${registry} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"

sh ".bin/helm push ${helmChartDir}/${repositoryName}-${controllerVersion}.tgz oci://${registry}/${registry_namespace}/"
}
}
}
}

stage('Finish Release') {
gitflow.finishRelease(releaseVersion, productionReleaseBranch)
}

stage('Add Github-Release') {
Expand Down
72 changes: 41 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Set these to the desired values
ARTIFACT_ID=k8s-service-discovery
VERSION=0.14.4
VERSION=0.15.0

## 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.21
MAKEFILES_VERSION=8.7.3
MAKEFILES_VERSION=9.0.1
LINT_VERSION?=v1.52.1

ADDITIONAL_CLEAN=dist-clean
Expand All @@ -29,41 +27,53 @@ include build/make/digital-signature.mk
include build/make/mocks.mk

K8S_RUN_PRE_TARGETS=setup-etcd-port-forward
PRE_COMPILE=generate
K8S_PRE_GENERATE_TARGETS=k8s-create-temporary-resource generate-warp-config generate-menu-json template-dev-only-image-pull-policy

K8S_COMPONENT_SOURCE_VALUES = ${HELM_SOURCE_DIR}/values.yaml
K8S_COMPONENT_TARGET_VALUES = ${HELM_TARGET_DIR}/values.yaml
PRE_COMPILE=generate-deepcopy
HELM_PRE_APPLY_TARGETS=template-stage template-log-level template-image-pull-policy
HELM_PRE_GENERATE_TARGETS = helm-values-update-image-version
HELM_POST_GENERATE_TARGETS = helm-values-replace-image-repo
CHECK_VAR_TARGETS=check-all-vars
IMAGE_IMPORT_TARGET=image-import

include build/make/k8s-controller.mk

.PHONY: helm-values-update-image-version
helm-values-update-image-version: $(BINARY_YQ)
@echo "Updating the image version in source values.yaml to ${VERSION}..."
@$(BINARY_YQ) -i e ".manager.image.tag = \"${VERSION}\"" ${K8S_COMPONENT_SOURCE_VALUES}

.PHONY: helm-values-replace-image-repo
helm-values-replace-image-repo: $(BINARY_YQ)
@if [[ ${STAGE} != "production" ]]; then \
echo "Setting dev image repo in target values.yaml!" ;\
$(BINARY_YQ) -i e ".manager.image.repository=\"${IMAGE_DEV}\"" "${K8S_COMPONENT_TARGET_VALUES}" ;\
fi

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
@echo "Generate manifests..."
@$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..."
.PHONY: template-stage
template-stage: $(BINARY_YQ)
@if [[ ${STAGE} != "production" ]]; then \
echo "Setting STAGE env in deployment to ${STAGE}!" ;\
$(BINARY_YQ) -i e ".manager.env.stage=\"${STAGE}\"" ${K8S_COMPONENT_TARGET_VALUES} ;\
fi

.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="./..."
.PHONY: template-log-level
template-log-level: ${BINARY_YQ}
@if [[ ${STAGE} != "production" ]]; then \
echo "Setting LOG_LEVEL env in deployment to ${LOG_LEVEL}!" ; \
$(BINARY_YQ) -i e ".manager.env.logLevel=\"${LOG_LEVEL}\"" "${K8S_COMPONENT_TARGET_VALUES}" ; \
fi

.PHONY: template-image-pull-policy
template-image-pull-policy: $(BINARY_YQ)
@if [[ ${STAGE} != "production" ]]; then \
echo "Setting pull policy to always!" ; \
$(BINARY_YQ) -i e ".manager.imagePullPolicy=\"Always\"" "${K8S_COMPONENT_TARGET_VALUES}" ; \
fi

## Local Development

.PHONY: setup-etcd-port-forward
setup-etcd-port-forward:
kubectl port-forward etcd-0 4001:2379 &

.PHONY: generate-warp-config
generate-warp-config:
@echo "---" >> $(K8S_RESOURCE_TEMP_YAML)
@cat $(K8S_WARP_CONFIG_RESOURCE_YAML) >> $(K8S_RESOURCE_TEMP_YAML)

.PHONY: generate-menu-json
generate-menu-json:
@echo "---" >> $(K8S_RESOURCE_TEMP_YAML)
@cat $(K8S_WARP_MENU_JSON_YAML) >> $(K8S_RESOURCE_TEMP_YAML)

create-temporary-release-resources: $(K8S_PRE_GENERATE_TARGETS)

.PHONY: template-dev-only-image-pull-policy
template-dev-only-image-pull-policy: $(BINARY_YQ)
@echo "Setting pull policy to always!"
@$(BINARY_YQ) -i e "(select(.kind == \"Deployment\").spec.template.spec.containers[]|select(.image == \"*$(ARTIFACT_ID)*\").imagePullPolicy)=\"Always\"" $(K8S_RESOURCE_TEMP_YAML)
Loading

0 comments on commit f86305a

Please sign in to comment.