forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
58 lines (50 loc) · 1.82 KB
/
helper.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
package images
import (
"fmt"
"strings"
"time"
"github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/image/registry/imagestreamimage"
exutil "github.com/openshift/origin/test/extended/util"
"k8s.io/kubernetes/pkg/labels"
)
// GetImageLabels retrieves Docker labels from image from image repository name and
// image reference
func GetImageLabels(c client.ImageStreamImageInterface, imageRepoName, imageRef string) (map[string]string, error) {
_, imageID, err := imagestreamimage.ParseNameAndID(imageRef)
image, err := c.Get(imageRepoName, imageID)
if err != nil {
return map[string]string{}, err
}
return image.Image.DockerImageMetadata.Config.Labels, nil
}
// RunInPodContainer will run provided command in the specified pod container.
func RunInPodContainer(oc *exutil.CLI, selector labels.Selector, cmd []string) error {
pods, err := exutil.WaitForPods(oc.KubeREST().Pods(oc.Namespace()), selector, exutil.CheckPodIsRunningFn, 1, 2*time.Minute)
if err != nil {
return err
}
if len(pods) != 1 {
return fmt.Errorf("Got %d pods for selector %v, expected 1", len(pods), selector)
}
pod, err := oc.KubeREST().Pods(oc.Namespace()).Get(pods[0])
if err != nil {
return err
}
args := []string{pod.Name, "-c", pod.Spec.Containers[0].Name, "--"}
args = append(args, cmd...)
return oc.Run("exec").Args(args...).Execute()
}
// CheckPageContains makes a http request for an example application and checks
// that the result contains given string
func CheckPageContains(oc *exutil.CLI, endpoint, path, contents string) (bool, error) {
address, err := exutil.GetEndpointAddress(oc, endpoint)
if err != nil {
return false, err
}
response, err := exutil.FetchURL(fmt.Sprintf("http://%s/%s", address, path), 3*time.Minute)
if err != nil {
return false, err
}
return strings.Contains(response, contents), nil
}