(labelSelector, containerName, namespace string, command []string)
| 59 | } |
| 60 | |
| 61 | func (k *KubeHelper) ExecByContainer(labelSelector, containerName, namespace string, command []string) (string, error) { |
| 62 | targetOptions := targetselector.NewOptionsFromFlags(containerName, labelSelector, nil, namespace, ""). |
| 63 | WithTimeout(120). |
| 64 | WithWaitingStrategy(targetselector.NewUntilNewestRunningWaitingStrategy(time.Second * 2)) |
| 65 | |
| 66 | globalTargetSelector := targetselector.NewTargetSelector(targetOptions) |
| 67 | container, err := globalTargetSelector.SelectSingleContainer(context.TODO(), k.client, log.Discard) |
| 68 | if err != nil { |
| 69 | return "", err |
| 70 | } |
| 71 | |
| 72 | stdout, stderr, err := k.client.ExecBuffered(context.TODO(), container.Pod, container.Container.Name, command, nil) |
| 73 | if err != nil { |
| 74 | return "", fmt.Errorf("exec error: %v %s", err, string(stderr)) |
| 75 | } |
| 76 | |
| 77 | return string(stdout), nil |
| 78 | } |
| 79 | |
| 80 | func (k *KubeHelper) CreateNamespace(name string) (string, error) { |
| 81 | name = strings.ToLower(name + "-" + randutil.GenerateRandomString(5)) |
no test coverage detected