-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
506 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
name: Bug Report | ||
about: Report a bug encountered while working with this Gardener extension | ||
|
||
--- | ||
|
||
**How to categorize this issue?** | ||
<!-- | ||
Please select area, kind, and priority for this issue. This helps the community categorizing it. | ||
Replace below TODOs or exchange the existing identifiers with those that fit best in your opinion. | ||
If multiple identifiers make sense you can also state the commands multiple times, e.g. | ||
/area control-plane | ||
/area auto-scaling | ||
... | ||
"/area" identifiers: audit-logging|auto-scaling|backup|certification|control-plane-migration|control-plane|cost|delivery|dev-productivity|disaster-recovery|documentation|high-availability|logging|metering|monitoring|networking|open-source|ops-productivity|os|performance|quality|robustness|scalability|security|storage|testing|usability|user-management | ||
"/kind" identifiers: api-change|bug|cleanup|discussion|enhancement|epic|impediment|poc|post-mortem|question|regression|task|technical-debt|test | ||
--> | ||
/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: |
Oops, something went wrong.