Run script on K8s cluster where Kubiya runner is installed
Next, run the following Bash script on the K8s cluster where the runner is installed:
#!/bin/bash# Function to display usage informationusage() {echo"Usage: $0 [options] <GitHub token>"echo""echo"Options:"echo" --dry-run Simulate the actions without applying any changes"echo" --help Display this help message"exit1}# Parse argumentsdry_run_flag=""token=""while [[ "$#"-gt0 ]]; docase $1 in--dry-run) dry_run_flag="--dry-run=client" ;;--help)usage ;;*) token=$1 ;;esacshiftdone# If no token was passed as an argument, prompt the userif [ -z"$token" ]; thenecho"Enter your GitHub token:"read-stokenfi# Create or update the Kubernetes secretkubectldeletesecretgithub-token-nkubiya $dry_run_flag &>/dev/nullkubectlcreatesecretgenericgithub-token-nkubiya--from-literal=gh-token=$token $dry_run_flag# Define the patch contentpatch=$(cat<<EOFspec:template: spec: containers: - name: tool-manager env: - name: TOOLS_GH_TOKEN valueFrom: secretKeyRef: name: github-token key: gh-tokenEOF)# Apply the patch to the deploymentkubectlpatchdeployment-nkubiyatool-manager--patch"$patch" $dry_run_flag# Optionally restart the deployment if not in dry-run modeif [ -z"$dry_run_flag" ]; thenkubectlrolloutrestartdeployment-nkubiyatool-managerfi
The script will ask for the GitHub token if not provided (interactive mode).
The GitHub token can also be provided as an argument.
# To run normally with a GitHub token as an argument:./script.sh<your-github-token># To run in dry-run mode:./script.sh--dry-run<your-github-token># To display the help message:./script.sh--help