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] Improve e2e test setup #44066

Merged
merged 2 commits into from
Apr 5, 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
34 changes: 20 additions & 14 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type Framework struct {
StagingClient *staging.Clientset
ClientPool dynamic.ClientPool

Namespace *v1.Namespace // Every test has at least one namespace
SkipNamespaceCreation bool // Whether to skip creating a namespace
Namespace *v1.Namespace // Every test has at least one namespace unless creation is skipped
namespacesToDelete []*v1.Namespace // Some tests have more than one.
NamespaceDeletionTimeout time.Duration

Expand Down Expand Up @@ -181,23 +182,26 @@ func (f *Framework) BeforeEach() {
f.ClientPool = dynamic.NewClientPool(config, api.Registry.RESTMapper(), dynamic.LegacyAPIPathResolverFunc)
}

By("Building a namespace api object")
namespace, err := f.CreateNamespace(f.BaseName, map[string]string{
"e2e-framework": f.BaseName,
})
Expect(err).NotTo(HaveOccurred())
if !f.SkipNamespaceCreation {
By("Building a namespace api object")
namespace, err := f.CreateNamespace(f.BaseName, map[string]string{
"e2e-framework": f.BaseName,
})
Expect(err).NotTo(HaveOccurred())

f.Namespace = namespace
f.Namespace = namespace

if TestContext.VerifyServiceAccount {
By("Waiting for a default service account to be provisioned in namespace")
err = WaitForDefaultServiceAccountInNamespace(f.ClientSet, namespace.Name)
Expect(err).NotTo(HaveOccurred())
} else {
Logf("Skipping waiting for service account")
if TestContext.VerifyServiceAccount {
By("Waiting for a default service account to be provisioned in namespace")
err = WaitForDefaultServiceAccountInNamespace(f.ClientSet, namespace.Name)
Expect(err).NotTo(HaveOccurred())
} else {
Logf("Skipping waiting for service account")
}
}

if TestContext.GatherKubeSystemResourceUsageData != "false" && TestContext.GatherKubeSystemResourceUsageData != "none" {
var err error
f.gatherer, err = NewResourceUsageGatherer(f.ClientSet, ResourceGathererOptions{
inKubemark: ProviderIs("kubemark"),
masterOnly: TestContext.GatherKubeSystemResourceUsageData == "master",
Expand Down Expand Up @@ -274,7 +278,9 @@ func (f *Framework) AfterEach() {
// Print events if the test failed.
if CurrentGinkgoTestDescription().Failed && TestContext.DumpLogsOnFailure {
// Pass both unversioned client and and versioned clientset, till we have removed all uses of the unversioned client.
DumpAllNamespaceInfo(f.ClientSet, f.Namespace.Name)
if !f.SkipNamespaceCreation {
DumpAllNamespaceInfo(f.ClientSet, f.Namespace.Name)
}
By(fmt.Sprintf("Dumping a list of prepulled images on each node"))
LogContainersInPodsWithLabels(f.ClientSet, metav1.NamespaceSystem, ImagePullerLabels, "image-puller", Logf)
}
Expand Down
35 changes: 22 additions & 13 deletions test/e2e_federation/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,40 @@ import (
type Framework struct {
*framework.Framework

// To make sure that this framework cleans up after itself, no matter what,
// we install a Cleanup action before each test and clear it after. If we
// should abort, the AfterSuite hook should run all Cleanup actions.
cleanupHandle framework.CleanupActionHandle

FederationClientset *federation_clientset.Clientset
FederationNamespace *v1.Namespace
}

func NewDefaultFederatedFramework(baseName string) *Framework {
options := framework.FrameworkOptions{
ClientQPS: 20,
ClientBurst: 50,
}
f := &Framework{}

// Register the federation cleanup before initializing the default
// e2e framework to ensure it gets called before the default
// framework's cleanup.
AfterEach(f.FederationAfterEach)
Copy link
Member

Choose a reason for hiding this comment

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

ahhh clever :)


f := &Framework{&framework.Framework{
BaseName: baseName,
AddonResourceConstraints: make(map[string]framework.ResourceConstraint),
Options: options,
ClientSet: nil,
}, nil, &v1.Namespace{}}
f.Framework = framework.NewDefaultFramework(baseName)
Copy link
Member

Choose a reason for hiding this comment

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

ugh why does &Framework{} have a Framework ? weird . but i think it makes sense.

f.Framework.SkipNamespaceCreation = true

BeforeEach(f.BeforeEach)
// Register the federation setup after initializing the default
// e2e framework to ensure it gets called after the default
// framework's setup.
BeforeEach(f.FederationBeforeEach)
AfterEach(f.FederationAfterEach)
AfterEach(f.AfterEach)

return f
}

// FederationBeforeEach checks for federation apiserver is ready and makes a namespace.
func (f *Framework) FederationBeforeEach() {
// The fact that we need this feels like a bug in ginkgo.
// https://github.com/onsi/ginkgo/issues/222
f.cleanupHandle = framework.AddCleanupAction(f.FederationAfterEach)

if f.FederationClientset == nil {
By("Creating a release 1.5 federation Clientset")
var err error
Expand Down Expand Up @@ -122,6 +129,8 @@ func (f *Framework) deleteFederationNs() {

// FederationAfterEach deletes the namespace, after reading its events.
func (f *Framework) FederationAfterEach() {
framework.RemoveCleanupAction(f.cleanupHandle)

// DeleteNamespace at the very end in defer, to avoid any
// expectation failures preventing deleting the namespace.
defer func() {
Expand Down