1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-14 11:37:37 +00:00

Don't set Kustomization ns if >1 of them present

Cleaner resolution for the problem mentioned last commit.
Fixes mono-namespace charts while assuming multi-namespace charts
have the diligence to set `.metadata.namespace` everywhere necessary.
This commit is contained in:
Antonio Gurgel 2024-07-21 19:56:29 -07:00
parent 961f215e50
commit a107476ca1
3 changed files with 27 additions and 4 deletions

View file

@ -26,7 +26,7 @@ in {
extraMetadata = nsMetadata;
};
buildInputs = [pkgs.kustomize];
buildInputs = [pkgs.kustomize pkgs.yq-go];
phases = ["installPhase"];
installPhase = builtins.readFile src/output.sh;
};

View file

@ -38,9 +38,9 @@ in rec {
objs,
...
}: let
# Some service modules may include extra resources which, it's safe to
# assume, belong to the same namespace. This line removes the need to
# define the namespace in each extra resource.
# Some service modules may include extra resources which, it's (usually)
# safe to assume, belong to the same namespace. This line removes the need
# to define the namespace in each extra resource.
# (Because all objects' metadata is of the ObjectMeta type, non-namespaced
# objects can have `metadata.namespace` set, too. It will just be ignored
# at creation time in the Kubernetes cluster.)

View file

@ -23,6 +23,29 @@ build_kustomizations() {
kustomize create
kustomize edit add resource -- *
# Some charts lack diligence in setting `Release.Namespace` on the
# objects they create, but Kustomizations can paper over that by
# setting the namespace on all of their resources.
# Unless the chart uses more than one namespace,
# in which case, don't do that.
if [ -f SERVICE.yaml ]; then
if [ -f EXTRA.yaml ]; then
all_yaml=$(mktemp)
cat SERVICE.yaml <(echo "---") EXTRA.yaml > "$all_yaml"
else
all_yaml=SERVICE.yaml
fi
ns_count=$(
yq -N 'select(.metadata.namespace) | .metadata.namespace' "$all_yaml" \
| sort -u \
| wc -l
)
if [ "$ns_count" -le 1 ]; then
kustomize edit set namespace "$(basename "$(dirname "$PWD")")"
fi
fi
popd > /dev/null || exit 1
done
}