From 3efa3d32d2511b386c7d4be4422ee9f11d0b99f4 Mon Sep 17 00:00:00 2001 From: Jonathan MacMillan Date: Fri, 24 Mar 2017 17:29:12 -0700 Subject: [PATCH] [Federation] Create a unique label and label selector for each replica set created by the replica sets E2E test. --- test/e2e_federation/BUILD | 1 + test/e2e_federation/replicaset.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/e2e_federation/BUILD b/test/e2e_federation/BUILD index 2fecaefc4a8..94545987d60 100644 --- a/test/e2e_federation/BUILD +++ b/test/e2e_federation/BUILD @@ -47,6 +47,7 @@ go_library( "//vendor:k8s.io/apimachinery/pkg/util/intstr", "//vendor:k8s.io/apimachinery/pkg/util/net", "//vendor:k8s.io/apimachinery/pkg/util/rand", + "//vendor:k8s.io/apimachinery/pkg/util/uuid", "//vendor:k8s.io/apimachinery/pkg/util/wait", "//vendor:k8s.io/client-go/rest", "//vendor:k8s.io/client-go/tools/clientcmd", diff --git a/test/e2e_federation/replicaset.go b/test/e2e_federation/replicaset.go index 4dfce571f30..d3ddc25a0a3 100644 --- a/test/e2e_federation/replicaset.go +++ b/test/e2e_federation/replicaset.go @@ -35,6 +35,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/kubernetes/federation/apis/federation" fedreplicsetcontroller "k8s.io/kubernetes/federation/pkg/federation-controller/replicaset" ) @@ -477,6 +478,12 @@ func updateReplicaSetOrFail(clientset *fedclientset.Clientset, replicaset *v1bet } func newReplicaSetObj(namespace string, replicas int32, pref *federation.FederatedReplicaSetPreferences) *v1beta1.ReplicaSet { + // When the tests are run in parallel, replicasets from different tests can + // collide with each other. Prevent that by creating a unique label and + // label selector for each created replica set. + uuidString := string(uuid.NewUUID()) + rsLabel := fmt.Sprintf("myrs-%s", uuidString) + rs := &v1beta1.ReplicaSet{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespace, @@ -485,11 +492,11 @@ func newReplicaSetObj(namespace string, replicas int32, pref *federation.Federat Spec: v1beta1.ReplicaSetSpec{ Replicas: &replicas, Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"name": "myrs"}, + MatchLabels: map[string]string{"name": rsLabel}, }, Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{"name": "myrs"}, + Labels: map[string]string{"name": rsLabel}, }, Spec: v1.PodSpec{ Containers: []v1.Container{