Skip to content

Commit

Permalink
feat: Created k8s-relogin for Azure
Browse files Browse the repository at this point in the history
This includes a semi breaking-change as the script for the tanzu flavour now is also called "k8s-relogin" instead of "relogin"

closes #33
  • Loading branch information
dploeger committed Jun 17, 2022
1 parent 4b938b4 commit a6c4522
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ For example: myresourcegroup:myk8s,myotherresourcegroup@othersubscription:myseco
the myresourcegroup resource group and mysecondk8s from the resource group myotherresourcegroup in the
subscription othersubscription.
Prefix a cluster name with an ! to load the admin-credentials for that cluster instead of the user credentials.
This generates the script `k8s-relogin` which allows you to recreate the Kubernetes credentials.

* (azure flavour) Environment AZ_K8S_INSTALL_OPTIONS: Additional options for the az aks install-cli programm.
(Defaults to empty)
Expand Down Expand Up @@ -423,7 +424,9 @@ seems to fail.
* Environment TANZU_CLUSTERS: A comma separated list of namespace:cluster name pairs
* Environment TANZU_ADD_CONTROL_CLUSTER: Whether to also authenticate against the control cluster [false]
* Environment TANZU_SKIP_TLS_VERIFY: Skip TLS verification [false]
* Environment TANZU_VSPHERE_PLUGIN_PATH: The path where to find the kubectl vsphere plugin [/wcp/plugin/linux-amd64/vsphere-plugin.zip]
* Environment TANZU_VSPHERE_PLUGIN_PATH: The path where to find the kubectl vsphere plugin [/wcp/plugin/linux-amd64/vsphere-plugin.zip]

This generates the script `k8s-relogin` which allows you to recreate the Kubernetes credentials.


### packages
Expand Down
5 changes: 4 additions & 1 deletion feature/kubernetes/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ configuration:
the myresourcegroup resource group and mysecondk8s from the resource group myotherresourcegroup in the
subscription othersubscription.
Prefix a cluster name with an ! to load the admin-credentials for that cluster instead of the user credentials.
This generates the script `k8s-relogin` which allows you to recreate the Kubernetes credentials.
- |
(azure flavour) Environment AZ_K8S_INSTALL_OPTIONS: Additional options for the az aks install-cli programm.
(Defaults to empty)
Expand Down Expand Up @@ -41,5 +42,7 @@ configuration:
* Environment TANZU_CLUSTERS: A comma separated list of namespace:cluster name pairs
* Environment TANZU_ADD_CONTROL_CLUSTER: Whether to also authenticate against the control cluster [false]
* Environment TANZU_SKIP_TLS_VERIFY: Skip TLS verification [false]
* Environment TANZU_VSPHERE_PLUGIN_PATH: The path where to find the kubectl vsphere plugin [/wcp/plugin/linux-amd64/vsphere-plugin.zip]
* Environment TANZU_VSPHERE_PLUGIN_PATH: The path where to find the kubectl vsphere plugin [/wcp/plugin/linux-amd64/vsphere-plugin.zip]
This generates the script `k8s-relogin` which allows you to recreate the Kubernetes credentials.
18 changes: 12 additions & 6 deletions feature/kubernetes/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
. /feature-installer-utils.sh

if [ "X$(cat /home/cloudcontrol/flavour)X" == "XazureX" ]; then
echo "#!/bin/sh" > ~/bin/k8s-relogin

for CLUSTER in $(echo "${AZ_K8S_CLUSTERS}" | tr "," "\n"); do
K8S_RESOURCEGROUP=$(echo "$CLUSTER" | cut -d ":" -f 1)
K8S_CLUSTER=$(echo "$CLUSTER" | cut -d ":" -f 2)
Expand All @@ -19,13 +21,17 @@ if [ "X$(cat /home/cloudcontrol/flavour)X" == "XazureX" ]; then
if [ "X${K8S_CLUSTER:0:1}X" == "X!X" ]; then
ADMIN_PARAMETER="--admin"
K8S_CLUSTER="${K8S_CLUSTER:1}"
echo -n "as admin"
echo " as admin"
else
echo ""
fi

echo
echo az aks get-credentials --overwrite-existing --resource-group "${K8S_RESOURCEGROUP}" --name "${K8S_CLUSTER}" ${ADMIN_PARAMETER} "${K8S_SUBSCRIPTION[@]}" >> ~/bin/k8s-relogin

execHandle "Fetching k8s credentials for ${CLUSTER}" az aks get-credentials --resource-group "${K8S_RESOURCEGROUP}" --name "${K8S_CLUSTER}" ${ADMIN_PARAMETER} "${K8S_SUBSCRIPTION[@]}"
done
chmod +x ~/bin/k8s-relogin

IFS=' ' read -r -a install_options <<< "${AZ_K8S_INSTALL_OPTIONS:=""}"

execHandle "Installing kubectl" sudo az aks install-cli "${install_options[@]}"
Expand Down Expand Up @@ -117,7 +123,7 @@ then
cd - &>/dev/null || exit
rm -rf "${TEMPDIR}"

echo "#!/bin/sh" > ~/bin/relogin
echo "#!/bin/sh" > ~/bin/k8s-relogin

PATH=$PATH:/home/cloudcontrol/bin

Expand All @@ -131,15 +137,15 @@ then
if [ "X${TANZU_ADD_CONTROL_CLUSTER:-no}X" == "XyesX" ]
then
execHandle "Authenticating against control cluster" kubectl vsphere login "${loginArgs[@]}"
echo kubectl vsphere login "${loginArgs[@]}" >> ~/bin/relogin
echo kubectl vsphere login "${loginArgs[@]}" >> ~/bin/k8s-relogin
fi

for NAMESPACEDCLUSTER in $(echo "${TANZU_CLUSTERS}" | tr "," "\n")
do
NAMESPACE=$(echo "$NAMESPACEDCLUSTER" | cut -d ":" -f 1)
CLUSTER=$(echo "$NAMESPACEDCLUSTER" | cut -d ":" -f 2)
execHandle "Authenticating against cluster ${CLUSTER} in namespace ${NAMESPACE}" kubectl vsphere login "${loginArgs[@]}" --tanzu-kubernetes-cluster-namespace="${NAMESPACE}" --tanzu-kubernetes-cluster-name="${CLUSTER}"
echo kubectl vsphere login "${loginArgs[@]}" --tanzu-kubernetes-cluster-namespace="${NAMESPACE}" --tanzu-kubernetes-cluster-name="${CLUSTER}" >> ~/bin/relogin
echo kubectl vsphere login "${loginArgs[@]}" --tanzu-kubernetes-cluster-namespace="${NAMESPACE}" --tanzu-kubernetes-cluster-name="${CLUSTER}" >> ~/bin/k8s-relogin
done
chmod +x ~/bin/relogin
chmod +x ~/bin/k8s-relogin
fi

0 comments on commit a6c4522

Please sign in to comment.