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:
parent
961f215e50
commit
a107476ca1
3 changed files with 27 additions and 4 deletions
|
@ -26,7 +26,7 @@ in {
|
|||
extraMetadata = nsMetadata;
|
||||
};
|
||||
|
||||
buildInputs = [pkgs.kustomize];
|
||||
buildInputs = [pkgs.kustomize pkgs.yq-go];
|
||||
phases = ["installPhase"];
|
||||
installPhase = builtins.readFile src/output.sh;
|
||||
};
|
||||
|
|
|
@ -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.)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue