-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
kubelet.go
62 lines (51 loc) · 1.9 KB
/
kubelet.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
package kubelet
import (
"context"
"io"
"time"
log "github.com/sirupsen/logrus"
"github.com/argoproj/argo-workflows/v3/errors"
)
type KubeletExecutor struct {
cli *kubeletClient
}
func NewKubeletExecutor(namespace, podName string) (*KubeletExecutor, error) {
cli, err := newKubeletClient(namespace, podName)
if err != nil {
return nil, errors.InternalWrapError(err)
}
return &KubeletExecutor{
cli: cli,
}, nil
}
func (k *KubeletExecutor) GetFileContents(containerName string, sourcePath string) (string, error) {
return "", errors.Errorf(errors.CodeNotImplemented, "GetFileContents() is not implemented in the kubelet executor.")
}
func (k *KubeletExecutor) CopyFile(containerName string, sourcePath string, destPath string, compressionLevel int) error {
return errors.Errorf(errors.CodeNotImplemented, "CopyFile() is not implemented in the kubelet executor.")
}
func (k *KubeletExecutor) GetOutputStream(ctx context.Context, containerName string, combinedOutput bool) (io.ReadCloser, error) {
if !combinedOutput {
log.Warn("non combined output unsupported")
}
return k.cli.GetLogStream(containerName)
}
// Wait for the container to complete
func (k *KubeletExecutor) Wait(ctx context.Context, containerNames []string) error {
return k.cli.WaitForTermination(ctx, containerNames, 0)
}
// Kill kills a list of containers first with a SIGTERM then with a SIGKILL after a grace period
func (k *KubeletExecutor) Kill(ctx context.Context, containerNames []string, terminationGracePeriodDuration time.Duration) error {
return k.cli.KillGracefully(ctx, containerNames, terminationGracePeriodDuration)
}
func (k *KubeletExecutor) ListContainerNames(ctx context.Context) ([]string, error) {
pod, err := k.cli.getPod()
if err != nil {
return nil, err
}
var containerNames []string
for _, c := range pod.Status.ContainerStatuses {
containerNames = append(containerNames, c.Name)
}
return containerNames, nil
}