fix: another round of upgrade tweaks

master
Stefan Reimer 3 weeks ago
parent 74a81a8964
commit e3be5ec420
  1. 2
      Dockerfile
  2. 51
      admin/migrate_argo_values.py
  3. 6
      admin/upgrade_cluster.sh
  4. 4
      admin/v1.23/pre-upgrade.sh
  5. 2
      charts/kubezero/templates/network.yaml

@ -28,7 +28,7 @@ RUN cd /etc/apk/keys && \
RUN helm repo add kubezero https://cdn.zero-downtime.net/charts && \
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 charts/kubeadm /charts/kubeadm

@ -4,8 +4,6 @@ import argparse
import io
import yaml
DEFAULT_VERSION = "1.23.10-3"
def migrate(values):
"""Actual changes here"""
@ -30,18 +28,19 @@ def migrate(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):
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)
yaml.add_representer(str, str_presenter)
# to use with safe_dump:
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
def rec_sort(d):
if isinstance(d, dict):
res = dict()
@ -66,39 +65,21 @@ def rec_sort(d):
return d
parser = argparse.ArgumentParser(
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()
application = yaml.safe_load(sys.stdin)
yaml.add_representer(str, str_presenter)
# Set version from cmd line
if args.version:
application["spec"]["source"]["targetRevision"] = args.version
# to use with safe_dump:
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
# Extract Helm values
values = yaml.safe_load(application["spec"]["source"]["helm"]["values"])
# Read values
values = yaml.safe_load(sys.stdin)
# Merge new values
# Output new values
buffer = io.StringIO()
yaml.safe_dump(
yaml.dump(
rec_sort(migrate(values)),
buffer,
sys.stdout,
default_flow_style=False,
indent=2,
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)

@ -139,3 +139,9 @@ kubectl rollout restart daemonset/cilium -n kube-system
kubectl rollout restart daemonset/kube-multus-ds -n kube-system
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."

@ -36,8 +36,10 @@ kubectl get application kubezero -n argocd -o yaml | yq '.spec.source.helm.value
# merge all into new CM
yq ea '. as $item ireduce ({}; . * $item ) |
.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
kubectl get cm -n kube-system kubezero-values -o=yaml | \

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

Loading…
Cancel
Save