Skip to content

Commit 6b5bcd9

Browse files
committed
Apply gitpod resources if there's diff
1 parent e694f8c commit 6b5bcd9

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

dev/preview/workflow/lib/k8s-util.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ function readWerftSecret {
8686
get secret "${name}" -o jsonpath="{.data.${key}}" \
8787
| base64 -d
8888
}
89+
90+
function diff-apply {
91+
local context=$1
92+
shift
93+
local yaml=$1
94+
yaml=$(realpath "${yaml}")
95+
96+
if kubectl --context "${context}" diff -f "${yaml}" > /dev/null; then
97+
echo "Skipping ${yaml}, as it produced no diff"
98+
else
99+
kubectl --context "${context}" apply -f "${yaml}"
100+
fi
101+
}

dev/preview/workflow/preview/deploy-gitpod.sh

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,35 +135,16 @@ EOF
135135
}
136136

137137
function installRookCeph {
138-
kubectl \
139-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
140-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
141-
apply -f "$ROOT/.werft/vm/manifests/rook-ceph/crds.yaml" --server-side --force-conflicts
138+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" "$ROOT/.werft/vm/manifests/rook-ceph/crds.yaml"
142139

143140
kubectl \
144141
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
145142
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
146143
wait --for condition=established --timeout=120s crd/cephclusters.ceph.rook.io
147144

148-
kubectl \
149-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
150-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
151-
apply -f "$ROOT/.werft/vm/manifests/rook-ceph/common.yaml" -f "$ROOT/.werft/vm/manifests/rook-ceph/operator.yaml"
152-
153-
kubectl \
154-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
155-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
156-
apply -f "$ROOT/.werft/vm/manifests/rook-ceph/cluster-test.yaml"
157-
158-
kubectl \
159-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
160-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
161-
apply -f "$ROOT/.werft/vm/manifests/rook-ceph/storageclass-test.yaml"
162-
163-
kubectl \
164-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
165-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
166-
apply -f "$ROOT/.werft/vm/manifests/rook-ceph/snapshotclass.yaml"
145+
for file in common operator cluster-test storageclass-test snapshotclass;do
146+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" "$ROOT/.werft/vm/manifests/rook-ceph/$file.yaml"
147+
done
167148
}
168149

169150
# Install Fluent-Bit sending logs to GCP
@@ -376,7 +357,7 @@ then
376357
yq d -i admin-login-secret.yaml metadata.creationTimestamp
377358
yq d -i admin-login-secret.yaml metadata.uid
378359
yq d -i admin-login-secret.yaml metadata.resourceVersion
379-
kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" apply -f admin-login-secret.yaml
360+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" admin-login-secret.yaml
380361
rm -f admin-login-secret.yaml
381362

382363
yq w -i "${INSTALLER_CONFIG_PATH}" adminLoginSecret.kind "secret"
@@ -391,7 +372,7 @@ yq w -i stripe-api-keys.secret.yaml metadata.namespace "default"
391372
yq d -i stripe-api-keys.secret.yaml metadata.creationTimestamp
392373
yq d -i stripe-api-keys.secret.yaml metadata.uid
393374
yq d -i stripe-api-keys.secret.yaml metadata.resourceVersion
394-
kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" apply -f stripe-api-keys.secret.yaml
375+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" stripe-api-keys.secret.yaml
395376
rm -f stripe-api-keys.secret.yaml
396377

397378
#
@@ -401,8 +382,9 @@ kubectl --kubeconfig "${DEV_KUBE_PATH}" --context "${DEV_KUBE_CONTEXT}" --namesp
401382
| yq w - metadata.namespace ${PREVIEW_NAMESPACE} \
402383
| yq d - metadata.uid \
403384
| yq d - metadata.resourceVersion \
404-
| yq d - metadata.creationTimestamp \
405-
| kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" apply -f -
385+
| yq d - metadata.creationTimestamp > host-key.yaml
386+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" host-key.yaml
387+
rm -f host-key.yaml
406388

407389
yq w -i "${INSTALLER_CONFIG_PATH}" sshGatewayHostKey.kind "secret"
408390
yq w -i "${INSTALLER_CONFIG_PATH}" sshGatewayHostKey.name "host-key"
@@ -524,7 +506,7 @@ yq w -i spicedb-secret.yaml metadata.namespace "default"
524506
yq d -i spicedb-secret.yaml metadata.creationTimestamp
525507
yq d -i spicedb-secret.yaml metadata.uid
526508
yq d -i spicedb-secret.yaml metadata.resourceVersion
527-
kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" apply -f spicedb-secret.yaml
509+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" spicedb-secret.yaml
528510
rm -f spicedb-secret.yaml
529511

530512
#
@@ -626,7 +608,18 @@ rm -f /tmp/public-api
626608
log_info "Applying manifests (installing)"
627609

628610
kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" delete -n "${PREVIEW_NAMESPACE}" job migrations || true
629-
kubectl --kubeconfig "${PREVIEW_K3S_KUBE_PATH}" --context "${PREVIEW_K3S_KUBE_CONTEXT}" apply -f "${INSTALLER_RENDER_PATH}"
611+
# export the function so we can use it in xargs
612+
export -f diff-apply
613+
mkdir temp-installer || true
614+
pushd temp-installer
615+
# this will split the big yaml produced by the installer, so we can diff individual parts of it and run them in parallel
616+
yq4 -s '.kind + "_" + .metadata.name' "../${INSTALLER_RENDER_PATH}"
617+
rm .yml || true # this one is a leftover from the split
618+
# shellcheck disable=SC2038
619+
find . | xargs -n 1 -I {} -P 5 bash -c "diff-apply ${PREVIEW_K3S_KUBE_CONTEXT} {}"
620+
log_info "Applied all"
621+
popd
622+
rm -rf temp-installer
630623
rm -f "${INSTALLER_RENDER_PATH}"
631624

632625
# =========================

dev/preview/workflow/preview/deploy-monitoring-satellite.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ kubectl \
8686
echo "Applying generated manifests"
8787
for f in "${manifests_dir}"/*.yaml; do
8888
echo "Applying $f"
89-
kubectl \
90-
--kubeconfig "${PREVIEW_K3S_KUBE_PATH}" \
91-
--context "${PREVIEW_K3S_KUBE_CONTEXT}" \
92-
apply --server-side -f "${f}"
89+
diff-apply "${PREVIEW_K3S_KUBE_CONTEXT}" "${f}"
9390
done
9491

9592
echo "Patching grafana deployment"

0 commit comments

Comments
 (0)