Skip to content

Commit

Permalink
fix context
Browse files Browse the repository at this point in the history
  • Loading branch information
topahadzi committed Nov 21, 2023
1 parent 1fa4955 commit 3fe5c2e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion chaoslib/litmus/vira/node-restart/lib/node-restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3fe5c2e

Please sign in to comment.