Skip to content

Instantly share code, notes, and snippets.

@cdelashmutt-pivotal
Last active July 3, 2024 21:19
Show Gist options
  • Save cdelashmutt-pivotal/fe7a84249689124c5c4dc08dd3fca034 to your computer and use it in GitHub Desktop.
Save cdelashmutt-pivotal/fe7a84249689124c5c4dc08dd3fca034 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
function requires() {
if ! command -v $1 &>/dev/null; then
echo "Requires $1"
exit 1
fi
}
scriptname=$(basename $0)
function usage {
echo "usage: $scriptname project clustergroup [sourceclustergroup]"
echo " project the project in Tanzu Platform to use"
echo " clustergroup the clustergroup to copy capabilities to"
echo " sourceclustergroup the source clustergroup to copy capabilities from, defaults to 'run'"
exit 1
}
requires "yq"
requires "ytt"
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "Illegal number of parameters"
usage
fi
project=$1
clustergroup=$2
sourceclustergroup=${3:-run}
#export KUBECONFIG="$HOME/.config/tanzu/kube/config"
tanzu project use $project
tanzu operations clustergroup use $sourceclustergroup
packages=$(KUBECONFIG="$HOME/.config/tanzu/kube/config" kubectl get packageinstall -o yaml | yq '.items[] | split_doc')
tanzu operations clustergroup use $clustergroup
ytt -f- <<EOF | KUBECONFIG="$HOME/.config/tanzu/kube/config" kubectl create --validate=false -f-
$packages
#@ load("@ytt:overlay", "overlay")
#@ def secret(packageinstall):
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: #@ packageinstall["metadata"]["name"]
data:
values.yml: ""
#@ end
#@overlay/match by=overlay.subset({"kind": "PackageInstall"}), expects="1+"
#@overlay/insert after=True, via=lambda packageinstall, _: secret(packageinstall)
---
#@overlay/match by=overlay.subset({"kind": "PackageInstall"}), expects="1+"
#@overlay/match-child-defaults missing_ok=True
---
metadata:
#@overlay/remove
annotations:
#@overlay/remove
labels:
#@overlay/remove
creationTimestamp:
#@overlay/remove
generation:
#@overlay/remove
resourceVersion:
#@overlay/remove
uid:
#@overlay/remove
status:
#@ def secretRefFragment(name):
- secretRef:
name: #@ name
#@ end
#@ def secretRef(packageinstall, result):
#@ mod_packageinstall = dict(packageinstall)
#@ mod_packageinstall_spec = dict(mod_packageinstall["spec"])
#@ mod_packageinstall_spec.update({"values": secretRefFragment(packageinstall["metadata"]["name"])})
#@ mod_packageinstall.update({"spec": mod_packageinstall_spec})
#@ return mod_packageinstall
#@ end
#@overlay/match by=overlay.subset({"kind": "PackageInstall"}), expects="1+"
#@overlay/replace via=secretRef
---
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment