mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #76028 from SataQiu/fix-e2e-framework-20190403
Fix golint failures of e2e/framework/rc_util.go
This commit is contained in:
commit
7849396966
@ -21,7 +21,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
"github.com/onsi/ginkgo"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -124,6 +124,10 @@ func ScaleRCByLabels(clientset clientset.Interface, scalesGetter scaleclient.Sca
|
|||||||
|
|
||||||
type updateRcFunc func(d *v1.ReplicationController)
|
type updateRcFunc func(d *v1.ReplicationController)
|
||||||
|
|
||||||
|
// UpdateReplicationControllerWithRetries retries updating the given rc on conflict with the following steps:
|
||||||
|
// 1. Get latest resource
|
||||||
|
// 2. applyUpdate
|
||||||
|
// 3. Update the resource
|
||||||
func UpdateReplicationControllerWithRetries(c clientset.Interface, namespace, name string, applyUpdate updateRcFunc) (*v1.ReplicationController, error) {
|
func UpdateReplicationControllerWithRetries(c clientset.Interface, namespace, name string, applyUpdate updateRcFunc) (*v1.ReplicationController, error) {
|
||||||
var rc *v1.ReplicationController
|
var rc *v1.ReplicationController
|
||||||
var updateErr error
|
var updateErr error
|
||||||
@ -152,12 +156,15 @@ func DeleteRCAndWaitForGC(c clientset.Interface, ns, name string) error {
|
|||||||
return DeleteResourceAndWaitForGC(c, api.Kind("ReplicationController"), ns, name)
|
return DeleteResourceAndWaitForGC(c, api.Kind("ReplicationController"), ns, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScaleRC scales Replication Controller to be desired size.
|
||||||
func ScaleRC(clientset clientset.Interface, scalesGetter scaleclient.ScalesGetter, ns, name string, size uint, wait bool) error {
|
func ScaleRC(clientset clientset.Interface, scalesGetter scaleclient.ScalesGetter, ns, name string, size uint, wait bool) error {
|
||||||
return ScaleResource(clientset, scalesGetter, ns, name, size, wait, api.Kind("ReplicationController"), api.Resource("replicationcontrollers"))
|
return ScaleResource(clientset, scalesGetter, ns, name, size, wait, api.Kind("ReplicationController"), api.Resource("replicationcontrollers"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunRC Launches (and verifies correctness) of a Replication Controller
|
||||||
|
// and will wait for all pods it spawns to become "Running".
|
||||||
func RunRC(config testutils.RCConfig) error {
|
func RunRC(config testutils.RCConfig) error {
|
||||||
By(fmt.Sprintf("creating replication controller %s in namespace %s", config.Name, config.Namespace))
|
ginkgo.By(fmt.Sprintf("creating replication controller %s in namespace %s", config.Name, config.Namespace))
|
||||||
config.NodeDumpFunc = DumpNodeDebugInfo
|
config.NodeDumpFunc = DumpNodeDebugInfo
|
||||||
config.ContainerDumpFunc = LogFailedContainers
|
config.ContainerDumpFunc = LogFailedContainers
|
||||||
return testutils.RunRC(config)
|
return testutils.RunRC(config)
|
||||||
@ -180,10 +187,9 @@ func WaitForReplicationController(c clientset.Interface, namespace, name string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
Logf("Get ReplicationController %s in namespace %s failed (%v).", name, namespace, err)
|
Logf("Get ReplicationController %s in namespace %s failed (%v).", name, namespace, err)
|
||||||
return !exist, nil
|
return !exist, nil
|
||||||
} else {
|
|
||||||
Logf("ReplicationController %s in namespace %s found.", name, namespace)
|
|
||||||
return exist, nil
|
|
||||||
}
|
}
|
||||||
|
Logf("ReplicationController %s in namespace %s found.", name, namespace)
|
||||||
|
return exist, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stateMsg := map[bool]string{true: "to appear", false: "to disappear"}
|
stateMsg := map[bool]string{true: "to appear", false: "to disappear"}
|
||||||
@ -249,13 +255,13 @@ func ValidateController(c clientset.Interface, containerImage string, replicas i
|
|||||||
|
|
||||||
getImageTemplate := fmt.Sprintf(`--template={{if (exists . "spec" "containers")}}{{range .spec.containers}}{{if eq .name "%s"}}{{.image}}{{end}}{{end}}{{end}}`, containername)
|
getImageTemplate := fmt.Sprintf(`--template={{if (exists . "spec" "containers")}}{{range .spec.containers}}{{if eq .name "%s"}}{{.image}}{{end}}{{end}}{{end}}`, containername)
|
||||||
|
|
||||||
By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
|
ginkgo.By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
|
||||||
waitLoop:
|
waitLoop:
|
||||||
for start := time.Now(); time.Since(start) < PodStartTimeout; time.Sleep(5 * time.Second) {
|
for start := time.Now(); time.Since(start) < PodStartTimeout; time.Sleep(5 * time.Second) {
|
||||||
getPodsOutput := RunKubectlOrDie("get", "pods", "-o", "template", getPodsTemplate, "-l", testname, fmt.Sprintf("--namespace=%v", ns))
|
getPodsOutput := RunKubectlOrDie("get", "pods", "-o", "template", getPodsTemplate, "-l", testname, fmt.Sprintf("--namespace=%v", ns))
|
||||||
pods := strings.Fields(getPodsOutput)
|
pods := strings.Fields(getPodsOutput)
|
||||||
if numPods := len(pods); numPods != replicas {
|
if numPods := len(pods); numPods != replicas {
|
||||||
By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
|
ginkgo.By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var runningPods []string
|
var runningPods []string
|
||||||
|
Loading…
Reference in New Issue
Block a user