From 3fe5c2e107be0db7515c7a9969dfae838e42036c Mon Sep 17 00:00:00 2001 From: topahadzi Date: Tue, 21 Nov 2023 14:07:16 +0700 Subject: [PATCH] fix context --- chaoslib/litmus/vira/node-restart/lib/node-restart.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chaoslib/litmus/vira/node-restart/lib/node-restart.go b/chaoslib/litmus/vira/node-restart/lib/node-restart.go index eca4930..a1d4b3c 100644 --- a/chaoslib/litmus/vira/node-restart/lib/node-restart.go +++ b/chaoslib/litmus/vira/node-restart/lib/node-restart.go @@ -3,6 +3,7 @@ package lib import ( "context" "fmt" + "io/ioutil" "os" "os/exec" "os/signal" @@ -117,13 +118,17 @@ func restartNode(experimentsDetails *experimentTypes.ExperimentDetails, clients os.Exit(0) default: log.Infof("[Inject]: Restarting the %v node", experimentsDetails.TargetNode) + token, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/token") + if err != nil { + return err + } setClusterCmd := exec.Command("kubectl", "config", "set-cluster", "kubernetes", "--certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt", "--server=https://kubernetes.default.svc") if err := common.RunCLICommands(setClusterCmd, "", "", "failed to set cluster configuration", cerrors.ErrorTypeHelper); err != nil { return err } // Set credentials - setCredentialsCmd := exec.Command("kubectl", "config", "set-credentials", "sa", "--token", "$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)") + setCredentialsCmd := exec.Command("kubectl", "config", "set-credentials", "sa", "--token", string(token)) if err := common.RunCLICommands(setCredentialsCmd, "", "", "failed to set credentials", cerrors.ErrorTypeHelper); err != nil { return err }