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

[Federation][e2e] Move Cluster Registration to federation-up.sh #40919

Merged
merged 1 commit into from
Feb 8, 2017
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
42 changes: 21 additions & 21 deletions federation/cluster/federation-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,34 @@ function init() {
--image="${kube_registry}/hyperkube-amd64:${kube_version}"
}

# create_cluster_secrets creates the secrets containing the kubeconfigs
# of the participating clusters in the host cluster. The kubeconfigs itself
# are created while deploying clusters, i.e. when kube-up is run.
function create_cluster_secrets() {
local -r kubeconfig_dir="$(dirname ${DEFAULT_KUBECONFIG})"
local -r base_dir="${kubeconfig_dir}/federation/kubernetes-apiserver"
# join_cluster_to_federation joins the clusters in the local kubeconfig to federation. The clusters
# and their kubeconfig entries in the local kubeconfig are created while deploying clusters, i.e. when kube-up is run.
function join_cluster_to_federation() {
for cluster in $("${KUBE_ROOT}/cluster/kubectl.sh" config get-clusters |sed -n '1!p'); do
# Skip federation context
if [[ "${cluster}" == "${FEDERATION_NAME}" ]]; then
continue
fi
# Skip contexts not beginning with "federation"
if [[ "${cluster}" != federation* ]]; then
continue
fi

# Create secrets with all the kubernetes-apiserver's kubeconfigs.
for dir in $(ls "${base_dir}"); do
# We create a secret with the same name as the directory name (which is
# same as cluster name in kubeconfig).
# Massage the name so that it is valid (should not contain "_" and max 253
# chars)
name=$(echo "${dir}" | sed -e "s/_/-/g") # Replace "_" by "-"
name=${name:0:252}
kube::log::status "Creating secret with name: ${name} in namespace ${FEDERATION_NAMESPACE}"
"${KUBE_ROOT}/cluster/kubectl.sh" create secret generic ${name} --from-file="${base_dir}/${dir}/kubeconfig" --namespace="${FEDERATION_NAMESPACE}"
kube::log::status "Joining cluster with name '${cluster}' to federation with name '${FEDERATION_NAME}'"

"${KUBE_ROOT}/federation/develop/kubefed.sh" join \
"${cluster}" \
--host-cluster-context="${HOST_CLUSTER_CONTEXT}" \
--context="${FEDERATION_NAME}" \
--secret-name="${cluster//_/-}" # Replace "_" by "-"
done
}

USE_KUBEFED="${USE_KUBEFED:-}"
if [[ "${USE_KUBEFED}" == "true" ]]; then
init
# TODO(madhusudancs): Call to create_cluster_secrets and the function
# itself must be removed after implementing cluster join with kubefed
# here. This call is now required for the cluster joins in the
# BeforeEach blocks of each e2e test to work.
create_cluster_secrets

join_cluster_to_federation
else
# Read the version back from the versions file if no version is given.
readonly kube_version="$(cat ${KUBE_ROOT}/_output/federation/versions | python -c '\
Expand Down
4 changes: 1 addition & 3 deletions test/e2e_federation/federated-daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ var _ = framework.KubeDescribe("Federation daemonsets [Feature:Federation]", fun

BeforeEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
clusters = map[string]*cluster{}
registerClusters(clusters, UserAgentName, "", f)
clusters, _ = getRegisteredClusters(UserAgentName, f)
})

AfterEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
// Delete all daemonsets.
nsName := f.FederationNamespace.Name
deleteAllDaemonSetsOrFail(f.FederationClientset, nsName)
unregisterClusters(clusters, f)
})

