Merge pull request #46120 from shashidharatd/federation-service-e2e-1

Automatic merge from submit-queue

Federation: create loadbalancer service in tests only if test depends on it

**What this PR does / why we need it**:
Creating LoadBalancer type of service for every test case is kind of expensive and time consuming to provision. So this PR changes the test cases to use LoadBalancer type services only when necessary.

**Which issue this PR fixes** (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #47068 

**Release note**:
```release-note
NONE
```
cc @kubernetes/sig-federation-pr-reviews 
/assign @madhusudancs
This commit is contained in:
Kubernetes Submit Queue 2017-06-07 09:13:04 -07:00 committed by GitHub
commit 335794674f
3 changed files with 46 additions and 6 deletions

View File

@ -163,7 +163,7 @@ var _ = framework.KubeDescribe("Federated ingresses [Feature:Federation]", func(
clusters = f.GetRegisteredClusters()
ns = f.FederationNamespace.Name
// create backend service
service = createServiceOrFail(f.FederationClientset, ns, FederatedIngressServiceName)
service = createLBServiceOrFail(f.FederationClientset, ns, FederatedIngressServiceName)
// create the TLS secret
secret = createTLSSecretOrFail(f.FederationClientset, ns, FederatedIngressTLSSecretName)
// wait for services objects sync

View File

@ -183,7 +183,7 @@ var _ = framework.KubeDescribe("Federated Services [Feature:Federation]", func()
backendPods = createBackendPodsOrFail(clusters, nsName, FederatedServicePodName)
service = createServiceOrFail(f.FederationClientset, nsName, FederatedServiceName)
service = createLBServiceOrFail(f.FederationClientset, nsName, FederatedServiceName)
obj, err := api.Scheme.DeepCopy(service)
// Cloning shouldn't fail. On the off-chance it does, we
// should shallow copy service to serviceShard before

View File

@ -120,6 +120,36 @@ func createService(clientset *fedclientset.Clientset, namespace, name string) (*
}
By(fmt.Sprintf("Creating federated service %q in namespace %q", name, namespace))
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: v1.ServiceSpec{
Selector: FederatedServiceLabels,
Type: v1.ServiceTypeClusterIP,
Ports: []v1.ServicePort{
{
Name: "http",
Protocol: v1.ProtocolTCP,
Port: 80,
TargetPort: intstr.FromInt(8080),
},
},
SessionAffinity: v1.ServiceAffinityNone,
},
}
By(fmt.Sprintf("Trying to create service %q in namespace %q", service.Name, namespace))
return clientset.Services(namespace).Create(service)
}
func createLBService(clientset *fedclientset.Clientset, namespace, name string) (*v1.Service, error) {
if clientset == nil || len(namespace) == 0 {
return nil, fmt.Errorf("Internal error: invalid parameters passed to createService: clientset: %v, namespace: %v", clientset, namespace)
}
By(fmt.Sprintf("Creating federated service (type: load balancer) %q in namespace %q", name, namespace))
// Tests can be run in parallel, so we need a different nodePort for
// each test.
// We add 1 to FederatedSvcNodePortLast because IntnRange's range end
@ -133,7 +163,7 @@ func createService(clientset *fedclientset.Clientset, namespace, name string) (*
},
Spec: v1.ServiceSpec{
Selector: FederatedServiceLabels,
Type: "LoadBalancer",
Type: v1.ServiceTypeLoadBalancer,
Ports: []v1.ServicePort{
{
Name: "http",
@ -146,6 +176,7 @@ func createService(clientset *fedclientset.Clientset, namespace, name string) (*
SessionAffinity: v1.ServiceAffinityNone,
},
}
By(fmt.Sprintf("Trying to create service %q in namespace %q", service.Name, namespace))
return clientset.Services(namespace).Create(service)
}
@ -157,6 +188,13 @@ func createServiceOrFail(clientset *fedclientset.Clientset, namespace, name stri
return service
}
func createLBServiceOrFail(clientset *fedclientset.Clientset, namespace, name string) *v1.Service {
service, err := createLBService(clientset, namespace, name)
framework.ExpectNoError(err, "Creating service %q in namespace %q", service.Name, namespace)
By(fmt.Sprintf("Successfully created federated service (type: load balancer) %q in namespace %q", name, namespace))
return service
}
func deleteServiceOrFail(clientset *fedclientset.Clientset, namespace string, serviceName string, orphanDependents *bool) {
if clientset == nil || len(namespace) == 0 || len(serviceName) == 0 {
Fail(fmt.Sprintf("Internal error: invalid parameters passed to deleteServiceOrFail: clientset: %v, namespace: %v, service: %v", clientset, namespace, serviceName))
@ -209,9 +247,11 @@ func cleanupServiceShardsAndProviderResources(namespace string, service *v1.Serv
if err != nil {
framework.Logf("Failed to delete service %q in namespace %q, in cluster %q: %v", service.Name, namespace, name, err)
}
err = cleanupServiceShardLoadBalancer(name, cSvc, fedframework.FederatedDefaultTestTimeout)
if err != nil {
framework.Logf("Failed to delete cloud provider resources for service %q in namespace %q, in cluster %q", service.Name, namespace, name)
if service.Spec.Type == v1.ServiceTypeLoadBalancer {
err = cleanupServiceShardLoadBalancer(name, cSvc, fedframework.FederatedDefaultTestTimeout)
if err != nil {
framework.Logf("Failed to delete cloud provider resources for service %q in namespace %q, in cluster %q, err: %v", service.Name, namespace, name, err)
}
}
}
}