forked from litmuschaos/litmus-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
litmus-executor.go
35 lines (28 loc) · 906 Bytes
/
litmus-executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package lib
import (
clients "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/log"
litmusexec "github.com/litmuschaos/litmus-go/pkg/utils/exec"
)
// LitmusExecutor implements the Executor interface to executing commands on pods
type LitmusExecutor struct {
ContainerName string
PodName string
Namespace string
Clients clients.ClientSets
}
// Execute executes commands on the current container in the current pod
func (executor LitmusExecutor) Execute(command Command) error {
log.Infof("Executing command: $%s", command)
execCommandDetails := litmusexec.PodDetails{}
cmd := []string{"/bin/sh", "-c", string(command)}
litmusexec.SetExecCommandAttributes(
&execCommandDetails,
executor.PodName,
executor.ContainerName,
executor.Namespace,
)
_, err := litmusexec.Exec(
&execCommandDetails, executor.Clients, cmd)
return err
}