forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_descriptor
executable file
·111 lines (92 loc) · 4.41 KB
/
component_descriptor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/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"
#
# GENERIC_DEPENDENCIES: Set images that are generic dependencies with no specific tag.
# Defaults to "hyperkube,kube-apiserver,kube-controller-manager,kube-scheduler,kube-proxy"
#
# 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"
fi
if [[ -z "${GENERIC_DEPENDENCIES}" ]]; then
GENERIC_DEPENDENCIES="hyperkube,kube-apiserver,kube-controller-manager,kube-scheduler,kube-proxy"
fi
if [[ -z "${COMPONENT_CLI_ARGS}" ]]; then
COMPONENT_CLI_ARGS="
--comp-desc ${BASE_DEFINITION_PATH} \
--image-vector "$image_vector_path" \
--component-prefixes "${COMPONENT_PREFIXES}" \
--generic-dependencies "${GENERIC_DEPENDENCIES}" \
"
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]}
gardener="eu.gcr.io/gardener-project/gardener"
if [[ "$NAME" == "hyperkube" ]]; then
${ADD_DEPENDENCIES_CMD} --generic-dependencies "{\"name\": \"$NAME\", \"version\": \"$TAG\"}"
elif [[ $REPOSITORY =~ "eu.gcr.io/gardener-project/gardener"* ]]; then
${ADD_DEPENDENCIES_CMD} --generic-dependencies "{\"name\": \"$NAME\", \"version\": \"$TAG\"}"
else
${ADD_DEPENDENCIES_CMD} --container-image-dependencies "{\"name\": \"${NAME}\", \"image_reference\": \"${REPOSITORY}:${TAG}\", \"version\": \"$TAG\"}"
fi
done < <(echo "$outputFile")
done
fi
cp "${BASE_DEFINITION_PATH}" "${descriptor_out_file}"