It("should be created and deleted successfully", func() {
Expand Down
11 changes: 2 additions & 9 deletions test/e2e_federation/federated-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package e2e_federation

import (
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -71,22 +70,16 @@ var _ = framework.KubeDescribe("Federation deployments [Feature:Federation]", fu
// e2e cases for federated deployment controller
Describe("Federated Deployment", func() {
var (
clusters map[string]*cluster
federationName string
clusters map[string]*cluster
)
BeforeEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
if federationName = os.Getenv("FEDERATION_NAME"); federationName == "" {
federationName = DefaultFederationName
}
clusters = map[string]*cluster{}
registerClusters(clusters, UserAgentName, federationName, f)
clusters, _ = getRegisteredClusters(UserAgentName, f)
})

AfterEach(func() {
nsName := f.FederationNamespace.Name
deleteAllDeploymentsOrFail(f.FederationClientset, nsName)
unregisterClusters(clusters, f)
})

It("should create and update matching deployments in underlying clusters", func() {
Expand Down
4 changes: 1 addition & 3 deletions test/e2e_federation/federated-ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ var _ = framework.KubeDescribe("Federated ingresses [Feature:Federation]", func(
federationName = DefaultFederationName
}
jig = newFederationTestJig(f.FederationClientset)
clusters = map[string]*cluster{}
primaryClusterName = registerClusters(clusters, UserAgentName, federationName, f)
clusters, primaryClusterName = getRegisteredClusters(UserAgentName, f)
ns = f.FederationNamespace.Name
})

AfterEach(func() {
// Delete all ingresses.
nsName := f.FederationNamespace.Name
deleteAllIngressesOrFail(f.FederationClientset, nsName)
unregisterClusters(clusters, f)
})

It("should create and update matching ingresses in underlying clusters", func() {
Expand Down
12 changes: 1 addition & 11 deletions test/e2e_federation/federated-namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package e2e_federation

import (
"fmt"
"os"
"strings"
"time"

Expand All @@ -44,19 +43,11 @@ var _ = framework.KubeDescribe("Federation namespace [Feature:Federation]", func
f := fedframework.NewDefaultFederatedFramework("federation-namespace")

Describe("Namespace objects", func() {
var federationName string
var clusters map[string]*cluster // All clusters, keyed by cluster name

BeforeEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)

// TODO: Federation API server should be able to answer this.
if federationName = os.Getenv("FEDERATION_NAME"); federationName == "" {
federationName = DefaultFederationName
}

clusters = map[string]*cluster{}
registerClusters(clusters, UserAgentName, federationName, f)
clusters, _ = getRegisteredClusters(UserAgentName, f)
})

AfterEach(func() {
Expand All @@ -69,7 +60,6 @@ var _ = framework.KubeDescribe("Federation namespace [Feature:Federation]", func
cluster.Core().Namespaces().List,
cluster.Core().Namespaces().Delete)
}
unregisterClusters(clusters, f)
})

It("should be created and deleted successfully", func() {
Expand Down
11 changes: 2 additions & 9 deletions test/e2e_federation/federated-replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package e2e_federation

import (
"fmt"
"os"
"strings"
"time"

Expand Down Expand Up @@ -73,23 +72,17 @@ var _ = framework.KubeDescribe("Federation replicasets [Feature:Federation]", fu
// e2e cases for federated replicaset controller
Describe("Federated ReplicaSet", func() {
var (
clusters map[string]*cluster
federationName string
clusters map[string]*cluster
)
BeforeEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
if federationName = os.Getenv("FEDERATION_NAME"); federationName == "" {
federationName = DefaultFederationName
}
clusters = map[string]*cluster{}
registerClusters(clusters, UserAgentName, federationName, f)
clusters, _ = getRegisteredClusters(UserAgentName, f)
})

AfterEach(func() {
// Delete all replicasets.
nsName := f.FederationNamespace.Name
deleteAllReplicaSetsOrFail(f.FederationClientset, nsName)
unregisterClusters(clusters, f)
})

It("should create and update matching replicasets in underling clusters", func() {
Expand Down
5 changes: 1 addition & 4 deletions test/e2e_federation/federated-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,14 @@ var _ = framework.KubeDescribe("Federation secrets [Feature:Federation]", func()

BeforeEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
clusters = map[string]*cluster{}
registerClusters(clusters, UserAgentName, "", f)
clusters, _ = getRegisteredClusters(UserAgentName, f)
})

AfterEach(func() {
fedframework.SkipUnlessFederated(f.ClientSet)
// Delete all secrets.
nsName := f.FederationNamespace.Name
deleteAllSecretsOrFail(f.FederationClientset, nsName)
unregisterClusters(clusters, f)

})

It("should be created and deleted successfully", func() {
Expand Down
7 changes: 1 addition & 6 deletions test/e2e_federation/federated-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ var _ = framework.KubeDescribe("Federated Services [Feature:Federation]", func()
federationName = DefaultFederationName
}

clusters = map[string]*cluster{}
primaryClusterName = registerClusters(clusters, UserAgentName, federationName, f)
})

AfterEach(func() {
unregisterClusters(clusters, f)
clusters, primaryClusterName = getRegisteredClusters(UserAgentName, f)
})

Describe("service creation", func() {
Expand Down
15 changes: 6 additions & 9 deletions test/e2e_federation/federation-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func clusterIsReadyOrFail(f *fedframework.Framework, context *fedframework.E2ECo
framework.Logf("Cluster %s is Ready", context.Name)
}

// waitForAllClustersReady wait for all clusters defined in e2e context to be created
// waitForAllRegisteredClusters waits for all clusters defined in e2e context to be created
// return ClusterList until the listed cluster items equals clusterCount
func waitForAllClustersReady(f *fedframework.Framework, clusterCount int) *federationapi.ClusterList {
func waitForAllRegisteredClusters(f *fedframework.Framework, clusterCount int) *federationapi.ClusterList {
var clusterList *federationapi.ClusterList
if err := wait.PollImmediate(framework.Poll, FederatedServiceTimeout, func() (bool, error) {
var err error
Expand Down Expand Up @@ -187,15 +187,12 @@ func unregisterClusters(clusters map[string]*cluster, f *fedframework.Framework)
}

// can not be moved to util, as By and Expect must be put in Ginkgo test unit
func registerClusters(clusters map[string]*cluster, userAgentName, federationName string, f *fedframework.Framework) string {
func getRegisteredClusters(userAgentName string, f *fedframework.Framework) (map[string]*cluster, string) {
clusters := make(map[string]*cluster)
contexts := f.GetUnderlyingFederatedContexts()

for _, context := range contexts {
createClusterObjectOrFail(f, &context)
}

By("Obtaining a list of all the clusters")
clusterList := waitForAllClustersReady(f, len(contexts))
clusterList := waitForAllRegisteredClusters(f, len(contexts))

framework.Logf("Checking that %d clusters are Ready", len(contexts))
for _, context := range contexts {
Expand All @@ -211,7 +208,7 @@ func registerClusters(clusters map[string]*cluster, userAgentName, federationNam
clusters[c.Name] = &cluster{c.Name, createClientsetForCluster(c, i, userAgentName), false, nil}
}
createNamespaceInClusters(clusters, f)
return primaryClusterName
return clusters, primaryClusterName
}

/*
Expand Down
3 changes: 0 additions & 3 deletions test/e2e_federation/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ func (f *Framework) FederationAfterEach() {
framework.Logf("Warning: framework is marked federated, but has no federation 1.5 clientset")
return
}
if err := f.FederationClientset.Federation().Clusters().DeleteCollection(nil, metav1.ListOptions{}); err != nil {
framework.Logf("Error: failed to delete Clusters: %+v", err)
}
}()

// Print events if the test failed.
Expand Down