Sync 0.9 to proxmox integration (#221)

Signed-off-by: Kingdon Barrett <kingdon+github@tuesdaystudios.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Co-authored-by: Kingdon Barrett <kingdon+notify@tuesdaystudios.com>
Co-authored-by: Andrei Kvapil <kvapss@gmail.com>
Co-authored-by: Kingdon Barrett <kingdon+github@tuesdaystudios.com>
This commit is contained in:
Marian Koreniuk
2024-07-17 21:51:40 +02:00
committed by GitHub
parent d5c202b8bd
commit bb2918d2ec
200 changed files with 16472 additions and 24346 deletions

37
scripts/fluxcd-kustomize.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/sh
# This scripts adds common fluxcd labels to all objects
if [ -z "$NAME" ]; then
echo 'Variable $NAME is not set!' >&2
exit 1
fi
if [ -z "$NAMESPACE" ]; then
echo 'Variable $NAMESPACE is not set!' >&2
exit 1
fi
TMP_DIR=$(mktemp -d)
cat - > "${TMP_DIR}/helm-generated-output.yaml"
cat > "${TMP_DIR}/global-labels.yaml" <<EOT
apiVersion: builtin
kind: LabelTransformer
metadata:
name: global-labels
labels:
helm.toolkit.fluxcd.io/name: ${NAME}
helm.toolkit.fluxcd.io/namespace: ${NAMESPACE:-$HELM_NAMESPACE}
fieldSpecs:
- path: metadata/labels
create: true
EOT
cat > "${TMP_DIR}/kustomization.yaml" <<EOT
resources:
- helm-generated-output.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
- global-labels.yaml
EOT
kubectl kustomize "${TMP_DIR}"
rm -rf "${TMP_DIR}"

View File

@@ -19,7 +19,33 @@ run_migrations() {
}
flux_is_ok() {
kubectl wait --for=condition=available -n cozy-fluxcd deploy/source-controller deploy/helm-controller --timeout=10s
kubectl wait --for=condition=available -n cozy-fluxcd deploy/source-controller deploy/helm-controller --timeout=1s
kubectl wait --for=condition=ready -n cozy-fluxcd helmrelease/fluxcd --timeout=1s # to call "apply resume" below
}
ensure_fluxcd() {
if flux_is_ok; then
return
fi
# Install fluxcd-operator
if kubectl get helmreleases.helm.toolkit.fluxcd.io -n cozy-fluxcd fluxcd-operator; then
make -C packages/system/fluxcd-operator apply resume
else
make -C packages/system/fluxcd-operator apply-locally
fi
wait_for_crds fluxinstances.fluxcd.controlplane.io
# Install fluxcd
if kubectl get helmreleases.helm.toolkit.fluxcd.io -n cozy-fluxcd fluxcd; then
make -C packages/system/fluxcd apply resume
else
make -C packages/system/fluxcd apply-locally
fi
wait_for_crds helmreleases.helm.toolkit.fluxcd.io helmrepositories.source.toolkit.fluxcd.io
}
wait_for_crds() {
timeout 60 sh -c "until kubectl get crd $*; do sleep 1; done"
}
install_basic_charts() {
@@ -40,19 +66,19 @@ run_migrations
make -C packages/core/platform namespaces-apply
# Install fluxcd
make -C packages/core/fluxcd apply
# Reconcile Helm repositories
kubectl annotate helmrepositories.source.toolkit.fluxcd.io -A -l cozystack.io/repository reconcile.fluxcd.io/requestedAt=$(date +"%Y-%m-%dT%H:%M:%SZ") --overwrite
ensure_fluxcd
# Install platform chart
make -C packages/core/platform apply
# Install basic system charts (should be after platform chart applied)
# Install basic charts
if ! flux_is_ok; then
install_basic_charts
fi
# Reconcile Helm repositories
kubectl annotate helmrepositories.source.toolkit.fluxcd.io -A -l cozystack.io/repository reconcile.fluxcd.io/requestedAt=$(date +"%Y-%m-%dT%H:%M:%SZ") --overwrite
# Reconcile platform chart
trap 'exit' INT TERM
while true; do

View File

@@ -5,13 +5,16 @@ help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
show: ## Show output of rendered templates
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | helm template --dry-run=server -n $(NAMESPACE) $(NAME) . -f -
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm template --dry-run=server --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . -f -
apply: suspend ## Apply Helm release to a Kubernetes cluster
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | helm upgrade -i -n $(NAMESPACE) $(NAME) . -f -
apply: suspend ## Apply Helm release to a Kubernetes cluster
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm upgrade -i --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . -f -
diff: ## Diff Helm release against objects in a Kubernetes cluster
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | helm diff upgrade --allow-unreleased --normalize-manifests -n $(NAMESPACE) $(NAME) . -f -
kubectl get hr -n $(NAMESPACE) $(NAME) -o jsonpath='{.spec.values}' | NAMESPACE=$(NAMESPACE) NAME=$(NAME) \
helm diff upgrade --allow-unreleased --post-renderer ../../../scripts/fluxcd-kustomize.sh -n $(NAMESPACE) $(NAME) . -f -
suspend: ## Suspend reconciliation for an existing Helm release
kubectl patch hr -n $(NAMESPACE) $(NAME) -p '{"spec": {"suspend": true}}' --type=merge --field-manager=flux-client-side-apply