diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..460380abe727020de5a3d566a5ade21b73aa63b4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,376 @@ +pipeline { + agent { + node { + label 'ozgcloud-jenkins-build-agent-jdk21' + } + } + + environment { + BLUE_OCEAN_URL = "https://jenkins.infra.ozg-cloud.systems/job/xta-test-server/job/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/" + RELEASE_REGEX = /\d+.\d+.\d+/ + SNAPSHOT_REGEX = /\d+.\d+.\d+-SNAPSHOT/ + FAILED_STAGE = "" + SH_SUCCESS_STATUS_CODE = 0 + } + + options { + timeout(time: 1, unit: 'HOURS') + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '5')) + } + + stages { + stage('Check Version') { + steps { + script { + FAILED_STAGE = env.STAGE_NAME + def rootVersion = getPomVersion('pom.xml') + + if(isReleaseBranch()){ + if ( !(rootVersion ==~ RELEASE_REGEX)) { + error("Keine Release Version für Branch ${env.BRANCH_NAME}.") + } + } else { + if ( !(rootVersion ==~ SNAPSHOT_REGEX)) { + error("Keine Snapshot Version für Branch ${env.BRANCH_NAME}.") + } + } + } + } + } + stage('Set Version') { + when { + not { + anyOf { + branch 'master' + branch 'release' + } + } + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + JAR_TAG = getPomVersion('pom.xml').replace("SNAPSHOT", "${env.BRANCH_NAME}-SNAPSHOT") + } + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh "mvn -s $MAVEN_SETTINGS versions:set -DnewVersion=${JAR_TAG} -DprocessAllModules=true" + + } + } + } + + stage('Build XtaTestServer') { + steps { + script { + FAILED_STAGE=env.STAGE_NAME + } + + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS clean install -Dmaven.wagon.http.retryHandler.count=3 -DelasticTests.disabled=true' + } + } + } + + stage('Deploy to Nexus'){ + steps { + script { + FAILED_STAGE = env.STAGE_NAME + } + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS -DskipTests deploy -Dmaven.wagon.http.retryHandler.count=3' + sh "mvn -s $MAVEN_SETTINGS versions:revert" + } + } + } + stage('Build Docker image') { + steps { + script { + FAILED_STAGE=env.STAGE_NAME + } + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn --no-transfer-progress -s $MAVEN_SETTINGS spring-boot:build-image -DskipTests -Dmaven.wagon.http.retryHandler.count=3' + } + } + } + + stage('Tag and Push Docker image') { + steps { + script { + FAILED_STAGE=env.STAGE_NAME + IMAGE_TAG = generateImageTag() + + tagAndPushDockerImage(IMAGE_TAG) + + if (env.BRANCH_NAME == 'master') { + tagAndPushDockerImage('snapshot-latest') + + } + else if (env.BRANCH_NAME == 'release') { + tagAndPushDockerImage('latest') + } + } + } + } + + stage('Test, build and deploy Helm Chart') { + steps { + script { + FAILED_STAGE=env.STAGE_NAME + HELM_CHART_VERSION = generateHelmChartVersion() + + sh "./run_helm_test.sh" + + dir('src/main/helm') { + + sh "helm package --version=${HELM_CHART_VERSION} ." + deployHelmChart(HELM_CHART_VERSION) + } + } + } + } + + + stage('Trigger Dev rollout') { + when { + branch 'master' + } + steps { + script { + FAILED_STAGE = env.STAGE_NAME + + cloneGitopsRepo() + + setNewDevXtaTestServerVersion() + + pushDevGitopsRepo() + } + } + } + stage('Trigger Test rollout') { + when { + branch 'release' + } + + steps { + script { + FAILED_STAGE = env.STAGE_NAME + + cloneGitopsRepo() + + setNewTestXtaTestServerVersion() + + pushTestGitopsRepo() + } + } + } + + stage ('Deploy SBOM to DependencyTrack') { + steps { + script { + IMAGE_TAG = "${env.BRANCH_NAME}-${getPomVersion('pom.xml')}" + + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + withCredentials([string(credentialsId: 'dependency-track-api-key', variable: 'API_KEY')]) { + + catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { + sh "mvn --no-transfer-progress -s $MAVEN_SETTINGS io.github.pmckeown:dependency-track-maven-plugin:upload-bom -Ddependency-track.apiKey=$API_KEY -Ddependency-track.projectVersion=${IMAGE_TAG} -Ddependency-track.dependencyTrackBaseUrl=https://dependency-track.ozg-sh.de" + } + } + } + } + } + } + + stage('Sonar Checks') { + when { + branch 'master' + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + + configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { + try { + withSonarQubeEnv('sonarqube-ozg-sh'){ + sh 'mvn -s $MAVEN_SETTINGS sonar:sonar' + } + } catch (Exception e) { + unstable("SonarQube failed") + } + } + } + } + } + } + + post { + always{ + junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true + } + failure { + script { + if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'release') { + sendFailureMessage() + } + } + } + } +} + + +Boolean isReleaseBranch() { + return env.BRANCH_NAME == 'release' +} + +String getPomVersion(String pomFile){ + def pom = readMavenPom file: pomFile + + return pom.version +} + + +Void sendFailureMessage() { + def room = '' + def data = """{"msgtype":"m.text", \ + "body":"XtaTestServer: Build Failed. Stage: ${FAILED_STAGE} Build-ID: ${env.BUILD_NUMBER} + Link: ${BLUE_OCEAN_URL}", \ + "format": "org.matrix.custom.html", \ + "formatted_body":"XtaTestServer: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <a + href='${BLUE_OCEAN_URL}'>${env.BUILD_NUMBER}</a>"}""" + + if (env.BRANCH_NAME == 'master') { + room = "!GjqhmouBtnDbwUkAjx:matrix.ozg-sh.de" + } + else if (env.BRANCH_NAME == 'release') { + room = "!oWZpUGTFsxkJIYNfYg:matrix.ozg-sh.de" + } + + sh "curl -XPOST -H 'authorization: Bearer ${getElementAccessToken()}' -d '${data}' https://matrix.ozg-sh.de/_matrix/client/v3/rooms/$room/send/m.room.message" +} + +String getElementAccessToken() { + withCredentials([string(credentialsId: 'element-login-json', variable: 'LOGIN_JSON')]) { + return readJSON ( text: sh (script: '''curl -XPOST -d \"$LOGIN_JSON\" https://matrix.ozg-sh.de/_matrix/client/v3/login''', returnStdout: true)).access_token + } +} + +Void deployHelmChart(String helmChartVersion) { + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){ + if (env.BRANCH_NAME == 'release') { + result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps -F file=@xta-test-server-'''+helmChartVersion+'''.tgz''', returnStdout: true + } + else { + result = sh script: '''curl -u $USERNAME:$PASSWORD https://nexus.ozg-sh.de/service/rest/v1/components?repository=ozg-base-apps-snapshot -F file=@xta-test-server-'''+helmChartVersion+'''.tgz''', returnStdout: true + } + + if (result != '') { + error(result) + } + } +} + +Void loginToDockerRepo() { + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { + sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' + } + +} + +String generateHelmChartVersion() { + def chartVersion = getPomVersion('pom.xml') + + if (env.BRANCH_NAME == 'master') { + chartVersion += "-${env.GIT_COMMIT.take(7)}" + } + else if (env.BRANCH_NAME != 'release') { + chartVersion += "-${env.BRANCH_NAME}" + } + + return chartVersion.replaceAll("_", "-") +} + +Void tagAndPushDockerImage(String newTag){ + withCredentials([usernamePassword(credentialsId: 'jenkins-nexus-login', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) { + sh 'docker login docker.ozg-sh.de -u ${USER} -p ${PASSWORD}' + + sh "docker tag docker.ozg-sh.de/xta-test-server:build-latest docker.ozg-sh.de/xta-test-server:${newTag}" + sh "docker push docker.ozg-sh.de/xta-test-server:${newTag}" + } +} + +String generateImageTag() { + def imageTag = "${env.BRANCH_NAME}-${getPomVersion('pom.xml')}" + + if (env.BRANCH_NAME == 'master') { + imageTag += "-${env.GIT_COMMIT.take(7)}" + } + + return imageTag +} + +Void configureGit() { + final email = "jenkins@ozg-sh.de" + final name = "jenkins" + + dir("gitops") { + sh "git config user.email '${email}'" + sh "git config user.name '${name}'" + } +} + +Void cloneGitopsRepo() { + withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { + sh 'git clone https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' + } + + configureGit() +} + +Void setNewDevXtaTestServerVersion() { + setNewXtaTestServerGitopsVersion("dev") +} + +Void setNewTestXtaTestServerVersion() { + setNewXtaTestServerGitopsVersion("test") +} + +Void setNewXtaTestServerGitopsVersion(String environment) { + dir("gitops") { + def envFile = "${environment}/application/values/xta-test-server-values.yaml" + + def envVersions = readYaml file: envFile + + envVersions.xta_test_server.image.tag = IMAGE_TAG + envVersions.xta_test_server.helm.version = HELM_CHART_VERSION + + writeYaml file: envFile, data: envVersions, overwrite: true + } +} + +Void pushDevGitopsRepo() { + pushNewGitopsVersion('dev') +} + +Void pushTestGitopsRepo() { + pushNewGitopsVersion('test') +} + +Void pushNewGitopsVersion(String environment) { + dir('gitops') { + if (!hasXtaTestServerValuesFileChanged(environment)) { + return + } + + withCredentials([usernamePassword(credentialsId: 'jenkins-gitea-access-token', passwordVariable: 'TOKEN', usernameVariable: 'USER')]) { + sh "git add ${environment}/application/values/xta-test-server-values.yaml" + + sh "git commit -m 'jenkins rollout ${environment} aggregation manager version ${IMAGE_TAG}'" + sh 'git push https://${USER}:${TOKEN}@git.ozg-sh.de/ozgcloud-devops/gitops.git' + } + } +} + +Boolean hasXtaTestServerValuesFileChanged(String environment) { + return sh (script: "git status | grep '${environment}/application/values/xta-test-server-values.yaml'", returnStatus: true) == env.SH_SUCCESS_STATUS_CODE as Integer +} + diff --git a/run_helm_test.sh b/run_helm_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..aafe0e7dd324a8e4764fad72362bc2d2039ae197 --- /dev/null +++ b/run_helm_test.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +helm template ./src/main/helm/ -f src/test/helm-linter-values.yaml +helm lint -f src/test/helm-linter-values.yaml ./src/main/helm/ +cd src/main/helm && helm unittest -f '../../test/helm/**/*test.yaml' . + diff --git a/src/main/helm/.helmignore b/src/main/helm/.helmignore new file mode 100644 index 0000000000000000000000000000000000000000..0e8a0eb36f4ca2c939201c0d54b5d82a1ea34778 --- /dev/null +++ b/src/main/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/src/main/helm/Chart.yaml b/src/main/helm/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..57983c6d076cf4a13f2d5689eae2b6b719b8ff28 --- /dev/null +++ b/src/main/helm/Chart.yaml @@ -0,0 +1,30 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +apiVersion: v1 +appVersion: "1.0" +description: OZG-Cloud Helm chart for xta-test-server +name: xta-test-server +version: 0.0.0-MANAGED-BY-JENKINS +icon: https://simpleicons.org/icons/helm.svg diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..3f621195330d4af82088262c265fd131e3549b36 --- /dev/null +++ b/src/main/helm/templates/_helpers.tpl @@ -0,0 +1,93 @@ + +{{/* error check 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec) */}} +{{/* Namespace */}} +{{- define "app.namespace" -}} +{{- if gt (len (.Release.Namespace)) 63 -}} +{{- fail (printf ".Release.Namespace %s ist zu lang (max. 63 Zeichen)" .Release.Namespace) -}} +{{- end -}} +{{ printf "%s" .Release.Namespace }} +{{- end -}} + +{{/* Chart: Name + Version */}} +{{- define "app.chart" -}} +{{- if gt (len (printf "%s-%s" .Chart.Name .Chart.Version)) 63 -}} +{{- fail (printf ".Chart.Name-.Chart.Version %s-%s ist zu lang (max. 63 Zeichen)" .Chart.Name .Chart.Version) -}} +{{- end -}} +{{ printf "%s-%s" .Chart.Name .Chart.Version }} +{{- end -}} + +{{/* Managed-by -> On Helm, this value is always Helm */}} +{{- define "app.managedBy" -}} +{{- if gt (len (.Release.Service)) 63 -}} +{{- fail (printf ".Release.Service %s ist zu lang (max. 63 Zeichen)" .Release.Service) -}} +{{- end -}} +{{ printf "%s" .Release.Service }} +{{- end -}} + + +{{/* Default Labels: Helm recommended best-practice labels https://helm.sh/docs/chart_best_practices/labels/ */}} +{{- define "app.defaultLabels" }} +app.kubernetes.io/instance: xta-test-server +app.kubernetes.io/managed-by: {{ include "app.managedBy" . }} +app.kubernetes.io/name: {{ .Release.Name }} +app.kubernetes.io/namespace: {{ include "app.namespace" . }} +app.kubernetes.io/part-of: ozgcloud +app.kubernetes.io/version: {{ .Chart.Version }} +helm.sh/chart: {{ include "app.chart" . }} +ozgcloud-mongodb-client: "true" +{{- end -}} + +{{- define "app.matchLabels" }} +app.kubernetes.io/name: {{ .Release.Name }} +app.kubernetes.io/namespace: {{ include "app.namespace" . }} +{{- end -}} + + +{{- define "app.envSpringProfiles" }} +{{- if (.Values.env).overrideSpringProfiles -}} +{{ printf "%s" (.Values.env).overrideSpringProfiles }} +{{- else -}} +{{ printf "oc, %s" (include "app.ozgcloudEnvironment" . ) }} +{{- end -}} +{{- end -}} + +{{- define "app.ozgcloudEnvironment" -}} +{{- required "Environment muss angegeben sein" (.Values.ozgcloud).environment -}} +{{- end -}} + +{{- define "app.ozgcloudBezeichner" -}} +{{- required "ozgcloud.bezeichner muss angegeben sein" (.Values.ozgcloud).bezeichner -}} +{{- if lt 46 (len (.Values.ozgcloud).bezeichner) -}} +{{ fail (printf "ozgcloud.bezeichner %s ist zu lang (max. 46 Zeichen)" (.Values.ozgcloud).bezeichner) }} +{{- end -}} +{{- end -}} + +{{- define "app.baseDomain" -}} +{{- printf "%s.%s" (include "app.ozgcloudBezeichner" .) (include "app.baseUrl" .) }} +{{- end -}} + +{{- define "app.baseUrl" -}} +{{- required "baseUrl muss angegeben sein" .Values.baseUrl }} +{{- end -}} + +{{- define "app.serviceAccountName" -}} +{{ printf "%s" ( (.Values.serviceAccount).name | default "xta-test-server-service-account" ) }} +{{- end -}} + +{{- define "app.getCustomList" -}} +{{- with (.Values.env).customList -}} +{{- if kindIs "map" . -}} +{{ include "app.dictToList" . }} +{{- else if kindIs "slice" . -}} +{{ . | toYaml }} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "app.dictToList" -}} +{{- $customList := list -}} +{{- range $key, $value := . -}} +{{- $customList = append $customList (dict "name" $key "value" $value) }} +{{- end -}} +{{- $customList | toYaml -}} +{{- end -}} \ No newline at end of file diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1990efe8a755c1d3b7287f8ff0b28f95a837ce9a --- /dev/null +++ b/src/main/helm/templates/deployment.yaml @@ -0,0 +1,148 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} + namespace: {{ include "app.namespace" . }} + labels: + {{- include "app.defaultLabels" . | indent 4 }} +spec: + progressDeadlineSeconds: 600 + replicas: {{ .Values.replicaCount }} + revisionHistoryLimit: 10 + selector: + matchLabels: + {{- include "app.matchLabels" . | indent 6 }} + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + template: + metadata: + labels: + {{- include "app.defaultLabels" . | indent 8 }} + component: xta-test-server + spec: + {{- if (.Values.serviceAccount).create }} + serviceAccountName: {{ include "app.serviceAccountName" . }} + {{- end }} + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + app.kubernetes.io/name: {{ .Release.Name }} + containers: + - env: + - name: spring_profiles_active + value: {{ include "app.envSpringProfiles" . }} + + {{- with include "app.getCustomList" . }} +{{ . | indent 10 }} + {{- end }} + image: "{{ .Values.image.repo }}/{{ .Values.image.name }}:{{ coalesce (.Values.image).tag "latest" }}" + imagePullPolicy: Always + name: xta-test-server + ports: + - containerPort: 8080 + name: 8080tcp1 + protocol: TCP + - containerPort: 8443 + name: 8443tcp1 + protocol: TCP + - containerPort: 8081 + name: metrics + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /actuator/health/readiness + port: 8081 + scheme: HTTP + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 3 + startupProbe: + httpGet: + path: /actuator/health/readiness + port: 8081 + scheme: HTTP + failureThreshold: 10 + initialDelaySeconds: 30 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + resources: + {{- with .Values.resources }} +{{ toYaml . | indent 10 }} + {{- end }} + securityContext: + allowPrivilegeEscalation: false + privileged: false + readOnlyRootFilesystem: false + runAsNonRoot: true + {{- with (.Values.securityContext).runAsUser }} + runAsUser: {{ . }} + {{- end }} + {{- with (.Values.securityContext).runAsGroup }} + runAsGroup: {{ . }} + {{- end }} + stdin: true + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + tty: true + volumeMounts: + - name: bindings + mountPath: "/bindings/ca-certificates/type" + subPath: type + readOnly: true + - name: mongodb-root-ca + mountPath: "/bindings/ca-certificates/mongodb-root-ca.pem" + subPath: ca.crt + readOnly: true + + volumes: + - name: bindings + configMap: + name: xta-test-server-bindings-type + - name: mongodb-root-ca + secret: + secretName: {{ ((.Values.database).tls).secretName | default "ozg-mongodb-tls-cert" }} + optional: true + dnsConfig: {} + dnsPolicy: ClusterFirst + {{- with .Values.hostAliases }} + hostAliases: +{{ toYaml . | indent 8 }} + {{- end }} + imagePullSecrets: + - name: {{ required "image-pull-secret must be set" .Values.imagePullSecret }} + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 diff --git a/src/main/helm/templates/ingress.yaml b/src/main/helm/templates/ingress.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e029f52a41099e9a1df22d13b7e50489d5bf446f --- /dev/null +++ b/src/main/helm/templates/ingress.yaml @@ -0,0 +1,39 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + namespace: {{ include "app.namespace" . }} + annotations: + {{- if (.Values.ingress).certManagerAnnotations -}} + {{- range (.Values.ingress).certManagerAnnotations }} +{{ . | indent 4 }} + {{- end }} + {{- else if (.Values.ingress).use_staging_cert }} + cert-manager.io/cluster-issuer: letsencrypt-staging + {{- else }} + cert-manager.io/cluster-issuer: letsencrypt-prod + {{- end }} +spec: + {{- if (.Values.ingress).className }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ .Release.Name }} + port: + number: 8443 + + host: {{ include "app.baseDomain" . }} + tls: + - hosts: + - {{ include "app.baseDomain" . }} + {{- if (.Values.ingress).tlsSecretName }} + secretName: {{ (.Values.ingress).tlsSecretName }} + {{- else }} + secretName: {{ .Values.ozgcloud.bezeichner }}-{{ .Release.Name }}-tls + {{- end }} \ No newline at end of file diff --git a/src/main/helm/templates/network_policy.yaml b/src/main/helm/templates/network_policy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8c490c4f1baa31bfd31d00285e868b43d88a8a60 --- /dev/null +++ b/src/main/helm/templates/network_policy.yaml @@ -0,0 +1,56 @@ +{{- if not (.Values.networkPolicy).disabled }} +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: network-policy-xta-test-server + namespace: {{ include "app.namespace" . }} +spec: + podSelector: + matchLabels: + component: xta-test-server + policyTypes: + - Ingress + - Egress + ingress: + - from: + - namespaceSelector: + matchLabels: + name: {{ (.Values.networkPolicy).monitoringNamespace | default "openshift-user-workload-monitoring" }} + ports: + - protocol: TCP + port: 8081 + - from: + - podSelector: + matchLabels: + component: vorgang-manager + ports: + - protocol: TCP + port: 8080 +{{- with (.Values.networkPolicy).additionalIngressConfigLocal }} +{{ toYaml . | indent 2 }} +{{- end }} +{{- with (.Values.networkPolicy).additionalIngressConfigGlobal }} +{{ toYaml . | indent 2 }} +{{- end }} + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: {{ required "networkPolicy.dnsServerNamespace must be set" (.Values.networkPolicy).dnsServerNamespace }} + ports: + - port: 53 + protocol: UDP + - port: 53 + protocol: TCP + - port: 5353 + protocol: UDP + - port: 5353 + protocol: TCP +{{- with (.Values.networkPolicy).additionalEgressConfigLocal }} +{{ toYaml . | indent 2 }} +{{- end }} +{{- with (.Values.networkPolicy).additionalEgressConfigGlobal }} +{{ toYaml . | indent 2 }} +{{- end }} + +{{- end }} \ No newline at end of file diff --git a/src/main/helm/templates/service.yaml b/src/main/helm/templates/service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..71ee6f44c099191537fe898af16479754c3c955e --- /dev/null +++ b/src/main/helm/templates/service.yaml @@ -0,0 +1,46 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} + namespace: {{ include "app.namespace" . }} + labels: + {{- include "app.defaultLabels" . | indent 4 }} + component: xta-test-server-service +spec: + type: ClusterIP + ports: + - name: 8080tcp1 + port: 8080 + protocol: TCP + - name: 8080tcp1 + port: 8443 + protocol: TCP + - name: metrics + port: 8081 + protocol: TCP + selector: + {{- include "app.matchLabels" . | indent 4 }} + component: xta-test-server diff --git a/src/main/helm/templates/service_monitor.yaml b/src/main/helm/templates/service_monitor.yaml new file mode 100644 index 0000000000000000000000000000000000000000..621fe6eb9792999ac798703799575c58bb6f6efd --- /dev/null +++ b/src/main/helm/templates/service_monitor.yaml @@ -0,0 +1,43 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ .Release.Name }} + namespace: {{ include "app.namespace" . }} + labels: + {{- include "app.defaultLabels" . | indent 4 }} + component: xta-test-server-service-monitor +spec: + endpoints: + - port: metrics + path: /actuator/prometheus + namespaceSelector: + matchNames: + - {{ include "app.namespace" . }} + selector: + matchLabels: + {{- include "app.matchLabels" . | indent 6 }} + component: xta-test-server-service \ No newline at end of file diff --git a/src/main/helm/values.yaml b/src/main/helm/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..072e1c91e8bc3c35b8007d0ec3a76c34da6bbe11 --- /dev/null +++ b/src/main/helm/values.yaml @@ -0,0 +1,31 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +replicaCount: 1 + +image: + repo: docker.ozg-sh.de + name: xta-test-server + tag: latest + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index abdee8f2198526d7b8783fa3023dc61194cad49b..908850b0b5804ebe8183d8343b84e94764d53648 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -44,3 +44,25 @@ logging: org.springframework.web: INFO org.apache.cxf: INFO +management: + server: + port: 8081 + health: + livenessState: + enabled: true + readinessState: + enabled: true + endpoint: + health: + group: + exploratory: + include: livenessState,readinessState,ping + show-details: always + probes: + enabled: true + prometheus: + enabled: true + endpoints: + web: + exposure: + include: health,prometheus \ No newline at end of file diff --git a/src/test/helm-linter-values.yaml b/src/test/helm-linter-values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ed41716e50f6c79b8635402fe919e501f622ffe4 --- /dev/null +++ b/src/test/helm-linter-values.yaml @@ -0,0 +1,36 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das +# Ministerium für Energiewende, Klimaschutz, Umwelt und Natur +# Zentrales IT-Management +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. + + +ozgcloud: + bezeichner: helm + environment: dev + +networkPolicy: + dnsServerNamespace: dummy-dns + + +imagePullSecret: image-pull-secret + +baseUrl: dev.xta.de + + \ No newline at end of file diff --git a/src/test/helm/deployment_defaults_labels_test.yaml b/src/test/helm/deployment_defaults_labels_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..75de30f765db02427c6b316526d519fcf0e68824 --- /dev/null +++ b/src/test/helm/deployment_defaults_labels_test.yaml @@ -0,0 +1,72 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: test deployment default labels +release: + name: xta-test-server + namespace: sh-helm-test +templates: + - templates/deployment.yaml +set: + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret +tests: + - it: check metadata.labels + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: xta-test-server + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: sh-helm-test + app.kubernetes.io/part-of: ozgcloud + app.kubernetes.io/version: 0.0.0-MANAGED-BY-JENKINS + helm.sh/chart: xta-test-server-0.0.0-MANAGED-BY-JENKINS + ozgcloud-mongodb-client: "true" + + - it: should set spec.selector.matchLabels + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: sh-helm-test + + + - it: should have correct deyploment spec.template.metadata.labels + asserts: + - equal: + path: spec.template.metadata.labels + value: + app.kubernetes.io/instance: xta-test-server + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: sh-helm-test + app.kubernetes.io/part-of: ozgcloud + app.kubernetes.io/version: 0.0.0-MANAGED-BY-JENKINS + component: xta-test-server + helm.sh/chart: xta-test-server-0.0.0-MANAGED-BY-JENKINS + ozgcloud-mongodb-client: "true" \ No newline at end of file diff --git a/src/test/helm/deployment_env_test.yaml b/src/test/helm/deployment_env_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b3f06bcd3ee12520788e7d2ec98df2814f9bb9ce --- /dev/null +++ b/src/test/helm/deployment_env_test.yaml @@ -0,0 +1,90 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: test deployment container environments +templates: + - templates/deployment.yaml +release: + namespace: sh-helm-test + +tests: + - it: check customList as list + set: + env.customList: + - name: my_test_environment_name + value: "A test value" + - name: test_environment + value: "B test value" + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: my_test_environment_name + value: "A test value" + - contains: + path: spec.template.spec.containers[0].env + content: + name: test_environment + value: "B test value" + - it: check customList as dict + set: + env.customList: + my_test_environment_name: "A test value" + test_environment: "B test value" + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: my_test_environment_name + value: "A test value" + - contains: + path: spec.template.spec.containers[0].env + content: + name: test_environment + value: "B test value" + + - it: check customList test value is not set by default + set: + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: my_test_environment_name + value: "A test value" + + - it: should fail template when env not set + set: + imagePullSecret: image-pull-secret + asserts: + - failedTemplate: + errormessage: Environment muss angegeben sein \ No newline at end of file diff --git a/src/test/helm/deployment_image_pull_secret_test.yaml b/src/test/helm/deployment_image_pull_secret_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e7020bc33e9fb6e0dbcf84dc2105177184175711 --- /dev/null +++ b/src/test/helm/deployment_image_pull_secret_test.yaml @@ -0,0 +1,44 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das +# Ministerium für Energiewende, Klimaschutz, Umwelt und Natur +# Zentrales IT-Management +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. + +suite: deployment image pull secret + +templates: + - templates/deployment.yaml +release: + namespace: helm-test +set: + ozgcloud: + environment: dev +tests: + - it: should set image pull secret + set: + imagePullSecret: image-pull-secret + asserts: + - contains: + path: spec.template.spec.imagePullSecrets + content: + name: image-pull-secret + - it: should fail template when image pull secret not set + asserts: + - failedTemplate: + errormessage: image-pull-secret must be set diff --git a/src/test/helm/deployment_resources_test.yaml b/src/test/helm/deployment_resources_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..df9718fca9cb1b8b30a2767cc42633421873d39e --- /dev/null +++ b/src/test/helm/deployment_resources_test.yaml @@ -0,0 +1,44 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das +# Ministerium für Energiewende, Klimaschutz, Umwelt und Natur +# Zentrales IT-Management +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. + +suite: deployment resources + +templates: + - templates/deployment.yaml +release: + namespace: helm-test +set: + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret +tests: + - it: should have customizable resources + set: + resources: { "test": 1 } + asserts: + - equal: + path: spec.template.spec.containers[0].resources + value: { "test": 1 } + - it: should not generate resources when values not set + asserts: + - isEmpty: + path: spec.template.spec.containers[0].resources \ No newline at end of file diff --git a/src/test/helm/deployment_service_account.yaml b/src/test/helm/deployment_service_account.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bc7d3d4643b4f9e100f27d942e0dc9461cd860f1 --- /dev/null +++ b/src/test/helm/deployment_service_account.yaml @@ -0,0 +1,30 @@ +suite: deployment service account +release: + name: xta-test-server + namespace: by-helm-test +templates: + - templates/deployment.yaml +set: + imagePullSecret: test-image-pull-secret +tests: + - it: should use service account with default name + set: + serviceAccount: + create: true + asserts: + - equal: + path: spec.template.spec.serviceAccountName + value: xta-test-server-service-account + - it: should use service account with name + set: + serviceAccount: + create: true + name: helm-service-account + asserts: + - equal: + path: spec.template.spec.serviceAccountName + value: helm-service-account + - it: should use default service account + asserts: + - isNull: + path: spec.template.spec.serviceAccountName \ No newline at end of file diff --git a/src/test/helm/deployment_spring_profile_test.yaml b/src/test/helm/deployment_spring_profile_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5d76c9d42e2ff9cc9731d0fa88fbc38281d31084 --- /dev/null +++ b/src/test/helm/deployment_spring_profile_test.yaml @@ -0,0 +1,50 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: deployment springProfile tests +release: + namespace: sh-helm-test +templates: + - templates/deployment.yaml +set: + ozgcloud: + environment: dev + imagePullSecret: image-pull-secret +tests: + - it: should override the spring profiles + set: + env.overrideSpringProfiles: oc,dev,ea + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: spring_profiles_active + value: oc,dev,ea + - it: should generate the spring profiles + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: spring_profiles_active + value: oc, dev diff --git a/src/test/helm/deployment_test.yaml b/src/test/helm/deployment_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..124a4b85efb19405a345bccd81c4a4b724a23c92 --- /dev/null +++ b/src/test/helm/deployment_test.yaml @@ -0,0 +1,237 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: deployment +release: + name: xta-test-server +templates: + - templates/deployment.yaml +set: + ozgcloud: + environment: "default" + imagePullSecret: image-pull-secret +tests: + - it: should have metadata values + asserts: + - isKind: + of: Deployment + - isAPIVersion: + of: apps/v1 + - equal: + path: metadata.name + value: "xta-test-server" + - equal: + path: metadata.namespace + value: "NAMESPACE" + - exists: + path: metadata.labels + - it: should have correct general settings + asserts: + - equal: + path: spec.progressDeadlineSeconds + value: 600 + - equal: + path: spec.replicas + value: 1 + - equal: + path: spec.revisionHistoryLimit + value: 10 + - exists: + path: spec.selector + - equal: + path: spec.selector.matchLabels["app.kubernetes.io/name"] + value: "xta-test-server" + - equal: + path: spec.selector.matchLabels["app.kubernetes.io/namespace"] + value: "NAMESPACE" + - equal: + path: spec.strategy.rollingUpdate.maxSurge + value: 1 + - equal: + path: spec.strategy.rollingUpdate.maxUnavailable + value: 0 + - equal: + path: spec.strategy.type + value: "RollingUpdate" + - it: should have correct template configuration + asserts: + - equal: + path: spec.template.metadata.labels["app.kubernetes.io/instance"] + value: "xta-test-server" + - equal: + path: spec.template.metadata.labels.component + value: "xta-test-server" + - equal: + path: metadata.labels["ozgcloud-mongodb-client"] + value: "true" + - equal: + path: spec.template.spec.topologySpreadConstraints[0].maxSkew + value: 1 + - equal: + path: spec.template.spec.topologySpreadConstraints[0].topologyKey + value: "kubernetes.io/hostname" + - equal: + path: spec.template.spec.topologySpreadConstraints[0].whenUnsatisfiable + value: "ScheduleAnyway" + - equal: + path: spec.template.spec.topologySpreadConstraints[0].labelSelector.matchLabels["app.kubernetes.io/name"] + value: "xta-test-server" + - isEmpty: + path: spec.template.spec.dnsConfig + - equal: + path: spec.template.spec.dnsPolicy + value: "ClusterFirst" + - equal: + path: spec.template.spec.restartPolicy + value: "Always" + - equal: + path: spec.template.spec.schedulerName + value: "default-scheduler" + - isEmpty: + path: spec.template.spec.securityContext + - equal: + path: spec.template.spec.terminationGracePeriodSeconds + value: 30 + - it: should have correct container configuration + asserts: + - equal: + path: spec.template.spec.containers[0].name + value: "xta-test-server" + - equal: + path: spec.template.spec.containers[0].image + value: "docker.ozg-sh.de/xta-test-server:latest" + - equal: + path: spec.template.spec.containers[0].imagePullPolicy + value: "Always" + - equal: + path: spec.template.spec.containers[0].ports[0].containerPort + value: 8080 + - equal: + path: spec.template.spec.containers[0].ports[0].name + value: "8080tcp1" + - equal: + path: spec.template.spec.containers[0].ports[0].protocol + value: "TCP" + - equal: + path: spec.template.spec.containers[0].ports[1].containerPort + value: 8443 + - equal: + path: spec.template.spec.containers[0].ports[1].name + value: "8443tcp1" + - equal: + path: spec.template.spec.containers[0].ports[1].protocol + value: "TCP" + - equal: + path: spec.template.spec.containers[0].ports[2].containerPort + value: 8081 + - equal: + path: spec.template.spec.containers[0].ports[2].name + value: "metrics" + - equal: + path: spec.template.spec.containers[0].ports[2].protocol + value: "TCP" + - equal: + path: spec.template.spec.containers[0].readinessProbe.failureThreshold + value: 3 + - equal: + path: spec.template.spec.containers[0].readinessProbe.httpGet.path + value: "/actuator/health/readiness" + - equal: + path: spec.template.spec.containers[0].readinessProbe.httpGet.port + value: 8081 + - equal: + path: spec.template.spec.containers[0].readinessProbe.httpGet.scheme + value: "HTTP" + - equal: + path: spec.template.spec.containers[0].readinessProbe.periodSeconds + value: 10 + - equal: + path: spec.template.spec.containers[0].readinessProbe.successThreshold + value: 1 + - equal: + path: spec.template.spec.containers[0].readinessProbe.timeoutSeconds + value: 3 + - equal: + path: spec.template.spec.containers[0].startupProbe.httpGet.path + value: "/actuator/health/readiness" + - equal: + path: spec.template.spec.containers[0].startupProbe.httpGet.port + value: 8081 + - equal: + path: spec.template.spec.containers[0].startupProbe.failureThreshold + value: 10 + - equal: + path: spec.template.spec.containers[0].startupProbe.initialDelaySeconds + value: 30 + - equal: + path: spec.template.spec.containers[0].startupProbe.periodSeconds + value: 10 + - equal: + path: spec.template.spec.containers[0].startupProbe.successThreshold + value: 1 + - equal: + path: spec.template.spec.containers[0].startupProbe.timeoutSeconds + value: 5 + - equal: + path: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation + value: false + - equal: + path: spec.template.spec.containers[0].securityContext.privileged + value: false + - equal: + path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem + value: false + - equal: + path: spec.template.spec.containers[0].securityContext.runAsNonRoot + value: true + - isNull: + path: spec.template.spec.containers[0].securityContext.runAsUser + - isNull: + path: spec.template.spec.containers[0].securityContext.runAsGroup + - equal: + path: spec.template.spec.containers[0].stdin + value: true + - equal: + path: spec.template.spec.containers[0].terminationMessagePath + value: "/dev/termination-log" + - equal: + path: spec.template.spec.containers[0].terminationMessagePolicy + value: "File" + - equal: + path: spec.template.spec.containers[0].tty + value: true + - it: check containers runAsUser + set: + securityContext.runAsUser: 1000 + asserts: + - equal: + path: spec.template.spec.containers[0].securityContext.runAsUser + value: 1000 + - it: check runAsGroup + set: + securityContext.runAsGroup: 1000 + asserts: + - equal: + path: spec.template.spec.containers[0].securityContext.runAsGroup + value: 1000 \ No newline at end of file diff --git a/src/test/helm/ingress_test.yaml b/src/test/helm/ingress_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e25af97ccb17497a93dc167175386699dcb08c5b --- /dev/null +++ b/src/test/helm/ingress_test.yaml @@ -0,0 +1,113 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: test ingress.yaml +release: + name: matabase + namespace: sh-helm-test +templates: + - templates/ingress.yaml +set: + ozgcloud: + bezeichner: helm + baseUrl: test.by.ozg-cloud.de + +tests: + - it: check ingress kind + asserts: + - isKind: + of: Ingress + - it: should create default ingress tls + asserts: + - equal: + path: spec.tls[0].secretName + value: helm-matabase-tls + - it: should set ingress tls + set: + ingress: + tlsSecretName: client-tls + asserts: + - equal: + path: spec.tls[0].secretName + value: client-tls + + - it: should not create ingress tls/ingressClass by default + asserts: + - isNull: + path: spec.ingressClassName + - it: should set ingress tls/ingressClass + set: + ingress: + className: ingress + asserts: + - equal: + path: spec.ingressClassName + value: ingress + + - it: should use default letsencrypt-prod cluster-issuer + asserts: + - equal: + path: metadata.annotations["cert-manager.io/cluster-issuer"] + value: letsencrypt-prod + + - it: should use letsencrypt-staging cluster-issuer + set: + ingress.use_staging_cert: true + asserts: + - equal: + path: metadata.annotations["cert-manager.io/cluster-issuer"] + value: letsencrypt-staging + + - it: should use letsencrypt-prod cluster-issuer + set: + ingress.use_staging_cert: false + asserts: + - equal: + path: metadata.annotations["cert-manager.io/cluster-issuer"] + value: letsencrypt-prod + + - it: should create tls hosts name correctly + asserts: + - equal: + path: spec.tls[0].hosts[0] + value: helm.test.by.ozg-cloud.de + + - it: should create rules correctly + asserts: + - equal: + path: spec.rules[0].http.paths[0] + value: + path: / + pathType: Prefix + backend: + service: + name: matabase + port: + number: 8443 + + - it: should set hostname + asserts: + - equal: + path: spec.rules[0].host + value: helm.test.by.ozg-cloud.de diff --git a/src/test/helm/network_policy_test.yaml b/src/test/helm/network_policy_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ff25d1850ac14fcf073efcf34ee88b08cd43ba72 --- /dev/null +++ b/src/test/helm/network_policy_test.yaml @@ -0,0 +1,239 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: network policy xta-test-server test +release: + name: xta-test-server + namespace: by-helm-test +templates: + - templates/network_policy.yaml + +tests: + - it: should match apiVersion + set: + networkPolicy: + dnsServerNamespace: kube-system + asserts: + - isAPIVersion: + of: networking.k8s.io/v1 + - it: should match kind + set: + networkPolicy: + dnsServerNamespace: kube-system + asserts: + - isKind: + of: NetworkPolicy + - it: validate metadata + set: + networkPolicy: + dnsServerNamespace: kube-system + asserts: + - equal: + path: metadata + value: + name: network-policy-xta-test-server + namespace: by-helm-test + - it: validate spec + set: + networkPolicy: + dnsServerNamespace: kube-system + asserts: + - equal: + path: spec + value: + egress: + - ports: + - port: 53 + protocol: UDP + - port: 53 + protocol: TCP + - port: 5353 + protocol: UDP + - port: 5353 + protocol: TCP + to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + ingress: + - from: + - namespaceSelector: + matchLabels: + name: openshift-user-workload-monitoring + ports: + - port: 8081 + protocol: TCP + - from: + - podSelector: + matchLabels: + component: vorgang-manager + ports: + - port: 8080 + protocol: TCP + podSelector: + matchLabels: + component: xta-test-server + policyTypes: + - Ingress + - Egress + + + - it: add ingress rule by values local + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + additionalIngressConfigLocal: + - from: + - podSelector: + matchLabels: + component: client2 + asserts: + - contains: + path: spec.ingress + content: + from: + - podSelector: + matchLabels: + component: client2 + + - it: set ingress monitoring namespace rule + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + monitoringNamespace: monitoring + asserts: + - contains: + path: spec.ingress + content: + from: + - namespaceSelector: + matchLabels: + name: "monitoring" + ports: + - protocol: TCP + port: 8081 + - it: add ingress rule by values global + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + additionalIngressConfigGlobal: + - from: + - podSelector: + matchLabels: + component: client2 + asserts: + - contains: + path: spec.ingress + content: + from: + - podSelector: + matchLabels: + component: client2 + + - it: add ingress rule by values global + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + additionalIngressConfigGlobal: + - from: + - podSelector: + matchLabels: + component: client2 + asserts: + - contains: + path: spec.ingress + content: + from: + - podSelector: + matchLabels: + component: client2 + + + - it: add egress rule by values local + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + additionalIngressConfigLocal: + - to: + - podSelector: + matchLabels: + component: client2 + asserts: + - contains: + path: spec.ingress + content: + to: + - podSelector: + matchLabels: + component: client2 + + - it: add egress rule by values global + set: + networkPolicy: + dnsServerNamespace: test-namespace-dns + additionalIngressConfigGlobal: + - to: + - podSelector: + matchLabels: + component: client2 + asserts: + - contains: + path: spec.ingress + content: + to: + - podSelector: + matchLabels: + component: client2 + + - it: test network policy disabled + set: + networkPolicy: + disabled: true + asserts: + - hasDocuments: + count: 0 + + - it: test network policy unset should be disabled + set: + networkPolicy: + disabled: false + dnsServerNamespace: test-dns-server-namespace + asserts: + - hasDocuments: + count: 1 + - it: test network policy dnsServerNamespace must be set message + set: + networkPolicy: + disabled: false + asserts: + - failedTemplate: + errorMessage: networkPolicy.dnsServerNamespace must be set + + - it: test network policy should be enabled by default + set: + networkPolicy: + dnsServerNamespace: test-dns-server-namespace + asserts: + - hasDocuments: + count: 1 \ No newline at end of file diff --git a/src/test/helm/service_monitor_test.yaml b/src/test/helm/service_monitor_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..15724821da4732a741d6cb688f59210e7dfa2daf --- /dev/null +++ b/src/test/helm/service_monitor_test.yaml @@ -0,0 +1,84 @@ +# +# Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den +# Ministerpräsidenten des Landes Schleswig-Holstein +# Staatskanzlei +# Abteilung Digitalisierung und zentrales IT-Management der Landesregierung +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. +# + +suite: test service_monitor +release: + name: xta-test-server + namespace: sh-helm-test +templates: + - templates/service_monitor.yaml +tests: + - it: should have basic info and the label component with value xta-test-server-service-monitor attached + asserts: + - isKind: + of: ServiceMonitor + - isAPIVersion: + of: monitoring.coreos.com/v1 + - equal: + path: metadata.name + value: xta-test-server + - equal: + path: metadata.namespace + value: sh-helm-test + - equal: + path: metadata.labels["component"] + value: xta-test-server-service-monitor + + - it: should contain default lables and component lables + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: xta-test-server + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: sh-helm-test + app.kubernetes.io/part-of: ozgcloud + app.kubernetes.io/version: 0.0.0-MANAGED-BY-JENKINS + component: xta-test-server-service-monitor + helm.sh/chart: xta-test-server-0.0.0-MANAGED-BY-JENKINS + ozgcloud-mongodb-client: "true" + + - it: should have the metrics endpoint configured by default + asserts: + - contains: + path: spec.endpoints + content: + port: metrics + path: /actuator/prometheus + + - it: namespace selector should contain the namespace + asserts: + - contains: + path: spec.namespaceSelector.matchNames + content: sh-helm-test + + - it: selector should contain helm recommended labels name and namespace + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: sh-helm-test + component: xta-test-server-service diff --git a/src/test/helm/service_test.yaml b/src/test/helm/service_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ff1b3b40deacef2be8a9565fcf6c94c3823220d6 --- /dev/null +++ b/src/test/helm/service_test.yaml @@ -0,0 +1,96 @@ +# +# Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das +# Ministerium für Energiewende, Klimaschutz, Umwelt und Natur +# Zentrales IT-Management +# +# Lizenziert unter der EUPL, Version 1.2 oder - sobald +# diese von der Europäischen Kommission genehmigt wurden - +# Folgeversionen der EUPL ("Lizenz"); +# Sie dürfen dieses Werk ausschließlich gemäß +# dieser Lizenz nutzen. +# Eine Kopie der Lizenz finden Sie hier: +# +# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 +# +# Sofern nicht durch anwendbare Rechtsvorschriften +# gefordert oder in schriftlicher Form vereinbart, wird +# die unter der Lizenz verbreitete Software "so wie sie +# ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - +# ausdrücklich oder stillschweigend - verbreitet. +# Die sprachspezifischen Genehmigungen und Beschränkungen +# unter der Lizenz sind dem Lizenztext zu entnehmen. + +suite: service + +templates: + - templates/service.yaml +release: + name: xta-test-server + namespace: helm-test + +tests: + - it: has expected document values + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: xta-test-server + namespace: helm-test + - it: should be of type ClusterIP + asserts: + - equal: + path: spec.type + value: ClusterIP + - it: has http port 8080 + asserts: + - contains: + path: spec.ports + content: + name: 8080tcp1 + port: 8080 + protocol: TCP + + - it: has http port 8443 + asserts: + - contains: + path: spec.ports + content: + name: 8080tcp1 + port: 8443 + protocol: TCP + + - it: has metrics port + asserts: + - contains: + path: spec.ports + content: + name: metrics + port: 8081 + protocol: TCP + - it: should contain helm recommended labels name and namespace + asserts: + - equal: + path: spec.selector["app.kubernetes.io/name"] + value: xta-test-server + - equal: + path: spec.selector["app.kubernetes.io/namespace"] + value: helm-test + - it: has selector component + asserts: + - equal: + path: spec.selector.component + value: xta-test-server + - it: should contain default lables and component lables + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: xta-test-server + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: xta-test-server + app.kubernetes.io/namespace: helm-test + app.kubernetes.io/part-of: ozgcloud + app.kubernetes.io/version: 0.0.0-MANAGED-BY-JENKINS + component: xta-test-server-service + helm.sh/chart: xta-test-server-0.0.0-MANAGED-BY-JENKINS + ozgcloud-mongodb-client: "true" \ No newline at end of file