mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
fed: Improve e2e framework setup/teardown
- reuse default framework setup rather than duplicating - skip namespace creation for each test in hosting cluster - ensure FederationAfterEach is called if BeforeEach fails
This commit is contained in:
parent
6170378764
commit
e769c33de4
@ -40,33 +40,40 @@ import (
|
|||||||
type Framework struct {
|
type Framework struct {
|
||||||
*framework.Framework
|
*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
|
FederationClientset *federation_clientset.Clientset
|
||||||
FederationNamespace *v1.Namespace
|
FederationNamespace *v1.Namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultFederatedFramework(baseName string) *Framework {
|
func NewDefaultFederatedFramework(baseName string) *Framework {
|
||||||
options := framework.FrameworkOptions{
|
f := &Framework{}
|
||||||
ClientQPS: 20,
|
|
||||||
ClientBurst: 50,
|
|
||||||
}
|
|
||||||
|
|
||||||
f := &Framework{&framework.Framework{
|
// Register the federation cleanup before initializing the default
|
||||||
BaseName: baseName,
|
// e2e framework to ensure it gets called before the default
|
||||||
AddonResourceConstraints: make(map[string]framework.ResourceConstraint),
|
// framework's cleanup.
|
||||||
Options: options,
|
|
||||||
ClientSet: nil,
|
|
||||||
}, nil, &v1.Namespace{}}
|
|
||||||
|
|
||||||
BeforeEach(f.BeforeEach)
|
|
||||||
BeforeEach(f.FederationBeforeEach)
|
|
||||||
AfterEach(f.FederationAfterEach)
|
AfterEach(f.FederationAfterEach)
|
||||||
AfterEach(f.AfterEach)
|
|
||||||
|
f.Framework = framework.NewDefaultFramework(baseName)
|
||||||
|
f.Framework.SkipNamespaceCreation = true
|
||||||
|
|
||||||
|
// Register the federation setup after initializing the default
|
||||||
|
// e2e framework to ensure it gets called after the default
|
||||||
|
// framework's setup.
|
||||||
|
BeforeEach(f.FederationBeforeEach)
|
||||||
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// FederationBeforeEach checks for federation apiserver is ready and makes a namespace.
|
// FederationBeforeEach checks for federation apiserver is ready and makes a namespace.
|
||||||
func (f *Framework) FederationBeforeEach() {
|
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 {
|
if f.FederationClientset == nil {
|
||||||
By("Creating a release 1.5 federation Clientset")
|
By("Creating a release 1.5 federation Clientset")
|
||||||
var err error
|
var err error
|
||||||
@ -122,6 +129,8 @@ func (f *Framework) deleteFederationNs() {
|
|||||||
|
|
||||||
// FederationAfterEach deletes the namespace, after reading its events.
|
// FederationAfterEach deletes the namespace, after reading its events.
|
||||||
func (f *Framework) FederationAfterEach() {
|
func (f *Framework) FederationAfterEach() {
|
||||||
|
framework.RemoveCleanupAction(f.cleanupHandle)
|
||||||
|
|
||||||
// DeleteNamespace at the very end in defer, to avoid any
|
// DeleteNamespace at the very end in defer, to avoid any
|
||||||
// expectation failures preventing deleting the namespace.
|
// expectation failures preventing deleting the namespace.
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user