-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to guide developers through setting up their environment t…
…o allow locally debugging the Kubernetes Agent (#1007) * Add initial script with changes * add comment * Update setup-k8s-agent-for-local-debug.sh Co-authored-by: Kevin Tchang <kevin.tchang@octopus.com> * address code review comments * Add documentation about debugging in the read me --------- Co-authored-by: Kevin Tchang <kevin.tchang@octopus.com>
- Loading branch information
Showing
10 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
name: k8s-agent-debug-cluster | ||
nodes: | ||
- role: control-plane | ||
extraMounts: | ||
- hostPath: /tmp/k8s-agent-debug-vol | ||
containerPath: /k8s-agent-debug-vol |
28 changes: 28 additions & 0 deletions
28
k8s-agent-debug-cluster-config/launchSettings.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"profiles": { | ||
"Octopus Kubernetes Agent": { | ||
"commandName": "Project", | ||
"commandLineArgs": "agent --instance Tentacle --noninteractive", | ||
"environmentVariables": { | ||
"ACCEPT_EULA": "Y", | ||
"OCTOPUS__K8STENTACLE__NAMESPACE": "octopus-agent-<agent-name>", | ||
"OCTOPUS__K8STENTACLE__PODSERVICEACCOUNTNAME": "octopus-agent-scripts", | ||
"OCTOPUS__K8STENTACLE__PODVOLUMECLAIMNAME": "octopus-agent-<agent-name>-pvc", | ||
"OCTOPUS__K8STENTACLE__HELMRELEASENAME": "<agent-name>", | ||
"OCTOPUS__K8STENTACLE__HELMCHARTVERSION": "2.4.0", | ||
"OCTOPUS__K8STENTACLE__DISABLEAUTOPODCLEANUP": "false", | ||
"OCTOPUS__K8STENTACLE__DISABLEPODEVENTSINTASKLOG": "false", | ||
"OCTOPUS__TENTACLE__LOGLEVEL": "Info", | ||
"TentacleHome": "/tmp/k8s-agent-debug-vol", | ||
"TentacleApplications": "/tmp/k8s-agent-debug-vol/Applications", | ||
"TentaclePollingConnectionCount": "5", | ||
"OCTOPUS__K8STENTACLE__ENABLEMETRICSCAPTURE": "false", | ||
"OCTOPUS__K8STENTACLE__PERSISTENTVOLUMESIZE": "10Gi", | ||
"KUBECONFIG": "<kube-config>", | ||
"DefaultLogDirectory": "/tmp/k8s-agent-debug-vol/logs", | ||
"BOOTSTRAPRUNNEREXECUTABLEPATH": "/tmp/k8s-agent-debug-vol/bootstrapRunner", | ||
"OCTOPUS__K8STENTACLE__PODRESOURCEJSON": "{\"requests\":{\"cpu\":\"25m\",\"memory\":\"100Mi\"}}" | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
k8s-agent-debug-cluster-config/local-persistent-volume.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: v1 | ||
kind: PersistentVolume | ||
metadata: | ||
name: local-pv | ||
spec: | ||
capacity: | ||
storage: 10Gi | ||
accessModes: | ||
- ReadWriteMany | ||
persistentVolumeReclaimPolicy: Retain | ||
storageClassName: local-storage | ||
local: | ||
path: /k8s-agent-debug-vol | ||
nodeAffinity: | ||
required: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: kubernetes.io/hostname | ||
operator: In | ||
values: | ||
- k8s-agent-debug-cluster-control-plane |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: StorageClass | ||
apiVersion: storage.k8s.io/v1 | ||
metadata: | ||
name: local-storage | ||
provisioner: kubernetes.io/no-provisioner | ||
volumeBindingMode: WaitForFirstConsumer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
echo "This script will create a kind cluster configured for debugging the k8s agent locally in Rider" | ||
echo "NOTE: This has only been tested on MacOS and for agents running as deployment targets." | ||
echo "Requirements: Docker Desktop, Kind CLI, Go CLI, Rider" | ||
echo "continue? Y/n" | ||
|
||
ans=Y | ||
read -r ans | ||
|
||
if [ -n "$ans" ] && [ "$ans" != "Y" ] && [ "$ans" != "y" ]; then | ||
exit 0 | ||
fi | ||
|
||
echo "" | ||
echo "" | ||
echo "🏗️ - Installing kind cluster with name \"kind-k8s-agent-debug-cluster\"" | ||
kind create cluster --config k8s-agent-debug-cluster-config/k8s-agent-debug-cluster.yaml | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "" | ||
echo "" | ||
echo "❗ - Failed to create kind cluster, please check errors above. Aborting." | ||
exit -1 | ||
fi | ||
|
||
echo "🏗️ - Adding local storage class to kind cluster called \"local-storage\"" | ||
kubectl apply -f k8s-agent-debug-cluster-config/local-storage-class.yaml | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "" | ||
echo "" | ||
echo "❗ - Failed to create local storage class. Aborting." | ||
exit -1 | ||
fi | ||
|
||
echo "🏗️ - Adding local persistent volume to kind cluster" | ||
kubectl apply -f k8s-agent-debug-cluster-config/local-persistent-volume.yaml | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "❗ - Failed to create local persistent volume. Aborting." | ||
exit -1 | ||
fi | ||
|
||
echo "🏗️ - Building bootstrap runner" | ||
env GOOS=linux go build -C docker/kubernetes-agent-tentacle/bootstrapRunner -ldflags "-s -w" -o "/tmp/k8s-agent-debug-vol/bootstrapRunner" | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "" | ||
echo "" | ||
echo "❗ - Failed to build bootstrap runner. Aborting." | ||
exit -1 | ||
fi | ||
|
||
echo "" | ||
echo "" | ||
echo "The cluster is ready! 👌" | ||
printf "Now generate the k8s agent helm command from your Octopus instance:\n- ADD \"local-storage\" as the storage class for your agent.\n- CHOOSE \"Docker Desktop\" in the DEV dropdown list.\n- RUN the install script against the new kind cluster (called \"kind-k8s-agent-debug-cluster\").\n\nWhen the installation is complete and the agent has successfully completed a health check, continue executing this script!" | ||
|
||
while [ -z "$agentName" ] | ||
do | ||
echo "" | ||
echo "" | ||
echo "❔ - What name did you give your agent?" | ||
|
||
read -r agentName | ||
done | ||
|
||
echo "" | ||
echo "" | ||
echo "🏗️ - Scaling down agent \"$agentName\" deployment in cluster" | ||
kubectl scale --replicas=0 deployment/octopus-agent-tentacle -n "octopus-agent-$agentName" | ||
echo "🏗️ - Changing the tentacle config to use localhost" | ||
configMapContents=`kubectl get configmap tentacle-config -n "octopus-agent-$agentName" -o yaml` | ||
configMapContents="${configMapContents//host\.docker\.internal/localhost}" | ||
echo "🏗️ - Changing home dir and applications dir to use /tmp/k8s-agent-debug-vol" | ||
configMapContents="${configMapContents//\/octopus//tmp/k8s-agent-debug-vol}" | ||
echo "$configMapContents" | kubectl apply -f - | ||
|
||
if [ -z "$KUBECONFIG" ]; then | ||
kubeConfig=~/.kube/config | ||
else | ||
kubeConfig="$KUBECONFIG" | ||
fi | ||
|
||
echo "" | ||
echo "" | ||
echo "🏗️ - Copying launch settings for Octopus.Tentacle project" | ||
launchSettings=`cat k8s-agent-debug-cluster-config/launchSettings.template.json` | ||
launchSettings=${launchSettings//\<agent-name\>/"$agentName"} | ||
launchSettings=${launchSettings//\<kube-config\>/"$kubeConfig"} | ||
echo "$launchSettings" > "./source/Octopus.Tentacle/Properties/launchSettings.json" | ||
|
||
echo "" | ||
echo "" | ||
echo "Done! 🚀" | ||
echo "" | ||
echo "You can now run/debug the Agent using the launch settings in Octopus.Tentacle/Properties/launchSettings.json." | ||
echo "Check the run configuration in Rider to ensure that you're running it with the correct .net Framework version (net8.0)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters