mirror of https://github.com/knative/client.git
Introduce -reusenamespace test flag (#1383)
* Introduce -reusenamespace test flag * allows for reusing test namespaces that were created in advance (possibly by a cluster admininstrator) * Fix gofmt
This commit is contained in:
parent
0c3e236006
commit
804d021e13
|
|
@ -28,6 +28,7 @@ var Flags = InitializeFlags()
|
||||||
// ClientFlags define the flags that are needed to run the e2e tests.
|
// ClientFlags define the flags that are needed to run the e2e tests.
|
||||||
type ClientFlags struct {
|
type ClientFlags struct {
|
||||||
DockerConfigJSON string
|
DockerConfigJSON string
|
||||||
|
ReuseNamespace bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeFlags initializes the client's flags
|
// InitializeFlags initializes the client's flags
|
||||||
|
|
@ -37,6 +38,9 @@ func InitializeFlags() *ClientFlags {
|
||||||
dockerConfigJSON := os.Getenv("DOCKER_CONFIG_JSON")
|
dockerConfigJSON := os.Getenv("DOCKER_CONFIG_JSON")
|
||||||
flag.StringVar(&f.DockerConfigJSON, "dockerconfigjson", dockerConfigJSON,
|
flag.StringVar(&f.DockerConfigJSON, "dockerconfigjson", dockerConfigJSON,
|
||||||
"Provide the path to Docker configuration file in json format. Defaults to $DOCKER_CONFIG_JSON")
|
"Provide the path to Docker configuration file in json format. Defaults to $DOCKER_CONFIG_JSON")
|
||||||
|
// Might be useful in restricted environments where namespaces need to be
|
||||||
|
// created by a user with increased privileges (admin).
|
||||||
|
flag.BoolVar(&f.ReuseNamespace, "reusenamespace", false, "Whether to re-use namespace for test if it already exists.")
|
||||||
|
|
||||||
return &f
|
return &f
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,14 @@ type KnTest struct {
|
||||||
// NewKnTest creates a new KnTest object
|
// NewKnTest creates a new KnTest object
|
||||||
func NewKnTest() (*KnTest, error) {
|
func NewKnTest() (*KnTest, error) {
|
||||||
ns := ""
|
ns := ""
|
||||||
// try next 20 namespace before giving up creating a namespace if it already exists
|
// Try next 20 namespace before giving up creating a namespace if it already exists
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
ns = NextNamespace()
|
ns = NextNamespace()
|
||||||
|
if Flags.ReuseNamespace {
|
||||||
|
// Re-using existing namespace, no need to create it.
|
||||||
|
// The namespace is supposed to be created in advance.
|
||||||
|
break
|
||||||
|
}
|
||||||
err := CreateNamespace(ns)
|
err := CreateNamespace(ns)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
|
|
@ -77,6 +82,10 @@ func NewKnTest() (*KnTest, error) {
|
||||||
|
|
||||||
// Teardown clean up
|
// Teardown clean up
|
||||||
func (test *KnTest) Teardown() error {
|
func (test *KnTest) Teardown() error {
|
||||||
|
// If we're reusing existing namespaces leave the deletion to the creator.
|
||||||
|
if Flags.ReuseNamespace {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return DeleteNamespace(test.namespace)
|
return DeleteNamespace(test.namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue