-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathgenerate.sh
executable file
·136 lines (120 loc) · 5.22 KB
/
generate.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
# This script updates the manifests in this directory using helm.
# Values files for the manifests in this directory can be found in
# ../calico/charts/values.
# Helm binary to use. Default to the one installed by the Makefile.
HELM=${HELM:-../bin/helm}
# Get versions to install.
defaultCalicoVersion=$(cat ../charts/calico/values.yaml | grep version: | cut -d" " -f2)
CALICO_VERSION=${CALICO_VERSION:-$defaultCalicoVersion}
defaultOperatorVersion=$(cat ../charts/tigera-operator/values.yaml | grep version: | cut -d" " -f4)
OPERATOR_VERSION=${OPERATOR_VERSION:-$defaultOperatorVersion}
NON_HELM_MANIFEST_IMAGES="calico/apiserver calico/windows calico/ctl calico/csi calico/node-driver-registrar calico/dikastes calico/flannel-migration-controller"
echo "Generating manifests for Calico=$CALICO_VERSION and tigera-operator=$OPERATOR_VERSION"
##########################################################################
# Build the operator manifest.
##########################################################################
cat <<EOF > tigera-operator.yaml
apiVersion: v1
kind: Namespace
metadata:
name: tigera-operator
labels:
name: tigera-operator
pod-security.kubernetes.io/enforce: privileged
EOF
${HELM} -n tigera-operator template \
--no-hooks \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set whisker.enabled=false \
--set goldmane.enabled=false \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set calicoctl.tag=$CALICO_VERSION \
../charts/tigera-operator >> tigera-operator.yaml
##########################################################################
# Build CRD manifest.
#
# This manifest is used in "Calico the hard way" documentation.
##########################################################################
echo "# CustomResourceDefinitions for Calico the Hard Way" > crds.yaml
for FILE in $(ls ../charts/calico/crds); do
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >> crds.yaml
done
##########################################################################
# Build manifest which includes both Calico and Operator CRDs.
##########################################################################
echo "# CustomResourceDefinitions for Calico and Tigera operator" > operator-crds.yaml
for FILE in $(ls ../charts/tigera-operator/crds/*.yaml | xargs -n1 basename); do
${HELM} -n tigera-operator template \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
../charts/tigera-operator >> operator-crds.yaml
done
for FILE in $(ls ../charts/calico/crds); do
${HELM} template ../charts/calico \
--include-crds \
--show-only $FILE \
--set version=$CALICO_VERSION \
-f ../charts/values/calico.yaml >> operator-crds.yaml
done
##########################################################################
# Build Calico manifests.
#
# To add a new manifest to this directory, define
# a new values file in ../charts/values/
##########################################################################
VALUES_FILES=$(cd ../charts/values && find . -type f -name "*.yaml")
for FILE in $VALUES_FILES; do
echo "Generating manifest from charts/values/$FILE"
${HELM} -n kube-system template \
../charts/calico \
--set version=$CALICO_VERSION \
-f ../charts/values/$FILE > $FILE
done
##########################################################################
# Build tigera-operator manifests for OCP.
#
# OCP requires resources in their own yaml files, so output to a dir.
# Then do a bit of cleanup to reduce the directory depth to 1.
##########################################################################
${HELM} template \
-n tigera-operator \
../charts/tigera-operator/ \
--output-dir ocp \
--no-hooks \
--set installation.kubernetesProvider=OpenShift \
--set installation.enabled=false \
--set apiServer.enabled=false \
--set goldmane.enabled=false \
--set whisker.enabled=false \
--set tigeraOperator.version=$OPERATOR_VERSION \
--set calicoctl.tag=$CALICO_VERSION
# The first two lines are a newline and a yaml separator - remove them.
find ocp/tigera-operator -name "*.yaml" | xargs sed -i -e 1,2d
mv $(find ocp/tigera-operator -name "*.yaml") ocp/ && rm -r ocp/tigera-operator
# Generating the upgrade manifest for OCP.
# It excludes the CRs (01-*) and the specific BPF files to maintain compatibility with iptables.
VALUES_FILES=$(ls ocp | grep -v -e '^01-' -e 'cluster-network-operator.yaml' -e '02-configmap-calico-resources.yaml')
rm -f tigera-operator-ocp-upgrade.yaml
for FILE in $VALUES_FILES; do
cat "ocp/$FILE" >> tigera-operator-ocp-upgrade.yaml
echo -e "---" >> tigera-operator-ocp-upgrade.yaml # Add divisor
done
# Remove the last separator (last line)
sed -i -e '$ d' tigera-operator-ocp-upgrade.yaml
##########################################################################
# Replace image versions for "static" Calico manifests.
##########################################################################
if [[ $CALICO_VERSION != master ]]; then
echo "Replacing image versions for static manifests"
for img in $NON_HELM_MANIFEST_IMAGES; do
echo $img
find . -type f -exec sed -i "s|$img:[A-Xa-z0-9_.-]*|$img:$CALICO_VERSION|g" {} \;
done
fi