Skip to content

Commit 4ce10b8

Browse files
committed
Add scripts to rebase istio-csr upstream manifests
with `make update` * ISTIO_CSR_VERSION in Makefile points to release version of upstream istio-csr * hack/update-istio-csr-manifests.sh pulls from upstream, modifies and places in bindata/ Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
1 parent ac9cc76 commit 4ce10b8

File tree

5 files changed

+106
-13
lines changed

5 files changed

+106
-13
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ GOLANGCI_LINT_BIN=$(BIN_DIR)/golangci-lint
9797

9898
OPERATOR_SDK_BIN=$(BIN_DIR)/operator-sdk
9999

100+
HELM_BIN=$(BIN_DIR)/helm
101+
100102
COMMIT ?= $(shell git rev-parse HEAD)
101103
SHORTCOMMIT ?= $(shell git rev-parse --short HEAD)
102104
GOBUILD_VERSION_ARGS = -ldflags "-X $(PACKAGE)/pkg/version.SHORTCOMMIT=$(SHORTCOMMIT) -X $(PACKAGE)/pkg/version.COMMIT=$(COMMIT)"
@@ -107,7 +109,7 @@ E2E_TIMEOUT ?= 1h
107109
E2E_GINKGO_LABEL_FILTER ?= "Platform: isSubsetOf {AWS}"
108110

109111
MANIFEST_SOURCE = https://github.com/cert-manager/cert-manager/releases/download/v1.15.5/cert-manager.yaml
110-
112+
ISTIO_CSR_VERSION = "v0.14.0"
111113

112114
##@ Development
113115

@@ -141,8 +143,9 @@ test: manifests generate fmt vet ## Run tests.
141143
mkdir -p "$(ENVTEST_ASSETS_DIR)"
142144
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_ASSETS_DIR) -p path)" go test ./... -coverprofile cover.out
143145

144-
update-manifests:
146+
update-manifests: $(HELM_BIN)
145147
hack/update-cert-manager-manifests.sh $(MANIFEST_SOURCE)
148+
hack/update-istio-csr-manifests.sh $(ISTIO_CSR_VERSION)
146149
.PHONY: update-manifests
147150

148151
update-scripts:
@@ -285,6 +288,10 @@ $(OPERATOR_SDK_BIN):
285288
mkdir -p $(BIN_DIR)
286289
hack/operator-sdk.sh $(OPERATOR_SDK_BIN)
287290

291+
$(HELM_BIN):
292+
mkdir -p $(BIN_DIR)
293+
hack/helm.sh $(HELM_BIN)
294+
288295
clean:
289296
go clean
290297
rm -f $(BIN)

hack/helm.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
set -eou pipefail
4+
5+
OUTPUT_PATH=${1:-./bin/helm}
6+
VERSION="v3.17.1"
7+
8+
GOOS=$(go env GOOS)
9+
GOARCH=$(go env GOARCH)
10+
11+
TAR_FILENAME="helm-${VERSION}-${GOOS}-${GOARCH}.tar.gz"
12+
TAR_DL_URL="https://get.helm.sh/${TAR_FILENAME}"
13+
14+
TEMP_DIR=$(mktemp -d)
15+
16+
echo "> downloading helm binary"
17+
18+
curl --silent --location -o "${TEMP_DIR}/${TAR_FILENAME}" "${TAR_DL_URL}"
19+
tar -C "${TEMP_DIR}" -xzf "${TEMP_DIR}/${TAR_FILENAME}"
20+
mv "${TEMP_DIR}/${GOOS}-${GOARCH}/helm" "${OUTPUT_PATH}"
21+
22+
echo "> helm binary available at ${OUTPUT_PATH}"

hack/lib/yq.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
OUTPUT_PATH="./bin/yq"
6+
7+
if [ ! -f "${OUTPUT_PATH}" ]; then
8+
echo "---- Installing yq tooling ----"
9+
10+
DIR=$(dirname "${OUTPUT_PATH}")
11+
mkdir -p "${DIR}"
12+
curl -s -f -L "https://github.com/mikefarah/yq/releases/download/v4.13.3/yq_$(go env GOHOSTOS)_$(go env GOHOSTARCH)" -o "${OUTPUT_PATH}"
13+
chmod +x "${OUTPUT_PATH}"
14+
15+
echo "yq binary installed in ${OUTPUT_PATH}"
16+
fi

hack/update-cert-manager-manifests.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
set -e
44

55
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
6+
source "$(dirname "${BASH_SOURCE}")/lib/yq.sh"
67

78
MANIFEST_SOURCE=${1:?"missing Cert Manager manifest url. You can use either http:// or file://"}
89

@@ -11,19 +12,12 @@ mkdir -p ./_output
1112
echo "---- Downloading manifest file from $MANIFEST_SOURCE ----"
1213
curl -NLs "$MANIFEST_SOURCE" -o ./_output/manifest.yaml
1314

