Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Tests importing [`github.com/knative/serving/test`](adding_tests.md#test-library

* [`--kubeconfig`](#specifying-kubeconfig)
* [`--cluster`](#specifying-cluster)
* [`--namespace`](#specifying-namespace)
* [`--dockerrepo`](#overriding-docker-repo)
* [`--resolvabledomain`](#using-a-resolvable-domain)
* [`--logverbose`](#output-verbose-logs)
Expand Down Expand Up @@ -177,6 +178,16 @@ The current cluster names can be obtained by running:
kubectl config get-clusters
```

### Specifying namespace

The `--namespace` argument lets you specify the namespace to use for the
tests. By default, `conformance` will use `noodleburg` and `e2e` will use `pizzaplanet`.

```bash
go test -v -tags=e2e -count=1 ./test/conformance --namespace your-namespace-name
go test -v -tags=e2e -count=1 ./test/e2e --namespace your-namespace-name
```

### Overridding docker repo

The `--dockerrepo` argument lets you specify the docker repo from which images used
Expand Down
17 changes: 11 additions & 6 deletions test/conformance/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ import (
)

const (
namespaceName = "pizzaplanet"
image1 = "pizzaplanetv1"
image2 = "pizzaplanetv2"
image1 = "pizzaplanetv1"
image2 = "pizzaplanetv2"
defaultNamespaceName = "pizzaplanet"
)

func createRouteAndConfig(clients *test.Clients, names test.ResourceNames, imagePaths []string) error {
_, err := clients.Configs.Create(test.Configuration(namespaceName, names, imagePaths[0]))
_, err := clients.Configs.Create(test.Configuration(test.Flags.Namespace, names, imagePaths[0]))
if err != nil {
return err
}
_, err = clients.Routes.Create(test.Route(namespaceName, names))
_, err = clients.Routes.Create(test.Route(test.Flags.Namespace, names))
return err
}

Expand Down Expand Up @@ -82,6 +82,7 @@ func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, logger *zap.Sugared
if err != nil {
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}

err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, updatedRoute.Status.Domain, func(body string) (bool, error) {
return body == expectedText, nil
}, "WaitForEndpointToServeText")
Expand Down Expand Up @@ -122,7 +123,11 @@ func getNextRevisionName(clients *test.Clients, names test.ResourceNames) (strin
}

func setup(t *testing.T) *test.Clients {
clients, err := test.NewClients(test.Flags.Kubeconfig, test.Flags.Cluster, namespaceName)
if test.Flags.Namespace == "" {
test.Flags.Namespace = defaultNamespaceName
}

clients, err := test.NewClients(test.Flags.Kubeconfig, test.Flags.Cluster, test.Flags.Namespace)
if err != nil {
t.Fatalf("Couldn't initialize clients: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestRunLatestService(t *testing.T) {
test.CleanupOnInterrupt(func() { tearDownService(clients, names) }, logger)

logger.Info("Creating a new Service")
svc, err := clients.Services.Create(test.LatestService(namespaceName, names, imagePaths[0]))
svc, err := clients.Services.Create(test.LatestService(test.Flags.Namespace, names, imagePaths[0]))
if err != nil {
t.Fatalf("Failed to create Service: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestAutoscaleUpDownUp(t *testing.T) {
increases.`)
generateTrafficBurst(clients, logger, 5, domain)
err = test.WaitForDeploymentState(
clients.Kube.ExtensionsV1beta1().Deployments(NamespaceName),
clients.Kube.ExtensionsV1beta1().Deployments(test.Flags.Namespace),
deploymentName,
isDeploymentScaledUp(),
"DeploymentIsScaledUp")
Expand All @@ -193,7 +193,7 @@ func TestAutoscaleUpDownUp(t *testing.T) {
faster testing.`)

err = test.WaitForDeploymentState(
clients.Kube.ExtensionsV1beta1().Deployments(NamespaceName),
clients.Kube.ExtensionsV1beta1().Deployments(test.Flags.Namespace),
deploymentName,
isDeploymentScaledToZero(),
"DeploymentScaledToZero")
Expand All @@ -204,7 +204,7 @@ func TestAutoscaleUpDownUp(t *testing.T) {

// Account for the case where scaling up uses all available pods.
logger.Infof("Wait until there are pods available to scale into.")
pc := clients.Kube.CoreV1().Pods(NamespaceName)
pc := clients.Kube.CoreV1().Pods(test.Flags.Namespace)

err = test.WaitForPodListState(
pc,
Expand All @@ -218,7 +218,7 @@ func TestAutoscaleUpDownUp(t *testing.T) {
traffic increases.`)
generateTrafficBurst(clients, logger, 8, domain)
err = test.WaitForDeploymentState(
clients.Kube.ExtensionsV1beta1().Deployments(NamespaceName),
clients.Kube.ExtensionsV1beta1().Deployments(test.Flags.Namespace),
deploymentName,
isDeploymentScaledUp(),
"DeploymentScaledUp")
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import (
)

const (
// NamespaceName is the namespace used for the e2e tests.
NamespaceName = "noodleburg"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice one!!


configName = "prod"
routeName = "noodleburg"
configName = "prod"
routeName = "noodleburg"
defaultNamespaceName = "noodleburg"
)

// Setup creates the client objects needed in the e2e tests.
func Setup(t *testing.T) *test.Clients {
if test.Flags.Namespace == "" {
test.Flags.Namespace = defaultNamespaceName
}

clients, err := test.NewClients(
test.Flags.Kubeconfig,
test.Flags.Cluster,
NamespaceName)
test.Flags.Namespace)
if err != nil {
t.Fatalf("Couldn't initialize clients: %v", err)
}
Expand Down Expand Up @@ -56,11 +58,11 @@ func CreateRouteAndConfig(clients *test.Clients, logger *zap.SugaredLogger, imag
names.Route = test.AppendRandomString(routeName, logger)

_, err := clients.Configs.Create(
test.Configuration(NamespaceName, names, imagePath))
test.Configuration(test.Flags.Namespace, names, imagePath))
if err != nil {
return test.ResourceNames{}, err
}
_, err = clients.Routes.Create(
test.Route(NamespaceName, names))
test.Route(test.Flags.Namespace, names))
return names, err
}
1 change: 1 addition & 0 deletions test/e2e/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestHelloWorld(t *testing.T) {
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}
domain := route.Status.Domain

err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, domain, isHelloWorldExpectedOutput(), "HelloWorldServesText")
if err != nil {
t.Fatalf("The endpoint for Route %s at domain %s didn't serve the expected text \"%s\": %v", names.Route, domain, helloWorldExpectedOutput, err)
Expand Down
22 changes: 12 additions & 10 deletions test/e2e_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ import (
"path"
)

// Flags will include the k8s cluster (defaults to $K8S_CLUSTER_OVERRIDE), kubeconfig (defaults to ./kube/config)
// (for connecting to an existing cluster), dockerRepo (defaults to $DOCKER_REPO_OVERRIDE),how to connect to deployed endpoints,
// how to log and whether or not to emit metrics.
// Flags holds the command line flags or defaults for settings in the user's environment.
// See EnvironmentFlags for a list of supported fields.
var Flags = initializeFlags()

// EnvironmentFlags holds the command line flags or defaults for settings in the user's environment.
type EnvironmentFlags struct {
Cluster string
DockerRepo string
Kubeconfig string
ResolvableDomain bool
LogVerbose bool
EmitMetrics bool
Cluster string // K8s cluster (defaults to $K8S_CLUSTER_OVERRIDE)
DockerRepo string // Docker repo (defaults to $DOCKER_REPO_OVERRIDE)
Kubeconfig string // Path to kubeconfig (defaults to ./kube/config)
Namespace string // K8s namespace (blank by default, to be overwritten by test suite)
ResolvableDomain bool // Resolve Route controller's `domainSuffix`
LogVerbose bool // Enable verbose logging
EmitMetrics bool // Emit metrics
}

func initializeFlags() *EnvironmentFlags {
Expand All @@ -56,6 +55,9 @@ func initializeFlags() *EnvironmentFlags {
flag.StringVar(&f.Kubeconfig, "kubeconfig", defaultKubeconfig,
"Provide the path to the `kubeconfig` file you'd like to use for these tests. The `current-context` will be used.")

flag.StringVar(&f.Namespace, "namespace", "",
"Provide the namespace you would like to use for these tests.")

flag.BoolVar(&f.ResolvableDomain, "resolvabledomain", false,
"Set this flag to true if you have configured the `domainSuffix` on your Route controller to a domain that will resolve to your test cluster.")

Expand Down