-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8sapi.go
64 lines (53 loc) · 1.88 KB
/
k8sapi.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package k8sapi
import (
"io"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"github.com/argoproj/argo/errors"
)
type K8sAPIExecutor struct {
client *k8sAPIClient
}
func NewK8sAPIExecutor(clientset *kubernetes.Clientset, config *restclient.Config, podName, namespace string) (*K8sAPIExecutor, error) {
log.Infof("Creating a K8sAPI executor")
client, err := newK8sAPIClient(clientset, config, podName, namespace)
if err != nil {
return nil, errors.InternalWrapError(err)
}
return &K8sAPIExecutor{
client: client,
}, nil
}
func (k *K8sAPIExecutor) GetFileContents(containerID string, sourcePath string) (string, error) {
return "", errors.Errorf(errors.CodeNotImplemented, "GetFileContents() is not implemented in the k8sapi executor.")
}
func (k *K8sAPIExecutor) CopyFile(containerID string, sourcePath string, destPath string) error {
return errors.Errorf(errors.CodeNotImplemented, "CopyFile() is not implemented in the k8sapi executor.")
}
func (k *K8sAPIExecutor) GetOutputStream(containerID string, combinedOutput bool) (io.ReadCloser, error) {
log.Infof("Getting output of %s", containerID)
if !combinedOutput {
log.Warn("non combined output unsupported")
}
return k.client.getLogsAsStream(containerID)
}
func (k *K8sAPIExecutor) WaitInit() error {
return nil
}
// Wait for the container to complete
func (k *K8sAPIExecutor) Wait(containerID string) error {
log.Infof("Waiting for container %s to complete", containerID)
return k.client.waitForTermination(containerID, 0)
}
// Kill kills a list of containerIDs first with a SIGTERM then with a SIGKILL after a grace period
func (k *K8sAPIExecutor) Kill(containerIDs []string) error {
log.Infof("Killing containers %s", containerIDs)
for _, containerID := range containerIDs {
err := k.client.killGracefully(containerID)
if err != nil {
return err
}
}
return nil
}