diff --git a/.ci/hack/component_descriptor b/.ci/hack/component_descriptor new file mode 100755 index 00000000..acc328c8 --- /dev/null +++ b/.ci/hack/component_descriptor @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# Configuration Options: +# +# COMPONENT_PREFIXES: Set the image prefix that should be used to +# determine if an image is defined by another component. +# Defaults to "eu.gcr.io/gardener-project/gardener,europe-docker.pkg.dev/gardener-project" +# +# COMPONENT_CLI_ARGS: Set all component-cli arguments. +# This should be used with care as all defaults are overwritten. +# + +set -e + +repo_root_dir="$1" +repo_name="${2:-github.com/gardener/gardener}" +descriptor_out_file="${COMPONENT_DESCRIPTOR_PATH}" + +resources_file="$repo_root_dir/.ci/resources.yaml" +if [[ -f ${resources_file} ]]; then + echo "Adding additional resources from ${resources_file}" + + # component-cli expects a directory where the component descriptor file is named component-descriptor.yaml. + # however the pre-rendered component descriptors of the pipeline have different filenames. + # therefore create a tempdir and copy the pre-rendered component descriptor to it with the correct filename. + tmp_dir="$(mktemp -d)" + tmp_cd="${tmp_dir}/component-descriptor.yaml" + cp "${BASE_DEFINITION_PATH}" "${tmp_cd}" + echo "${tmp_cd}" + + # read the component version. + if [[ -z ${EFFECTIVE_VERSION} ]]; then + echo "The env variable EFFECTIVE_VERSION must be set" + exit 1 + fi + + # adds all resources defined in the resources file to the component descriptor. + component-cli component-archive resources add ${tmp_dir} ${resources_file} -v=3 -- COMPONENT_VERSION=${EFFECTIVE_VERSION} + + # move modified component descriptor back to the original file. + mv "${tmp_cd}" "${BASE_DEFINITION_PATH}" +else + echo "Resources file ${resources_file} not found. Skip adding additional resources." +fi + +echo "Enriching component descriptor from ${BASE_DEFINITION_PATH}" + +image_vector_path="" +if [[ -f "$repo_root_dir/charts/images.yaml" ]]; then + image_vector_path="$repo_root_dir/charts/images.yaml" +elif [[ -f "$repo_root_dir/imagevector/images.yaml" ]]; then + image_vector_path="$repo_root_dir/imagevector/images.yaml" +fi + +if [[ ! -z "$image_vector_path" ]]; then + # default environment variables + if [[ -z "${COMPONENT_PREFIXES}" ]]; then + COMPONENT_PREFIXES="eu.gcr.io/gardener-project/gardener,europe-docker.pkg.dev/gardener-project" + fi + + if [[ -z "${COMPONENT_CLI_ARGS}" ]]; then + COMPONENT_CLI_ARGS=" + --comp-desc ${BASE_DEFINITION_PATH} \ + --image-vector "$image_vector_path" \ + --component-prefixes "${COMPONENT_PREFIXES}" \ + " + fi + + # translates all images defined the images.yaml into component descriptor resources. + # For detailed documentation see https://github.com/gardener/component-cli/blob/main/docs/reference/components-cli_image-vector_add.md + component-cli image-vector add ${COMPONENT_CLI_ARGS} +fi + +if [[ -d "$repo_root_dir/charts/" ]]; then + for image_tpl_path in "$repo_root_dir/charts/"*"/templates/_images.tpl"; do + if [[ ! -f "$image_tpl_path" ]]; then + continue + fi + + outputFile=$(sed 's/{{-//' $image_tpl_path | sed 's/}}//' | sed 's/define//' | sed 's/-//' | sed 's/end//' | sed 's/"//' | sed 's/"//' |sed 's/image.//' | sed -e 's/^[ \t]*//' | awk -v RS= '{for (i=1; i<=NF; i++) printf "%s%s", $i, (i==NF?"\n":" ")}') + echo "enriching component descriptor from ${image_tpl_path}" + + while read p; do + line="$(echo -e "$p")" + IFS=' ' read -r -a array <<< "$line" + IFS=': ' read -r -a imageAndTag <<< ${array[1]} + + NAME=${array[0]} + REPOSITORY=${imageAndTag[0]} + TAG=${imageAndTag[1]} + + ${ADD_DEPENDENCIES_CMD} --container-image-dependencies "{\"name\": \"${NAME}\", \"image_reference\": \"${REPOSITORY}:${TAG}\", \"version\": \"$TAG\"}" + done < <(echo "$outputFile") + done +fi + +cp "${BASE_DEFINITION_PATH}" "${descriptor_out_file}" diff --git a/.ci/hack/doc.go b/.ci/hack/doc.go new file mode 100755 index 00000000..fd4efa87 --- /dev/null +++ b/.ci/hack/doc.go @@ -0,0 +1,16 @@ +// Copyright 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This package imports CI related scripts - it is to force `go mod` to see them as dependencies. +package ci diff --git a/.ci/hack/prepare_release b/.ci/hack/prepare_release new file mode 100755 index 00000000..42eeb6f1 --- /dev/null +++ b/.ci/hack/prepare_release @@ -0,0 +1,99 @@ +#!/usr/bin/env sh +# +# Copyright 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +repo_root_dir="$(realpath $1)" +repo_base="$2" +repo_name="$3" + +apk update +apk add --no-cache \ + ca-certificates \ + make \ + bash \ + git \ + curl \ + openssl \ + tar \ + gzip \ + sed \ + jq + +# create virtual package with the dev tools +echo "Installing dev tools in a virtual package" +apk add --no-cache --virtual .build-deps \ + gcc \ + go \ + musl-dev + +GOLANG_VERSION="$(sed -rn 's/FROM (eu\.gcr\.io\/gardener-project\/3rd\/golang|golang):([^ ]+).*/\2/p' < "$repo_root_dir/Dockerfile")" + +# As we cannot expect alpine to provide and maintain all golang versions via apk, we need to find another way to install the required golang version. +# Alpine is using musl-libc instead of glibc, therefore we cannot use the available pre-built binaries from golang, but have to build them ourselves from source. +# refs: +# - https://stackoverflow.com/a/45987284 +# - https://github.com/docker-library/golang/blob/f300e60ca19c3b98cfcf01ca112af2ac10104320/1.16/alpine3.14/Dockerfile +echo "Downloading go src $GOLANG_VERSION" +rm -rf /usr/local/go +wget -q -O - "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz" | tar zx -C /usr/local + +# Configure golang environment +echo "Building and installing go $GOLANG_VERSION" +export \ + PATH="/usr/local/go/bin":$PATH \ + GOARCH="$(go env GOARCH)" \ + GOOS="$(go env GOOS)" \ + GOROOT_BOOTSTRAP="$(go env GOROOT)" +export GOHOSTOS="$GOOS" \ + GOHOSTARCH="$GOARCH" +cd /usr/local/go/src +echo "Executing make on go $GOLANG_VERSION" +./make.bash + +echo "Deleting the virtual package for go" +apk del --no-network .build-deps + +export GOROOT="/usr/local/go" +export GOPATH="$(mktemp -d)" +export GOBIN="$GOPATH/bin" +export PATH="$GOBIN:$PATH" + +REPO_BASE="$GOPATH/src/$repo_base" +mkdir -p "$REPO_BASE" +REPO_PATH="$REPO_BASE/$repo_name" +cp -R "$repo_root_dir" "$REPO_PATH" + +current_dir="$(pwd)" +cd "$REPO_PATH" + +if make -n install-requirements &>/dev/null; then + make install-requirements +else + echo "skipping optional 'make install-requirements' as it is not present" +fi + +cd "$current_dir" + +echo "$EFFECTIVE_VERSION" > "$REPO_PATH/VERSION" +cur_dir="$(pwd)" +cd "$REPO_PATH" +if ! make generate; then + cd "$cur_dir" + exit 1 +fi +cd "$cur_dir" +cp -RT "$REPO_PATH/" "$repo_root_dir/" diff --git a/.ci/hack/set_dependency_version b/.ci/hack/set_dependency_version new file mode 100755 index 00000000..95997760 --- /dev/null +++ b/.ci/hack/set_dependency_version @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +# +# Copyright 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import pathlib +import sys + +import ci.util + + +dependency_type = ci.util.check_env('DEPENDENCY_TYPE') +if not dependency_type == 'component': + ci.util.fail( + "don't know how to upgrade dependency type: " + f'{dependency_type}' + ) + +dependency_name = ci.util.check_env('DEPENDENCY_NAME') +dependency_version = ci.util.check_env('DEPENDENCY_VERSION') + +images_file = pathlib.Path( + ci.util.check_env('REPO_DIR'), + 'imagevector', + 'images.yaml', +) + + +class ImagesParser(object): + ''' + a naive YAML-parser crafted for the special case of processing + gardener's images.yaml file; crafted that way to preserve + comments/empty lines + ''' + def __init__( + self, + images_file, + names, + target_version, + ): + self.images_file = images_file + self.lines = images_file.read_text().split('\n') + self.names = names + self.target_version = target_version + self._line_idx = 0 + + def _line(self): + return self.lines[self._line_idx] + + def _next_line(self): + self._line_idx += 1 + return self._line() + + def _skip_to_next_entry(self, names): + while not self._line().startswith('-'): + self._next_line() + name = self._line().strip().split(':')[-1].strip() + + if name not in names: + self._next_line() + return self._skip_to_next_entry(names) + + # found one of the entries: + return name + + def _skip_to_next_tag(self): + self._next_line() + while not self._line().startswith('-'): + if self._line().strip().startswith('tag:'): + return + self._next_line() + raise RuntimeError('did not find tag attribute') + + def set_versions(self): + while self.names: + try: + name = self._skip_to_next_entry(self.names) + except IndexError: + print(str(self.names)) + ci.util.fail('don\'t know how to update ' + str(self.names)) + self.names.remove(name) + self._skip_to_next_tag() + tag_line = self._line() + indent = len(tag_line) - len(tag_line.lstrip()) + patched_line = ' ' * indent + 'tag: "{version}"'.format( + version=self.target_version, + ) + self.lines[self._line_idx] = patched_line + + def write_updated_file(self): + self.images_file.write_text( + '\n'.join(self.lines) + ) + + +# optionally load special cases from first argument given as JSON +injectedSpecialCases = {} +if len(sys.argv) == 2: + injectedSpecialCases = json.loads(sys.argv[1]) + +# handle special cases +name = dependency_name.split('/')[-1] +if name in injectedSpecialCases: + names = injectedSpecialCases[name] +elif name == 'autoscaler': + names = ['cluster-autoscaler'] +elif name == 'vpn2': + names = ['vpn-seed-server', 'vpn-shoot-client'] +elif name == 'external-dns-management': + names = ['dns-controller-manager'] +elif name == 'logging': + names = ['fluent-bit-plugin-installer', 'vali-curator', 'telegraf', 'event-logger', 'tune2fs'] +elif name == 'etcd-custom-image': + names = ['etcd'] +elif name == 'egress-filter-refresher': + names = ['egress-filter'] +elif name == 'apiserver-proxy': + names = ['apiserver-proxy-sidecar'] +else: + names = [name] + + +parser = ImagesParser( + images_file=images_file, + names=names, + target_version=dependency_version, +) + +parser.set_versions() +parser.write_updated_file() diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 00000000..7b2c9873 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,37 @@ +--- +name: Bug Report +about: Report a bug encountered while working with this Gardener extension + +--- + +**How to categorize this issue?** + +/area TODO +/kind bug +/platform aws + +**What happened**: + +**What you expected to happen**: + +**How to reproduce it (as minimally and precisely as possible)**: + +**Anything else we need to know?**: + +**Environment**: + +- Gardener version (if relevant): +- Extension version: +- Kubernetes version (use `kubectl version`): +- Cloud provider or hardware configuration: +- Others: diff --git a/.github/ISSUE_TEMPLATE/feature.md b/.github/ISSUE_TEMPLATE/feature.md new file mode 100644 index 00000000..ed5ff966 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -0,0 +1,25 @@ +--- +name: Enhancement Request +about: Suggest an enhancement for this extension + +--- + +**How to categorize this issue?** + +/area TODO +/kind enhancement +/platform aws + +**What would you like to be added**: + +**Why is this needed**: diff --git a/.github/ISSUE_TEMPLATE/flaking-test.md b/.github/ISSUE_TEMPLATE/flaking-test.md new file mode 100644 index 00000000..3871f8c8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/flaking-test.md @@ -0,0 +1,33 @@ +--- +name: Flaking Test +about: Report flaky tests or jobs in Gardener CI +title: "[Flaky Test] FLAKING TEST/SUITE" + +--- + + + +**How to categorize this issue?** + +/area testing +/kind flake +/platform aws + +**Which test(s)/suite(s) are flaking**: + +**CI link**: + +**Reason for failure**: + +**Anything else we need to know**: + diff --git a/.github/ISSUE_TEMPLATE/support.md b/.github/ISSUE_TEMPLATE/support.md new file mode 100644 index 00000000..227875a3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/support.md @@ -0,0 +1,13 @@ +--- +name: Support Request +about: Support request or question relating to this extension + +--- + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 66fed918..8aeb085a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,21 @@ +**How to categorize this PR?** + +/area TODO +/kind TODO +/platform aws + **What this PR does / why we need it**: **Which issue(s) this PR fixes**: @@ -13,9 +31,9 @@ Write your release note: Format of block header: Possible values: -- category: breaking|feature|bugfix|doc|other +- category: breaking|noteworthy|feature|bugfix|doc|other - target_group: user|operator|developer|dependency --> -```improvement user +```other operator -``` \ No newline at end of file +``` diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 9369172e..7ad9eeeb 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -15,7 +15,7 @@ CODE_GEN_DIR=$(go list -m -f '{{.Dir}}' k8s.io/code-generator) rm -f $GOPATH/bin/*-gen -bash "${CODE_GEN_DIR}/kube_codegen.sh" \ +bash "${CODE_GEN_DIR}/generate-internal-groups.sh" \ deepcopy,defaulter \ github.com/gardener/machine-controller-manager-provider-openstack/pkg/client \ github.com/gardener/machine-controller-manager-provider-openstack/pkg/apis \ @@ -23,7 +23,7 @@ bash "${CODE_GEN_DIR}/kube_codegen.sh" \ "openstack:v1alpha1" \ --go-header-file "${GARDENER_HACK_DIR}/LICENSE_BOILERPLATE.txt" -bash "${CODE_GEN_DIR}/kube_codegen.sh" \ +bash "${CODE_GEN_DIR}/generate-internal-groups.sh" \ conversion \ github.com/gardener/machine-controller-manager-provider-openstack/pkg/client \ github.com/gardener/machine-controller-manager-provider-openstack/pkg/apis \ diff --git a/hack/update-github-templates.sh b/hack/update-github-templates.sh new file mode 100755 index 00000000..ce25e5aa --- /dev/null +++ b/hack/update-github-templates.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors +# +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o nounset +set -o pipefail + +mkdir -p "$(dirname $0)/../.github" "$(dirname $0)/../.github/ISSUE_TEMPLATE" + +for file in `find "${GARDENER_HACK_DIR}"/../.github -name '*.md'`; do + cat "$file" |\ + sed 's/operating Gardener/working with this Gardener extension/g' |\ + sed 's/to the Gardener project/for this extension/g' |\ + sed 's/to Gardener/to this extension/g' |\ + sed 's/- Gardener version:/- Gardener version (if relevant):\n- Extension version:/g' |\ + sed 's/\/kind [a-zA-Z]*/&\n\/platform aws/g' \ + > "$(dirname $0)/../.github/${file#*.github/}" +done