fix: another round of upgrade tweaks

This commit is contained in:
Stefan Reimer 2022-09-15 13:05:38 +02:00
parent a382c10b71
commit 7b33509107
5 changed files with 27 additions and 38 deletions

View File

@ -28,7 +28,7 @@ RUN cd /etc/apk/keys && \
RUN helm repo add kubezero https://cdn.zero-downtime.net/charts && \ RUN helm repo add kubezero https://cdn.zero-downtime.net/charts && \
mkdir -p /var/lib/kubezero mkdir -p /var/lib/kubezero
ADD admin/kubezero.sh admin/libhelm.sh admin/migrate_argo.py /usr/bin ADD admin/kubezero.sh admin/libhelm.sh admin/migrate_argo_values.py /usr/bin
ADD admin/libhelm.sh admin/v${KUBE_VERSION}/* /var/lib/kubezero ADD admin/libhelm.sh admin/v${KUBE_VERSION}/* /var/lib/kubezero
ADD charts/kubeadm /charts/kubeadm ADD charts/kubeadm /charts/kubeadm

View File

@ -4,8 +4,6 @@ import argparse
import io import io
import yaml import yaml
DEFAULT_VERSION = "1.23.10-3"
def migrate(values): def migrate(values):
"""Actual changes here""" """Actual changes here"""
@ -30,18 +28,19 @@ def migrate(values):
return values return values
class MyDumper(yaml.Dumper):
"""
Required to add additional indent for arrays to match yq behaviour to reduce noise in diffs
"""
def increase_indent(self, flow=False, indentless=False):
return super(MyDumper, self).increase_indent(flow, False)
def str_presenter(dumper, data): def str_presenter(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data) return dumper.represent_scalar("tag:yaml.org,2002:str", data)
yaml.add_representer(str, str_presenter)
# to use with safe_dump:
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
def rec_sort(d): def rec_sort(d):
if isinstance(d, dict): if isinstance(d, dict):
res = dict() res = dict()
@ -66,39 +65,21 @@ def rec_sort(d):
return d return d
parser = argparse.ArgumentParser( yaml.add_representer(str, str_presenter)
description="Migrate ArgoCD Kubezero values to new cluster config"
)
parser.add_argument(
"--version",
dest="version",
default=DEFAULT_VERSION,
action="store",
required=False,
help="Update KubeZero version",
)
args = parser.parse_args() # to use with safe_dump:
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
application = yaml.safe_load(sys.stdin) # Read values
values = yaml.safe_load(sys.stdin)
# Set version from cmd line # Output new values
if args.version:
application["spec"]["source"]["targetRevision"] = args.version
# Extract Helm values
values = yaml.safe_load(application["spec"]["source"]["helm"]["values"])
# Merge new values
buffer = io.StringIO() buffer = io.StringIO()
yaml.safe_dump( yaml.dump(
rec_sort(migrate(values)), rec_sort(migrate(values)),
buffer, sys.stdout,
default_flow_style=False, default_flow_style=False,
indent=2, indent=2,
sort_keys=False, sort_keys=False,
Dumper=MyDumper
) )
application["spec"]["source"]["helm"]["values"] = buffer.getvalue()
# Output new Application resource
yaml.dump(application, sys.stdout, default_flow_style=False)

View File

@ -139,3 +139,9 @@ kubectl rollout restart daemonset/cilium -n kube-system
kubectl rollout restart daemonset/kube-multus-ds -n kube-system kubectl rollout restart daemonset/kube-multus-ds -n kube-system
argo_used && enable_argo argo_used && enable_argo
# Final step is to commit the new argocd kubezero app
kubectl get app kubezero -n argocd -o yaml | yq 'del(.status) | del(.metadata) | .metadata.name="kubezero" | .metadata.namespace="argocd"' | yq 'sort_keys(..) | .spec.source.helm.values |= (from_yaml | to_yaml)' > /tmp/new-kubezero-argoapp.yaml
echo "Please commit /tmp/new-kubezero-argoapp.yaml as the updated kubezero/application.yaml for your cluster!"
echo "Then head over to ArgoCD for this cluster and sync all KubeZero modules to apply remaining upgrades."

View File

@ -36,8 +36,10 @@ kubectl get application kubezero -n argocd -o yaml | yq '.spec.source.helm.value
# merge all into new CM # merge all into new CM
yq ea '. as $item ireduce ({}; . * $item ) | yq ea '. as $item ireduce ({}; . * $item ) |
.global.clusterName = strenv(CLUSTERNAME) | .global.clusterName = strenv(CLUSTERNAME) |
.global.highAvailable = env(HIGHAVAILABLE)' $WORKDIR/addons-values.yaml ${WORKDIR}/network-values.yaml $WORKDIR/argo-values.yaml > $WORKDIR/kubezero-values.yaml .global.highAvailable = env(HIGHAVAILABLE)' $WORKDIR/addons-values.yaml ${WORKDIR}/network-values.yaml $WORKDIR/argo-values.yaml > $WORKDIR/kubezero-pre-values.yaml
# tumble new config via migrate.py
cat $WORKDIR/kubezero-pre-values.yaml | migrate_argo_values.py > $WORKDIR/kubezero-values.yaml
# Update kubezero-values CM # Update kubezero-values CM
kubectl get cm -n kube-system kubezero-values -o=yaml | \ kubectl get cm -n kube-system kubezero-values -o=yaml | \

View File

@ -19,7 +19,7 @@ cilium:
{{- define "network-argo" }} {{- define "network-argo" }}
# Metallb # Metallb
ignoreDifferences: ignoreDifferences:
- group: apiextensions.k8s.io/v1 - group: apiextensions.k8s.io
kind: CustomResourceDefinition kind: CustomResourceDefinition
jsonPointers: jsonPointers:
- /spec/conversion/webhook/clientConfig/caBundle - /spec/conversion/webhook/clientConfig/caBundle