Skip to content

Commit

Permalink
Remove unversioned federation client, clientset and versioned release…
Browse files Browse the repository at this point in the history
…_1_3 clientset and all their accesses in e2e tests. Switch everything to federation release_1_4 external client.
  • Loading branch information
madhusudancs committed Aug 10, 2016
1 parent f2d9aab commit a91182a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 115 deletions.
36 changes: 20 additions & 16 deletions test/e2e/federated-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"strconv"
"time"

"k8s.io/kubernetes/federation/apis/federation"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_3"
federationapi "k8s.io/kubernetes/federation/apis/federation/v1beta1"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/v1"
Expand Down Expand Up @@ -94,11 +94,11 @@ var _ = framework.KubeDescribe("[Feature:Federation]", func() {
createClusterObjectOrFail(f, &context)
}

var clusterList *federation.ClusterList
var clusterList *federationapi.ClusterList
By("Obtaining a list of all the clusters")
if err := wait.PollImmediate(framework.Poll, FederatedServiceTimeout, func() (bool, error) {
var err error
clusterList, err = f.FederationClientset.Federation().Clusters().List(api.ListOptions{})
clusterList, err = f.FederationClientset_1_4.Federation().Clusters().List(api.ListOptions{})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -174,10 +174,10 @@ var _ = framework.KubeDescribe("[Feature:Federation]", func() {
}

// Delete the registered clusters in the federation API server.
clusterList, err := f.FederationClientset.Federation().Clusters().List(api.ListOptions{})
clusterList, err := f.FederationClientset_1_4.Federation().Clusters().List(api.ListOptions{})
framework.ExpectNoError(err, "Error listing clusters")
for _, cluster := range clusterList.Items {
err := f.FederationClientset.Federation().Clusters().Delete(cluster.Name, &api.DeleteOptions{})
err := f.FederationClientset_1_4.Federation().Clusters().Delete(cluster.Name, &api.DeleteOptions{})
framework.ExpectNoError(err, "Error deleting cluster %q", cluster.Name)
}
})
Expand All @@ -195,20 +195,20 @@ var _ = framework.KubeDescribe("[Feature:Federation]", func() {

It("should succeed", func() {
framework.SkipUnlessFederated(f.Client)
service := createServiceOrFail(f.FederationClientset_1_3, f.Namespace.Name)
service := createServiceOrFail(f.FederationClientset_1_4, f.Namespace.Name)
By(fmt.Sprintf("Creation of service %q in namespace %q succeeded. Deleting service.", service.Name, f.Namespace.Name))
// Cleanup
err := f.FederationClientset_1_3.Services(f.Namespace.Name).Delete(service.Name, &api.DeleteOptions{})
err := f.FederationClientset_1_4.Services(f.Namespace.Name).Delete(service.Name, &api.DeleteOptions{})
framework.ExpectNoError(err, "Error deleting service %q in namespace %q", service.Name, service.Namespace)
By(fmt.Sprintf("Deletion of service %q in namespace %q succeeded.", service.Name, f.Namespace.Name))
})

It("should create matching services in underlying clusters", func() {
framework.SkipUnlessFederated(f.Client)
service := createServiceOrFail(f.FederationClientset_1_3, f.Namespace.Name)
service := createServiceOrFail(f.FederationClientset_1_4, f.Namespace.Name)
defer func() { // Cleanup
By(fmt.Sprintf("Deleting service %q in namespace %q", service.Name, f.Namespace.Name))
err := f.FederationClientset_1_3.Services(f.Namespace.Name).Delete(service.Name, &api.DeleteOptions{})
err := f.FederationClientset_1_4.Services(f.Namespace.Name).Delete(service.Name, &api.DeleteOptions{})
framework.ExpectNoError(err, "Error deleting service %q in namespace %q", service.Name, f.Namespace.Name)
}()
waitForServiceShardsOrFail(f.Namespace.Name, service, clusters)
Expand All @@ -224,7 +224,7 @@ var _ = framework.KubeDescribe("[Feature:Federation]", func() {
BeforeEach(func() {
framework.SkipUnlessFederated(f.Client)
createBackendPodsOrFail(clusters, f.Namespace.Name, FederatedServicePodName)
service = createServiceOrFail(f.FederationClientset_1_3, f.Namespace.Name)
service = createServiceOrFail(f.FederationClientset_1_4, f.Namespace.Name)
waitForServiceShardsOrFail(f.Namespace.Name, service, clusters)
})

Expand All @@ -233,7 +233,7 @@ var _ = framework.KubeDescribe("[Feature:Federation]", func() {
deleteBackendPodsOrFail(clusters, f.Namespace.Name)

if service != nil {
deleteServiceOrFail(f.FederationClientset_1_3, f.Namespace.Name, service.Name)
deleteServiceOrFail(f.FederationClientset_1_4, f.Namespace.Name, service.Name)
service = nil
} else {
By("No service to delete. Service is nil")
Expand Down Expand Up @@ -356,9 +356,9 @@ func waitForServiceShardsOrFail(namespace string, service *v1.Service, clusters
}
}

func createServiceOrFail(clientset *federation_release_1_3.Clientset, namespace string) *v1.Service {
func createService(clientset *federation_release_1_4.Clientset, namespace string) (*v1.Service, error) {
if clientset == nil || len(namespace) == 0 {
Fail(fmt.Sprintf("Internal error: invalid parameters passed to deleteServiceOrFail: clientset: %v, namespace: %v", clientset, namespace))
return nil, fmt.Errorf("Internal error: invalid parameters passed to deleteServiceOrFail: clientset: %v, namespace: %v", clientset, namespace)
}
By(fmt.Sprintf("Creating federated service %q in namespace %q", FederatedServiceName, namespace))

Expand All @@ -379,13 +379,17 @@ func createServiceOrFail(clientset *federation_release_1_3.Clientset, namespace
},
}
By(fmt.Sprintf("Trying to create service %q in namespace %q", service.Name, namespace))
_, err := clientset.Services(namespace).Create(service)
return clientset.Services(namespace).Create(service)
}

func createServiceOrFail(clientset *federation_release_1_4.Clientset, namespace string) *v1.Service {
service, err := createService(clientset, namespace)
framework.ExpectNoError(err, "Creating service %q in namespace %q", service.Name, namespace)
By(fmt.Sprintf("Successfully created federated service %q in namespace %q", FederatedServiceName, namespace))
return service
}

func deleteServiceOrFail(clientset *federation_release_1_3.Clientset, namespace string, serviceName string) {
func deleteServiceOrFail(clientset *federation_release_1_4.Clientset, namespace string, serviceName string) {
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))
}
Expand Down
17 changes: 9 additions & 8 deletions test/e2e/federation-apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"time"

. "github.com/onsi/ginkgo"
federationapi "k8s.io/kubernetes/federation/apis/federation"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
federationapi "k8s.io/kubernetes/federation/apis/federation/v1beta1"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"

Expand All @@ -40,10 +41,10 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func

// Delete registered clusters.
// This is if a test failed, it should not affect other tests.
clusterList, err := f.FederationClientset.Federation().Clusters().List(api.ListOptions{})
clusterList, err := f.FederationClientset_1_4.Federation().Clusters().List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred())
for _, cluster := range clusterList.Items {
err := f.FederationClientset.Federation().Clusters().Delete(cluster.Name, &api.DeleteOptions{})
err := f.FederationClientset_1_4.Federation().Clusters().Delete(cluster.Name, &api.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
}
})
Expand All @@ -68,14 +69,14 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func
framework.Logf("Deleting %d clusters", len(contexts))
for _, context := range contexts {
framework.Logf("Deleting cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
err := f.FederationClientset.Federation().Clusters().Delete(context.Name, &api.DeleteOptions{})
err := f.FederationClientset_1_4.Federation().Clusters().Delete(context.Name, &api.DeleteOptions{})
framework.ExpectNoError(err, fmt.Sprintf("unexpected error in deleting cluster %s: %+v", context.Name, err))
framework.Logf("Successfully deleted cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
}

// There should not be any remaining cluster.
framework.Logf("Verifying that zero clusters remain")
clusterList, err := f.FederationClientset.Federation().Clusters().List(api.ListOptions{})
clusterList, err := f.FederationClientset_1_4.Federation().Clusters().List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred())
if len(clusterList.Items) != 0 {
framework.Failf("there should not have been any remaining clusters. Found: %+v", clusterList)
Expand All @@ -86,14 +87,14 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func
})

// Verify that the cluster is marked ready.
func isReady(clusterName string, clientset *federation_internalclientset.Clientset) error {
func isReady(clusterName string, clientset *federation_release_1_4.Clientset) error {
return wait.PollImmediate(time.Second, 5*time.Minute, func() (bool, error) {
c, err := clientset.Federation().Clusters().Get(clusterName)
if err != nil {
return false, err
}
for _, condition := range c.Status.Conditions {
if condition.Type == federationapi.ClusterReady && condition.Status == api.ConditionTrue {
if condition.Type == federationapi.ClusterReady && condition.Status == v1.ConditionTrue {
return true, nil
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/federation-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package e2e
import (
"fmt"

federationapi "k8s.io/kubernetes/federation/apis/federation"
"k8s.io/kubernetes/pkg/api"
federationapi "k8s.io/kubernetes/federation/apis/federation/v1beta1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/test/e2e/framework"
)

func createClusterObjectOrFail(f *framework.Framework, context *framework.E2EContext) {
framework.Logf("Creating cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
cluster := federationapi.Cluster{
ObjectMeta: api.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: context.Name,
},
Spec: federationapi.ClusterSpec{
Expand All @@ -37,26 +37,26 @@ func createClusterObjectOrFail(f *framework.Framework, context *framework.E2ECon
ServerAddress: context.Cluster.Cluster.Server,
},
},
SecretRef: &api.LocalObjectReference{
SecretRef: &v1.LocalObjectReference{
// Note: Name must correlate with federation build script secret name,
// which currently matches the cluster name.
// See federation/cluster/common.sh:132
Name: context.Name,
},
},
}
_, err := f.FederationClientset.Federation().Clusters().Create(&cluster)
_, err := f.FederationClientset_1_4.Federation().Clusters().Create(&cluster)
framework.ExpectNoError(err, fmt.Sprintf("creating cluster: %+v", err))
framework.Logf("Successfully created cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
}

func clusterIsReadyOrFail(f *framework.Framework, context *framework.E2EContext) {
c, err := f.FederationClientset.Federation().Clusters().Get(context.Name)
c, err := f.FederationClientset_1_4.Federation().Clusters().Get(context.Name)
framework.ExpectNoError(err, fmt.Sprintf("get cluster: %+v", err))
if c.ObjectMeta.Name != context.Name {
framework.Failf("cluster name does not match input context: actual=%+v, expected=%+v", c, context)
}
err = isReady(context.Name, f.FederationClientset)
err = isReady(context.Name, f.FederationClientset_1_4)
framework.ExpectNoError(err, fmt.Sprintf("unexpected error in verifying if cluster %s is ready: %+v", context.Name, err))
framework.Logf("Cluster %s is Ready", context.Name)
}
38 changes: 7 additions & 31 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import (
release_1_4 "k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/util/sets"
clientreporestclient "k8s.io/client-go/1.4/rest"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
unversionedfederation "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset/typed/federation/unversioned"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_3"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
Expand Down Expand Up @@ -64,12 +61,7 @@ type Framework struct {
Clientset_1_3 *release_1_3.Clientset
StagingClient *release_1_4.Clientset

// TODO(mml): Remove this. We should generally use the versioned clientset.
FederationClientset *federation_internalclientset.Clientset
FederationClientset_1_3 *federation_release_1_3.Clientset
FederationClientset_1_4 *federation_release_1_4.Clientset
// TODO: remove FederationClient, all the client access must be through FederationClientset
FederationClient *unversionedfederation.FederationClient

Namespace *api.Namespace // Every test has at least one namespace
namespacesToDelete []*api.Namespace // Some tests have more than one.
Expand Down Expand Up @@ -195,22 +187,10 @@ func (f *Framework) BeforeEach() {
}

if f.federated {
if f.FederationClient == nil {
By("Creating a federated kubernetes client")
var err error
f.FederationClient, err = LoadFederationClient()
Expect(err).NotTo(HaveOccurred())
}
if f.FederationClientset == nil {
By("Creating an unversioned federation Clientset")
var err error
f.FederationClientset, err = LoadFederationClientset()
Expect(err).NotTo(HaveOccurred())
}
if f.FederationClientset_1_3 == nil {
By("Creating a release 1.3 federation Clientset")
if f.FederationClientset_1_4 == nil {
By("Creating a release 1.4 federation Clientset")
var err error
f.FederationClientset_1_3, err = LoadFederationClientset_1_3()
f.FederationClientset_1_4, err = LoadFederationClientset_1_4()
Expect(err).NotTo(HaveOccurred())
}
if f.FederationClientset_1_4 == nil {
Expand All @@ -220,7 +200,7 @@ func (f *Framework) BeforeEach() {
Expect(err).NotTo(HaveOccurred())
}
By("Waiting for federation-apiserver to be ready")
err := WaitForFederationApiserverReady(f.FederationClientset)
err := WaitForFederationApiserverReady(f.FederationClientset_1_4)
Expect(err).NotTo(HaveOccurred())
By("federation-apiserver is ready")
}
Expand Down Expand Up @@ -300,15 +280,11 @@ func (f *Framework) AfterEach() {

if f.federated {
defer func() {
if f.FederationClient == nil {
Logf("Warning: framework is marked federated, but has no federation client")
return
}
if f.FederationClientset == nil {
Logf("Warning: framework is marked federated, but has no federation clientset")
if f.FederationClientset_1_4 == nil {
Logf("Warning: framework is marked federated, but has no federation 1.4 clientset")
return
}
if err := f.FederationClient.Clusters().DeleteCollection(nil, api.ListOptions{}); err != nil {
if err := f.FederationClientset_1_4.Federation().Clusters().DeleteCollection(nil, api.ListOptions{}); err != nil {
Logf("Error: failed to delete Clusters: %+v", err)
}
}()
Expand Down
54 changes: 1 addition & 53 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ import (
"sync"
"time"

"k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
unversionedfederation "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset/typed/federation/unversioned"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_3"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
Expand Down Expand Up @@ -875,7 +872,7 @@ func WaitForDefaultServiceAccountInNamespace(c *client.Client, namespace string)

// WaitForFederationApiserverReady waits for the federation apiserver to be ready.
// It tests the readiness by sending a GET request and expecting a non error response.
func WaitForFederationApiserverReady(c *federation_internalclientset.Clientset) error {
func WaitForFederationApiserverReady(c *federation_release_1_4.Clientset) error {
return wait.PollImmediate(time.Second, 1*time.Minute, func() (bool, error) {
_, err := c.Federation().Clusters().List(api.ListOptions{})
if err != nil {
Expand Down Expand Up @@ -1757,36 +1754,6 @@ func setTimeouts(cs ...*http.Client) {
}
}

func LoadFederationClientset() (*federation_internalclientset.Clientset, error) {
config, err := LoadFederatedConfig()
if err != nil {
return nil, err
}

c, err := federation_internalclientset.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("error creating federation clientset: %v", err.Error())
}
// Set timeout for each client in the set.
setTimeouts(c.DiscoveryClient.Client, c.FederationClient.Client, c.CoreClient.Client)
return c, nil
}

func LoadFederationClientset_1_3() (*federation_release_1_3.Clientset, error) {
config, err := LoadFederatedConfig()
if err != nil {
return nil, err
}

c, err := federation_release_1_3.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("error creating federation clientset: %v", err.Error())
}
// Set timeout for each client in the set.
setTimeouts(c.DiscoveryClient.Client, c.FederationClient.Client, c.CoreClient.Client)
return c, nil
}

func LoadFederationClientset_1_4() (*federation_release_1_4.Clientset, error) {
config, err := LoadFederatedConfig()
if err != nil {
Expand All @@ -1802,25 +1769,6 @@ func LoadFederationClientset_1_4() (*federation_release_1_4.Clientset, error) {
return c, nil
}

func loadFederationClientFromConfig(config *restclient.Config) (*unversionedfederation.FederationClient, error) {
c, err := unversionedfederation.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("error creating client: %v", err.Error())
}
if c.Client.Timeout == 0 {
c.Client.Timeout = SingleCallTimeout
}
return c, nil
}

func LoadFederationClient() (*unversionedfederation.FederationClient, error) {
config, err := LoadFederatedConfig()
if err != nil {
return nil, err
}
return loadFederationClientFromConfig(config)
}

func LoadClient() (*client.Client, error) {
config, err := LoadConfig()
if err != nil {
Expand Down

0 comments on commit a91182a

Please sign in to comment.