Skip to content

Instantly share code, notes, and snippets.

@jkremser
Last active October 17, 2023 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkremser/176c5bae04a9db8feea0f72217e8eff5 to your computer and use it in GitHub Desktop.
Save jkremser/176c5bae04a9db8feea0f72217e8eff5 to your computer and use it in GitHub Desktop.
cluster api tui
kind: ConfigMap
metadata:
labels:
app-operator.giantswarm.io/watching: "true"
name: $CLUSTER-user-values
namespace: org-$ORG
apiVersion: v1
data:
values: |
baseDomain: test.gigantic.io
clusterDescription: "test cluster"
organization: "$ORG"
cluster:
kubernetesVersion: $K8S_VERSION
enableEncryptionProvider: false
connectivity:
network:
allowAllEgress: true
controlPlaneEndpoint:
host: "$IP"
ipPoolName: wc-cp-ips
port: 6443
loadBalancers:
cidrBlocks:
- "10.10.222.132/32"
controlPlane:
image:
repository: registry.k8s.io
replicas: 1
machineTemplate:
network:
devices:
- networkName: 'grasshopper-capv'
dhcp4: true
cloneMode: "linkedClone"
diskGiB: 50
numCPUs: 4
memoryMiB: 8096
resourcePool: "grasshopper"
template: ubuntu-2004-kube-$K8S_VERSION
nodeClasses:
default:
template: ubuntu-2004-kube-$K8S_VERSION
cloneMode: "linkedClone"
diskGiB: 50
numCPUs: 6
memoryMiB: 14000
resourcePool: "grasshopper"
network:
devices:
- networkName: 'grasshopper-capv'
dhcp4: true
nodePools:
worker:
class: "default"
replicas: 2
helmReleases:
cilium:
interval:
20s
cpi:
interval:
30s
coredns:
interval:
30s
---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
labels:
app-operator.giantswarm.io/version: 0.0.0
app.kubernetes.io/name: cluster-vsphere
name: $CLUSTER
namespace: org-giantswarm
spec:
catalog: $CLUSTER_CATALOG
extraConfigs:
- kind: secret
name: container-registries-configuration
namespace: giantswarm
priority: 25
kubeConfig:
inCluster: true
name: cluster-vsphere
namespace: org-$ORG
userConfig:
configMap:
name: $CLUSTER-user-values
namespace: org-$ORG
secret:
name: vsphere-credentials
namespace: org-$ORG
version: $CLUSTER_VERSION
---
apiVersion: v1
data:
values: |
clusterName: $CLUSTER
organization: $ORG
managementCluster: $CLUSTER
kind: ConfigMap
metadata:
name: $CLUSTER-default-apps-user-values
namespace: org-$ORG
---
apiVersion: application.giantswarm.io/v1alpha1
kind: App
metadata:
generation: 1
labels:
app-operator.giantswarm.io/version: 0.0.0
app.kubernetes.io/name: default-apps-vsphere
giantswarm.io/cluster: $CLUSTER
giantswarm.io/managed-by: cluster
name: $CLUSTER-default-apps
namespace: org-$ORG
spec:
catalog: cluster
config:
configMap:
name: $CLUSTER-cluster-values
namespace: org-$ORG
kubeConfig:
inCluster: true
name: default-apps-vsphere
namespace: org-$ORG
userConfig:
configMap:
name: $CLUSTER-default-apps-user-values
namespace: org-$ORG
version: 0.9.2
#!/bin/bash
DIR="${DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )}"
K8S_VERSIONS=(v1.25.6 v1.24.11 v1.23.16 v1.22.5+vmware.1)
TEMPLATE_FILE=${TEMPLATE_FILE:-"cluster-list.yaml"}
export ORG=${ORG:-"giantswarm"}
main() {
[[ $# -lt 1 ]] && echo "usage: $0 [deploy|delete]" && exit 1
! which fzf > /dev/null && echo "Install fzf, this script needs it" && exit 2
! which kubectl > /dev/null && echo "Install kubectl, this script needs it" && exit 2
! which yq > /dev/null && echo "Install yq, this script needs it" && exit 2
! which figlet > /dev/null && echo "Install figlet, this script needs it" && exit 2
[[ $1 == deploy ]] && {
deploy
exit 0
}
[[ $1 == delete ]] && {
delete
exit 0
}
echo "usage: $0 [deploy|delete]" && exit 1
}
deploy() {
export COL="\e[2;35;49m"
export RES="\e[0m"
# version
export K8S_VERSION=$(printf "%s\n" "${K8S_VERSIONS[@]}" | \
fzf --header "Select k8s version" --prompt='λ' --cycle --preview-window top:80% \
--preview "printf '${COL}'; figlet -f big GiantSwarm.io; printf '${RES}'; echo -e 'values.yaml for cluster chart:\n=============================='; export K8S_VERSION={}; cat "${DIR}/${TEMPLATE_FILE}" | envsubst | yq 'select(documentIndex == 0) | .data.values' - | yq --colors")
[[ $? != 0 ]] && exit
# name
echo "cluster name:"
read CLUSTER
export CLUSTER
[[ -z $CLUSTER ]] && echo "Cluster name can't be empty" && exit 1
# ip
echo "control plane ip? (leave empty for auto-assignment)"
read IP
# org
echo -e "Organization: ${ORG}? [Y/n]"
read _resp
[[ $_resp =~ [nN] ]] && {
ORG=$(kubectl get organizations.security.giantswarm.io --no-headers -o custom-columns=":metadata.name" | \
fzf --header "Select organization" --prompt='λ' --cycle --preview-window top:80% \
--preview "printf '${COL}'; figlet -f big GiantSwarm.io; printf '${RES}'; echo -e 'values.yaml for cluster chart: (configmaps will be created in org-{} namespace)\n=============================='; export ORG={}; cat "${DIR}/${TEMPLATE_FILE}" | envsubst | yq 'select(documentIndex == 0) | .data.values' - | yq --colors")
}
export CLUSTER IP ORG
export CLUSTER_CATALOG=cluster
export CLUSTER_VERSION=0.6.1
TEST_CATALOG=$(echo -e "no\nyes" | fzf --header "test catalog?" --prompt='λ')
[[ $? != 0 ]] && exit
[[ ${TEST_CATALOG} == "yes" ]] && {
export CLUSTER_CATALOG=cluster-test
_possible_versions=$(curl -s https://giantswarm.github.io/cluster-test-catalog/index.yaml | grep -A1 cluster-vsphere | grep version: | cut -f2 -d':')
_filtered_versions=()
echo "Fetching the versions.."
{
rm -rf cluster-vsphere
git clone https://github.com/giantswarm/cluster-vsphere && cd cluster-vsphere
for v in $(echo ${_possible_versions}); do
git cat-file -t $(echo $v | cut -f2 -d'-') &> /dev/null && _filtered_versions+=($v)
done
rm -rf cluster-vsphere
} &> /dev/null
export CLUSTER_VERSION=$(printf "%s\n" "${_filtered_versions[@]}" | fzf --header "cluster version?" --prompt='λ' --cycle --delimiter='-' --preview-window right:80% --preview "git show --color=always {2}")
_ret=$?
[[ $_ret != 0 ]] && exit
}
check_result "${DIR}/${TEMPLATE_FILE}"
}
check_result() {
[[ $# -lt 1 ]] && echo "usage: $0 file_path" && exit 1
file_path="${1}"
cat ${file_path} | envsubst | bat -lyaml
[[ $? != 0 ]] && exit
printf "Are you sure to create the cluster '$CLUSTER' on ${COL}'$(kubectl config current-context)'${RES}\nHit 'e' for modifying the manifests further.\nHit 'p' for printing the manifests to stdout."
echo "[y/N/e/p]?"
read _resp
[[ $_resp =~ [yY] ]] && {
# here we apply the manifests
cat ${file_path} | envsubst | kubectl apply -f -
}
[[ $_resp =~ [eE] ]] && {
tmp=$(mktemp)
cat ${file_path} | envsubst > ${tmp}
${EDITOR} ${tmp}
check_result ${tmp}
}
[[ $_resp =~ [pP] ]] && {
cat ${file_path} | envsubst
}
}
delete() {
CLUSTER=$(kubectl get cluster --no-headers -o custom-columns=":metadata.name" -A | fzf --header "Select cluster to delete" --prompt='λ')
NS=$(kubectl get cluster -A | grep $CLUSTER | cut -d' ' -f1)
echo "Are you sure to delete cluster '$CLUSTER' in namespace '$NS' on $(kubectl config current-context):"
echo "[y/N]?"
read _resp
[[ $_resp =~ [yY] ]] && {
kubectl delete cm $CLUSTER-user-values -n$NS
kubectl delete app $CLUSTER $CLUSTER-default-apps -n$NS
}
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment