Skip to content

Commit

Permalink
Merge branch 'release/v3.3.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
meiserloh authored and cesmarvin committed Jan 30, 2025
2 parents 39e4a68 + 147c3ca commit d5f7261
Show file tree
Hide file tree
Showing 21 changed files with 331 additions and 194 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v3.3.1] - 2025-01-30
### Fixed
- [#132] Resource patches can now patch values of any type

## [v3.3.0] - 2025-01-27
### Added
- [#128] Proxy support for dogu, container and helm registry.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.23.2 AS builder
FROM golang:1.23.5 AS builder

WORKDIR /workspace

Expand Down Expand Up @@ -30,7 +30,7 @@ RUN make compile-generic
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="[email protected]" \
NAME="k8s-ces-setup" \
VERSION="3.3.0"
VERSION="3.3.1"

WORKDIR /

Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gitflow = new GitFlow(this, gitWrapper)
github = new GitHub(this, gitWrapper)
changelog = new Changelog(this)
Docker docker = new Docker(this)
goVersion = "1.23"
goVersion = "1.23.5"
Makefile makefile = new Makefile(this)

// Configuration of repository
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Set these to the desired values
ARTIFACT_ID=k8s-ces-setup
VERSION=3.3.0
VERSION=3.3.1

GOTAG?=1.23.2
MAKEFILES_VERSION=9.3.2
GOTAG?=1.23.5
MAKEFILES_VERSION=9.5.3

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
Expand Down
2 changes: 1 addition & 1 deletion app/patch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type JsonPatch struct {
// If keys contain '/' or '~', those characters have to be replaced with '~1' and '~0' respectively.
Path string `yaml:"path" json:"path"`
// Value contains the value that should be inserted at the specified path.
Value map[string]interface{} `yaml:"value,omitempty" json:"value,omitempty"`
Value any `yaml:"value,omitempty" json:"value,omitempty"`
}

// Validate checks the JsonPatch for errors.
Expand Down
93 changes: 91 additions & 2 deletions app/patch/config_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package patch

import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/assert"

"k8s.io/apimachinery/pkg/runtime/schema"
"testing"
)

func TestResourceReference_GroupVersionKind(t *testing.T) {
Expand Down Expand Up @@ -49,11 +53,96 @@ func TestResourceReference_GroupVersionKind(t *testing.T) {
})
}

func TestJsonPatch_unmarshalling(t *testing.T) {
tests := []struct {
jsonRepresentation []byte
objectRepresentation JsonPatch
}{
{
jsonRepresentation: []byte(`{}`),
objectRepresentation: JsonPatch{},
},
{
jsonRepresentation: []byte(`{"op": "add", "path": "/metadata/labels", "value": {"foo": "bar"}}`),
objectRepresentation: JsonPatch{
Operation: "add",
Path: "/metadata/labels",
Value: map[string]interface{}{"foo": "bar"},
},
},
{
jsonRepresentation: []byte(`{"op": "add", "path": "/spec/loadBalancerIP", "value": "203.0.113.55"}`),
objectRepresentation: JsonPatch{
Operation: "add",
Path: "/spec/loadBalancerIP",
Value: "203.0.113.55",
},
},
{
jsonRepresentation: []byte(`{"op": "remove", "path": "/spec/loadBalancerIP"}`),
objectRepresentation: JsonPatch{
Operation: "remove",
Path: "/spec/loadBalancerIP",
},
},
}
for _, tt := range tests {
t.Run(string(tt.jsonRepresentation), func(t *testing.T) {
var actual JsonPatch
err := json.Unmarshal(tt.jsonRepresentation, &actual)
require.NoError(t, err)
assert.Equal(t, tt.objectRepresentation, actual)
})
}
}

func TestJsonPatch_marshalling(t *testing.T) {
tests := []struct {
jsonRepresentation []byte
objectRepresentation JsonPatch
}{
{
jsonRepresentation: []byte(`{"op":"","path":""}`),
objectRepresentation: JsonPatch{},
},
{
jsonRepresentation: []byte(`{"op":"add","path":"/metadata/labels","value":{"foo":"bar"}}`),
objectRepresentation: JsonPatch{
Operation: "add",
Path: "/metadata/labels",
Value: map[string]interface{}{"foo": "bar"},
},
},
{
jsonRepresentation: []byte(`{"op":"add","path":"/spec/loadBalancerIP","value":"203.0.113.55"}`),
objectRepresentation: JsonPatch{
Operation: "add",
Path: "/spec/loadBalancerIP",
Value: "203.0.113.55",
},
},
{
jsonRepresentation: []byte(`{"op":"remove","path":"/spec/loadBalancerIP"}`),
objectRepresentation: JsonPatch{
Operation: "remove",
Path: "/spec/loadBalancerIP",
},
},
}
for _, tt := range tests {
t.Run(string(tt.jsonRepresentation), func(t *testing.T) {
actual, err := json.Marshal(tt.objectRepresentation)
require.NoError(t, err)
assert.Equal(t, tt.jsonRepresentation, actual)
})
}
}

func TestJsonPatch_Validate(t *testing.T) {
type fields struct {
Operation JsonPatchOperation
Path string
Value map[string]interface{}
Value interface{}
}
tests := []struct {
name string
Expand Down
4 changes: 2 additions & 2 deletions app/patch/mock_jsonPatchApplier_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/make/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ K3S_LOCAL_REGISTRY_PORT?=30099

# The URL of the container-registry to use. Defaults to the registry of the local-cluster.
# If RUNTIME_ENV is "remote" it is "registry.cloudogu.com/testing"
CES_REGISTRY_HOST?="${K3S_CLUSTER_FQDN}:${K3S_LOCAL_REGISTRY_PORT}"
CES_REGISTRY_HOST?=${K3S_CLUSTER_FQDN}:${K3S_LOCAL_REGISTRY_PORT}
CES_REGISTRY_NAMESPACE ?=
ifeq (${RUNTIME_ENV}, remote)
CES_REGISTRY_HOST="registry.cloudogu.com"
CES_REGISTRY_NAMESPACE="/testing"
CES_REGISTRY_HOST=registry.cloudogu.com
CES_REGISTRY_NAMESPACE=/testing
endif
$(info CES_REGISTRY_HOST=$(CES_REGISTRY_HOST))

Expand Down
6 changes: 6 additions & 0 deletions build/make/prerelease.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# used to create switch the dogu to a prerelease namespace
# e.g. official/usermgmt -> prerelease_official/usermgmt

.PHONY: prerelease_namespace
prerelease_namespace:
build/make/prerelease.sh prerelease_namespace
41 changes: 41 additions & 0 deletions build/make/prerelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail

prerelease_namespace() {

TIMESTAMP=$(date +"%Y%m%d%H%M%S")

# Update version in dogu.json
if [ -f "dogu.json" ]; then
echo "Updating name in dogu.json..."
ORIG_NAME="$(jq -r ".Name" ./dogu.json)"
ORIG_VERSION="$(jq -r ".Version" ./dogu.json)"
PRERELEASE_NAME="prerelease_${ORIG_NAME}"
PRERELEASE_VERSION="${ORIG_VERSION}${TIMESTAMP}"
jq ".Name = \"${PRERELEASE_NAME}\"" dogu.json >dogu2.json && mv dogu2.json dogu.json
jq ".Version = \"${PRERELEASE_VERSION}\"" dogu.json >dogu2.json && mv dogu2.json dogu.json
jq ".Image = \"registry.cloudogu.com/${PRERELEASE_NAME}\"" dogu.json >dogu2.json && mv dogu2.json dogu.json
fi

# Update version in Dockerfile
if [ -f "Dockerfile" ]; then
echo "Updating version in Dockerfile..."
ORIG_NAME="$(grep -oP ".*[ ]*NAME=\"([^\"]*)" Dockerfile | awk -F "\"" '{print $2}')"
ORIG_VERSION="$(grep -oP ".*[ ]*VERSION=\"([^\"]*)" Dockerfile | awk -F "\"" '{print $2}')"
PRERELEASE_NAME="prerelease_$( echo -e "$ORIG_NAME" | sed 's/\//\\\//g' )"
PRERELEASE_VERSION="${ORIG_VERSION}${TIMESTAMP}"
sed -i "s/\(.*[ ]*NAME=\"\)\([^\"]*\)\(.*$\)/\1${PRERELEASE_NAME}\3/" Dockerfile
sed -i "s/\(.*[ ]*VERSION=\"\)\([^\"]*\)\(.*$\)/\1${PRERELEASE_VERSION}\3/" Dockerfile
fi

}


TYPE="${1}"

echo ${TYPE}
if [[ "${TYPE}" == "prerelease_namespace" ]];then
prerelease_namespace
fi
2 changes: 1 addition & 1 deletion build/make/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.PHONY: dogu-release
dogu-release: ## Start a dogu release
build/make/release.sh dogu
build/make/release.sh dogu "${FIXED_CVE_LIST}" $(DRY_RUN)

.PHONY: node-release
node-release: ## Start a node package release
Expand Down
1 change: 1 addition & 0 deletions build/make/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fi

update_versions "${NEW_RELEASE_VERSION}"
update_changelog "${NEW_RELEASE_VERSION}" "${FIXED_CVE_LIST}"
update_releasenotes "${NEW_RELEASE_VERSION}"
show_diff

if [[ -n "${DRY_RUN}" ]]; then
Expand Down
44 changes: 44 additions & 0 deletions build/make/release_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,50 @@ update_changelog() {
git commit -m "Update changelog"
}

update_releasenotes() {
local NEW_RELEASE_VERSION="${1}"

# ReleaseNotes update
local CURRENT_DATE
CURRENT_DATE=$(date --rfc-3339=date)
local NEW_RELEASENOTE_TITLE="## [v${NEW_RELEASE_VERSION}] - ${CURRENT_DATE}"
rm -rf ".rn_changed"
find . -name "*release_notes*.md" -print0 | while read -d $'\0' file
do
# Check if "Unreleased" tag exists
while ! grep --silent "## \[Unreleased\]" "${file}"; do
echo ""
echo -e "\e[31mYour ${file} does not contain a \"## [Unreleased]\" line!\e[0m"
echo "Please add one to make it comply to https://keepachangelog.com/en/1.0.0/"
wait_for_ok "Please insert a \"## [Unreleased]\" line into ${file} now."
done

# Add new title line to changelog
sed -i "s|## \[Unreleased\]|## \[Unreleased\]\n\n${NEW_RELEASENOTE_TITLE}|g" "${file}"
echo "Processed ${file}"
echo true > ".rn_changed"
done

if test -f ".rn_changed" ; then
# Wait for user to validate changelog changes
wait_for_ok "Please make sure your release notes looks as desired."

find . -name "*release_notes*.md" -print0 | while read -d $'\0' file
do
# Check if new version tag still exists
while ! grep --silent "$(echo $NEW_RELEASENOTE_TITLE | sed -e 's/[]\/$*.^[]/\\&/g')" "${file}"; do
echo ""
echo -e "\e[31mYour ${file} does not contain \"${NEW_RELEASENOTE_TITLE}\"!\e[0m"
wait_for_ok "Please update your ${file} now."
done
git add "${file}"
done

git commit -m "Update ReleaseNotes"
fi
rm -rf ".rn_changed"
}

# addFixedCVEListFromReRelease is used in dogu cve releases. The method adds the fixed CVEs under the ### Fixed header
# in the unreleased section.
addFixedCVEListFromReRelease() {
Expand Down
7 changes: 6 additions & 1 deletion build/make/self-update.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ remove-old-files:

.PHONY: copy-new-files
copy-new-files:
@cp -r $(TMP_DIR)/makefiles-$(MAKEFILES_VERSION)/build/make $(BUILD_DIR)
@cp -r $(TMP_DIR)/makefiles-$(MAKEFILES_VERSION)/build/make $(BUILD_DIR)

.PHONY: update-build-libs
update-build-libs:
@echo "Check for newer Build-Lib versions"
build/make/self-update.sh buildlibs
48 changes: 48 additions & 0 deletions build/make/self-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail

TYPE="${1}"

update_build_libs() {
echo "Get newest version of ces-build-lib and dogu-build-lib"
update_jenkinsfile
echo "Newest Versions set. Please check your Jenkinsfile"
}

get_highest_version() {
local target="${1}"
local gitCesBuildLib
# getting tags from ces-build.libs OR dogu-build-libs
gitCesBuildLib="$(git ls-remote --tags --refs https://github.com/cloudogu/${target}-build-lib)"
local highest
# Flagfile for getting results out of while-loop
rm -rf .versions
while IFS= read -r line; do
local version
version="$(awk -F'/tags/' '{ for(i=1;i<=NF;i++) print $i }' <<< $line | tail -n 1 | sed 's/[^0-9\.]*//g')"
if [[ $version == *"."* ]] ; then
echo $version >> ".versions"
fi
done <<< "$gitCesBuildLib"
highest=$(sort .versions | tail -n 1)
rm -rf .versions
echo "${highest}"
}

# Patch Jenkinsfile
update_jenkinsfile() {
sed -i "s/ces-build-lib@[[:digit:]].[[:digit:]].[[:digit:]]/ces-build-lib@$(get_highest_version ces)/g" Jenkinsfile
sed -i "s/dogu-build-lib@v[[:digit:]].[[:digit:]].[[:digit:]]/dogu-build-lib@v$(get_highest_version dogu)/g" Jenkinsfile
}

# switch for script entrypoint
if [[ "${TYPE}" == "buildlibs" ]];then
update_build_libs
else
echo "Unknown target ${TYPE}"
fi



4 changes: 2 additions & 2 deletions build/make/test-common.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GO_JUNIT_REPORT=$(UTILITY_BIN_PATH)/go-junit-report
GO_JUNIT_REPORT_VERSION=v1.0.0
GO_JUNIT_REPORT_VERSION=v2.1.0

$(GO_JUNIT_REPORT): $(UTILITY_BIN_PATH)
@echo "Download go-junit-report..."
@$(call go-get-tool,$@,github.com/jstemmer/go-junit-report@$(GO_JUNIT_REPORT_VERSION))
@$(call go-get-tool,$@,github.com/jstemmer/go-junit-report/v2@$(GO_JUNIT_REPORT_VERSION))
Loading

0 comments on commit d5f7261

Please sign in to comment.