14-
echo "---- Installing tooling ----"
15-
if [ ! -f ./_output/tools/bin/yq ]; then
16-
mkdir -p ./_output/tools/bin
17-
curl -s -f -L https://github.com/mikefarah/yq/releases/download/v4.13.3/yq_$(go env GOHOSTOS)_$(go env GOHOSTARCH) -o ./_output/tools/bin/yq
18-
chmod +x ./_output/tools/bin/yq
19-
fi
20-
2115
go install ./vendor/github.com/google/go-jsonnet/cmd/jsonnet
2216

2317
echo "---- Patching manifest ----"
2418
# Upstream manifest includes yaml items in a single file as separate yaml documents.
2519
# JSON cannot handle this so create one yaml document which includes an array of items instead.
26-
./_output/tools/bin/yq \
20+
./bin/yq \
2721
--output-format json \
2822
eval-all '. as $item ireduce ([]; . + $item)' \
2923
_output/manifest.yaml \
@@ -34,7 +28,7 @@ echo "---- Patching manifest ----"
3428
jsonnet \
3529
--tla-code-file manifest=_output/manifest_as_array.json \
3630
jsonnet/main.jsonnet \
37-
| ./_output/tools/bin/yq e '.' - \
31+
| ./bin/yq e '.' - \
3832
> _output/targets_as_map.json
3933

4034
# regenerate all bindata
@@ -43,12 +37,12 @@ rm -rf bindata/cert-manager-deployment
4337
rm -rf config/crd/bases/*-crd.yaml
4438

4539
# Split the produced target items in separate files and convert back to yaml.
46-
for file in $(./_output/tools/bin/yq eval 'keys | join(" ")' _output/targets_as_map.json)
40+
for file in $(./bin/yq eval 'keys | join(" ")' _output/targets_as_map.json)
4741
do
4842
dir=$(dirname "${file}")
4943
mkdir -p "${dir}"
5044
echo "${file}"
51-
./_output/tools/bin/yq \
45+
./bin/yq \
5246
--output-format yaml --prettyPrint \
5347
eval ".[\"${file}\"]" _output/targets_as_map.json \
5448
> "${file}"

hack/update-istio-csr-manifests.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
6+
source "$(dirname "${BASH_SOURCE}")/lib/yq.sh"
7+
8+
ISTIO_CSR_VERSION=${1:?"missing istio-csr version. Please specify a version from https://github.com/cert-manager/istio-csr/releases"}
9+
10+
mkdir -p ./_output
11+
12+
echo "---- Downloading istio-csr manifests ${ISTIO_CSR_VERSION} ----"
13+
14+
./bin/helm repo add jetstack https://charts.jetstack.io --force-update
15+
./bin/helm template cert-manager-istio-csr jetstack/cert-manager-istio-csr \
16+
-n cert-manager --version "${ISTIO_CSR_VERSION}" > _output/istio-csr-manifest.yaml
17+
18+
echo "---- Patching manifest ----"
19+
20+
# remove the helm specific labels from .metadata.labels and .spec.template.metadata.labels
21+
./bin/yq e 'del(.metadata.labels."helm.sh/chart")' -i _output/istio-csr-manifest.yaml
22+
./bin/yq e 'del(.spec.template.metadata.labels."helm.sh/chart")' -i _output/istio-csr-manifest.yaml
23+
./bin/yq e 'del(.spec.template.metadata.labels."app.kubernetes.io/managed-by")' -i _output/istio-csr-manifest.yaml
24+
25+
# update all occurences of app.kubernetes.io/managed-by label value.
26+
./bin/yq e \
27+
'(.[][] | select(has("app.kubernetes.io/managed-by"))."app.kubernetes.io/managed-by") |= "cert-manager-operator"' \
28+
-i _output/istio-csr-manifest.yaml
29+
30+
# regenerate all bindata
31+
rm -rf bindata/istio-csr
32+
mkdir -p bindata/istio-csr
33+
34+
# split into individual manifest files
35+
./bin/yq --output-format json \
36+
eval-all '.' -I 0 \
37+
_output/istio-csr-manifest.yaml | while read -r item; do
38+
39+
name=$(echo "$item" | ./bin/yq eval '.metadata.name' -)
40+
kind=$(echo "$item" | ./bin/yq eval '.kind' - | tr '[:upper:]' '[:lower:]')
41+
42+
# skip unused manifests
43+
if [[ "${name}-${kind}" == "cert-manager-istio-csr-metrics-service" || \
44+
"${name}-${kind}" == "cert-manager-istio-csr-dynamic-istiod-rolebinding" \
45+
]]; then
46+
47+
continue
48+
fi
49+
50+
output_file="bindata/istio-csr/${name}-${kind}.yaml"
51+
52+
echo "$item" | ./bin/yq eval -P > "$output_file"
53+
echo "$output_file"
54+
done

0 commit comments

Comments
 (0)