Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: replace some hardcoded vars and remove unused functions #44842

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/common/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ var _ = framework.KubeDescribe("Pods", func() {
Containers: []v1.Container{
{
Name: "srv",
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: framework.ServeHostnameImage,
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
},
},
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ var _ = framework.KubeDescribe("Daemon set [Serial]", func() {

f = framework.NewDefaultFramework("daemonsets")

image := "gcr.io/google_containers/serve_hostname:v1.4"
redisImage := "gcr.io/k8s-testimages/redis:e2e"
image := framework.ServeHostnameImage
dsName := "daemon-set"

var ns string
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/etcd_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func etcdFailTest(f *framework.Framework, failCommand, fixCommand string) {

checkExistingRCRecovers(f)

testReplicationControllerServeImageOrFail(f, "basic", "gcr.io/google_containers/serve_hostname:v1.4")
testReplicationControllerServeImageOrFail(f, "basic", framework.ServeHostnameImage)
}

// For this duration, etcd will be failed by executing a failCommand on the master.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = framework.KubeDescribe("Events", func() {
Containers: []v1.Container{
{
Name: "p",
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: framework.ServeHostnameImage,
Ports: []v1.ContainerPort{{ContainerPort: 80}},
},
},
Expand Down
11 changes: 0 additions & 11 deletions test/e2e/framework/metrics_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,6 @@ func LogSuspiciousLatency(latencyData []PodLatencyData, latencyDataLag []PodLate
float64(nodeCount)/(latencyDataLag[len(latencyDataLag)-1].Latency.Minutes()))
}

// testMaximumLatencyValue verifies the highest latency value is less than or equal to
// the given time.Duration. Since the arrays are sorted we are looking at the last
// element which will always be the highest. If the latency is higher than the max Failf
// is called.
func testMaximumLatencyValue(latencies []PodLatencyData, max time.Duration, name string) {
highestLatency := latencies[len(latencies)-1]
if !(highestLatency.Latency <= max) {
Failf("%s were not all under %s: %#v", name, max.String(), latencies)
}
}

func PrintLatencies(latencies []PodLatencyData, header string) {
metrics := ExtractLatencyMetrics(latencies)
Logf("10%% %s: %v", header, latencies[(len(latencies)*9)/10:])
Expand Down
23 changes: 0 additions & 23 deletions test/e2e/framework/nodes_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,6 @@ func nodeUpgradeGCE(rawV, img string) error {
return err
}

func cleanupNodeUpgradeGCE(tmplBefore string) {
Logf("Cleaning up any unused node templates")
tmplAfter, err := MigTemplate()
if err != nil {
Logf("Could not get node template post-upgrade; may have leaked template %s", tmplBefore)
return
}
if tmplBefore == tmplAfter {
// The node upgrade failed so there's no need to delete
// anything.
Logf("Node template %s is still in use; not cleaning up", tmplBefore)
return
}
Logf("Deleting node template %s", tmplBefore)
if _, _, err := retryCmd("gcloud", "compute", "instance-templates",
fmt.Sprintf("--project=%s", TestContext.CloudConfig.ProjectID),
"delete",
tmplBefore); err != nil {
Logf("gcloud compute instance-templates delete %s call failed with err: %v", tmplBefore, err)
Logf("May have leaked instance template %q", tmplBefore)
}
}

func nodeUpgradeGKE(v string, img string) error {
Logf("Upgrading nodes to version %q and image %q", v, img)
args := []string{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/service_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ func StartServeHostnameService(c clientset.Interface, internalClient internalcli
config := testutils.RCConfig{
Client: c,
InternalClient: internalClient,
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: ServeHostnameImage,
Name: name,
Namespace: ns,
PollInterval: 3 * time.Second,
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/framework/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ import (
)

const (
serveHostnameImage = "gcr.io/google_containers/serve_hostname:v1.4"
resizeNodeReadyTimeout = 2 * time.Minute
resizeNodeNotReadyTimeout = 2 * time.Minute
nodeReadinessTimeout = 3 * time.Minute
podNotReadyTimeout = 1 * time.Minute
podReadyTimeout = 2 * time.Minute
testPort = 9376
)

func ResizeGroup(group string, size int32) error {
Expand Down
10 changes: 0 additions & 10 deletions test/e2e/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,6 @@ func RegisterNodeFlags() {
flag.BoolVar(&TestContext.PrepullImages, "prepull-images", true, "If true, prepull images so image pull failures do not cause test failures.")
}

// overwriteFlagsWithViperConfig finds and writes values to flags using viper as input.
func overwriteFlagsWithViperConfig() {
viperFlagSetter := func(f *flag.Flag) {
if viper.IsSet(f.Name) {
f.Value.Set(viper.GetString(f.Name))
}
}
flag.VisitAll(viperFlagSetter)
}

// ViperizeFlags sets up all flag and config processing. Future configuration info should be added to viper, not to flags.
func ViperizeFlags() {

Expand Down
30 changes: 3 additions & 27 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ const (

// TODO(justinsb): Avoid hardcoding this.
awsMasterIP = "172.20.0.9"

// Serve hostname image name
ServeHostnameImage = "gcr.io/google_containers/serve_hostname:v1.4"
)

var (
Expand Down Expand Up @@ -407,9 +410,6 @@ func SkipIfMissingResource(clientPool dynamic.ClientPool, gvr schema.GroupVersio
// ProvidersWithSSH are those providers where each node is accessible with SSH
var ProvidersWithSSH = []string{"gce", "gke", "aws", "local"}

// providersWithMasterSSH are those providers where master node is accessible with SSH
var providersWithMasterSSH = []string{"gce", "gke", "kubemark", "aws", "local"}

type podCondition func(pod *v1.Pod) (bool, error)

// logPodStates logs basic info of provided pods for debugging.
Expand Down Expand Up @@ -1377,30 +1377,6 @@ func WaitForPodSuccessInNamespaceSlow(c clientset.Interface, podName string, nam
return waitForPodSuccessInNamespaceTimeout(c, podName, namespace, slowPodStartTimeout)
}

// waitForRCPodOnNode returns the pod from the given replication controller (described by rcName) which is scheduled on the given node.
// In case of failure or too long waiting time, an error is returned.
func waitForRCPodOnNode(c clientset.Interface, ns, rcName, node string) (*v1.Pod, error) {
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": rcName}))
var p *v1.Pod = nil
err := wait.PollImmediate(10*time.Second, 5*time.Minute, func() (bool, error) {
Logf("Waiting for pod %s to appear on node %s", rcName, node)
options := metav1.ListOptions{LabelSelector: label.String()}
pods, err := c.Core().Pods(ns).List(options)
if err != nil {
return false, err
}
for _, pod := range pods.Items {
if pod.Spec.NodeName == node {
Logf("Pod %s found on node %s", pod.Name, node)
p = &pod
return true, nil
}
}
return false, nil
})
return p, err
}

// WaitForRCToStabilize waits till the RC has a matching generation/replica count between spec and status.
func WaitForRCToStabilize(c clientset.Interface, ns, name string, timeout time.Duration) error {
options := metav1.ListOptions{FieldSelector: fields.Set{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/network_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func podOnNode(podName, nodeName string, image string) *v1.Pod {
}

func newPodOnNode(c clientset.Interface, namespace, podName, nodeName string) error {
pod, err := c.Core().Pods(namespace).Create(podOnNode(podName, nodeName, serveHostnameImage))
pod, err := c.Core().Pods(namespace).Create(podOnNode(podName, nodeName, framework.ServeHostnameImage))
if err == nil {
framework.Logf("Created pod %s on node %s", pod.ObjectMeta.Name, nodeName)
} else {
Expand Down
27 changes: 12 additions & 15 deletions test/e2e/perf/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ import (
)

const (
smallGroupSize = 5
mediumGroupSize = 30
bigGroupSize = 250
smallGroupName = "load-small"
mediumGroupName = "load-medium"
bigGroupName = "load-big"
smallGroupBatchSize = 30
mediumGroupBatchSize = 5
bigGroupBatchSize = 1
smallGroupSize = 5
mediumGroupSize = 30
bigGroupSize = 250
smallGroupName = "load-small"
mediumGroupName = "load-medium"
bigGroupName = "load-big"
// We start RCs/Services/pods/... in different namespace in this test.
// nodeCountPerNamespace determines how many namespaces we will be using
// depending on the number of nodes in the underlying cluster.
Expand Down Expand Up @@ -143,16 +140,16 @@ var _ = framework.KubeDescribe("Load capacity", func() {
loadTests := []Load{
// The container will consume 1 cpu and 512mb of memory.
{podsPerNode: 3, image: "jess/stress", command: []string{"stress", "-c", "1", "-m", "2"}, kind: api.Kind("ReplicationController")},
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: api.Kind("ReplicationController")},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: api.Kind("ReplicationController")},
// Tests for other resource types
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: extensions.Kind("Deployment")},
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: batch.Kind("Job")},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: extensions.Kind("Deployment")},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: batch.Kind("Job")},
// Test scheduling when daemons are preset
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: api.Kind("ReplicationController"), daemonsPerNode: 2},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: api.Kind("ReplicationController"), daemonsPerNode: 2},
// Test with secrets
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: extensions.Kind("Deployment"), secretsPerPod: 2},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: extensions.Kind("Deployment"), secretsPerPod: 2},
// Special test case which randomizes created resources
{podsPerNode: 30, image: "gcr.io/google_containers/serve_hostname:v1.4", kind: randomKind},
{podsPerNode: 30, image: framework.ServeHostnameImage, kind: randomKind},
}

for _, testArg := range loadTests {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = framework.KubeDescribe("ReplicationController", func() {
f := framework.NewDefaultFramework("replication-controller")

It("should serve a basic image on each replica with a public image [Conformance]", func() {
testReplicationControllerServeImageOrFail(f, "basic", "gcr.io/google_containers/serve_hostname:v1.4")
testReplicationControllerServeImageOrFail(f, "basic", framework.ServeHostnameImage)
})

It("should serve a basic image on each replica with a private image", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = framework.KubeDescribe("ReplicaSet", func() {
f := framework.NewDefaultFramework("replicaset")

It("should serve a basic image on each replica with a public image [Conformance]", func() {
testReplicaSetServeImageOrFail(f, "basic", "gcr.io/google_containers/serve_hostname:v1.4")
testReplicaSetServeImageOrFail(f, "basic", framework.ServeHostnameImage)
})

It("should serve a basic image on each replica with a private image", func() {
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/resize_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ import (
)

const (
serveHostnameImage = "gcr.io/google_containers/serve_hostname:v1.4"
resizeNodeReadyTimeout = 2 * time.Minute
resizeNodeNotReadyTimeout = 2 * time.Minute
nodeReadinessTimeout = 3 * time.Minute
podNotReadyTimeout = 1 * time.Minute
podReadyTimeout = 2 * time.Minute
testPort = 9376
resizeNodeReadyTimeout = 2 * time.Minute
nodeReadinessTimeout = 3 * time.Minute
podNotReadyTimeout = 1 * time.Minute
podReadyTimeout = 2 * time.Minute
testPort = 9376
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need gofmt in our e2e code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already run

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sorry, it just seems not gofmt'd :)
Update: I reviewed the PR on my phone. The code format on phone looks different from that on PC...

)

func svcByName(name string, port int) *v1.Service {
Expand Down Expand Up @@ -68,7 +66,7 @@ func newSVCByName(c clientset.Interface, ns, name string) error {
func newRCByName(c clientset.Interface, ns, name string, replicas int32, gracePeriod *int64) (*v1.ReplicationController, error) {
By(fmt.Sprintf("creating replication controller %s", name))
return c.Core().ReplicationControllers(ns).Create(framework.RcByNamePort(
name, replicas, serveHostnameImage, 9376, v1.ProtocolTCP, map[string]string{}, gracePeriod))
name, replicas, framework.ServeHostnameImage, 9376, v1.ProtocolTCP, map[string]string{}, gracePeriod))
}

func resizeRC(c clientset.Interface, ns, name string, replicas int32) error {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/ubernetes_lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = framework.KubeDescribe("Multi-AZ Clusters", func() {
f := framework.NewDefaultFramework("multi-az")
var zoneCount int
var err error
image := "gcr.io/google_containers/serve_hostname:v1.4"
image := framework.ServeHostnameImage
BeforeEach(func() {
framework.SkipUnlessProviderIs("gce", "gke", "aws")
if zoneCount <= 0 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/upgrades/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (DaemonSetUpgradeTest) Name() string { return "daemonset-upgrade" }
func (t *DaemonSetUpgradeTest) Setup(f *framework.Framework) {
daemonSetName := "ds1"
labelSet := map[string]string{"ds-name": daemonSetName}
image := "gcr.io/google_containers/serve_hostname:v1.4"
image := framework.ServeHostnameImage

ns := f.Namespace

Expand Down
2 changes: 1 addition & 1 deletion test/e2e_federation/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func createDaemonSetOrFail(clientset *fedclientset.Clientset, namespace string)
Containers: []v1.Container{
{
Name: "container1",
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: framework.ServeHostnameImage,
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e_node/container_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = framework.KubeDescribe("Container Manager Misc [Serial]", func() {
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: framework.ServeHostnameImage,
Name: podName,
},
},
Expand Down
1 change: 1 addition & 0 deletions test/soak/cauldron/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
deps = [
"//pkg/api:go_default_library",
"//pkg/client/clientset_generated/internalclientset:go_default_library",
"//test/e2e/framework:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion test/soak/cauldron/cauldron.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
restclient "k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/api"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/test/e2e/framework"
)

var (
Expand Down Expand Up @@ -184,7 +185,7 @@ func main() {
Containers: []api.Container{
{
Name: "serve-hostname",
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: framework.ServeHostnameImage,
Ports: []api.ContainerPort{{ContainerPort: 9376}},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/soak/serve_hostnames/serve_hostnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func main() {
Containers: []v1.Container{
{
Name: "serve-hostname",
Image: "gcr.io/google_containers/serve_hostname:v1.4",
Image: e2e.ServeHostnameImage,
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
},
},
Expand Down