add activation script to clear k3s
This commit is contained in:
parent
80d8842f94
commit
1ee07edb31
1 changed files with 22 additions and 0 deletions
|
|
@ -40,5 +40,27 @@ in
|
||||||
"ubuntu"
|
"ubuntu"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
system.activationScripts.cleanK3sManifests = {
|
||||||
|
text = ''
|
||||||
|
MANIFESTS_DIR="/var/lib/rancher/k3s/server/manifests"
|
||||||
|
NIX_MANIFESTS="${builtins.concatStringsSep " " (builtins.attrNames config.services.k3s.manifests)}"
|
||||||
|
DEFAULT_MANIFESTS="ccm coredns local-storage rolebindings runtimes traefik"
|
||||||
|
|
||||||
|
echo "Cleaning up K3s manifests"
|
||||||
|
|
||||||
|
for file in $MANIFESTS_DIR/*.yaml; do
|
||||||
|
[ -f "$file" ] || echo "not a file"; continue
|
||||||
|
name=$(basename "$file" .yaml)
|
||||||
|
if ! (echo "$NIX_MANIFESTS $DEFAULT_MANIFESTS" | grep -qw $name); then
|
||||||
|
echo "Stale manifest found, deleting $name.yaml"
|
||||||
|
k3s kubectl delete -f "$file" --ignore-not-found=true 2>/dev/null || true
|
||||||
|
rm -f "$file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Done"
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue