forked from knative/serving
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamespace_test.go
More file actions
133 lines (111 loc) · 4.55 KB
/
namespace_test.go
File metadata and controls
133 lines (111 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// +build e2e
/*
Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"fmt"
"testing"
pkgTest "knative.dev/pkg/test"
"knative.dev/pkg/test/logstream"
"knative.dev/serving/pkg/apis/serving"
"knative.dev/serving/test"
v1a1test "knative.dev/serving/test/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func checkResponse(t *testing.T, clients *test.Clients, names test.ResourceNames, expectedText string) error {
_, err := pkgTest.WaitForEndpointState(
clients.KubeClient,
t.Logf,
names.URL,
v1a1test.RetryingRouteInconsistency(pkgTest.MatchesAllOf(pkgTest.IsStatusOK, pkgTest.EventuallyMatchesBody(expectedText))),
"WaitForEndpointToServeText",
test.ServingFlags.ResolvableDomain)
if err != nil {
return fmt.Errorf("the endpoint for Route %s at %s didn't serve the expected text %q: %w", names.Route, names.URL.String(), expectedText, err)
}
return nil
}
func TestMultipleNamespace(t *testing.T) {
t.Parallel()
cancel := logstream.Start(t)
defer cancel()
defaultClients := Setup(t) // This one uses the default namespace `test.ServingNamespace`
altClients := SetupAlternativeNamespace(t)
serviceName := test.ObjectNameForTest(t)
defaultResources := test.ResourceNames{
Service: serviceName,
Image: test.PizzaPlanet1,
}
test.CleanupOnInterrupt(func() { test.TearDown(defaultClients, defaultResources) })
defer test.TearDown(defaultClients, defaultResources)
if _, _, err := v1a1test.CreateRunLatestServiceReady(t, defaultClients, &defaultResources,
false /* https TODO(taragu) turn this on after helloworld test running with https */); err != nil {
t.Fatalf("Failed to create Service %v in namespace %v: %v", defaultResources.Service, test.ServingNamespace, err)
}
altResources := test.ResourceNames{
Service: serviceName,
Image: test.PizzaPlanet2,
}
test.CleanupOnInterrupt(func() { test.TearDown(altClients, altResources) })
defer test.TearDown(altClients, altResources)
if _, _, err := v1a1test.CreateRunLatestServiceReady(t, altClients, &altResources,
false /* https TODO(taragu) turn this on after helloworld test running with https */); err != nil {
t.Fatalf("Failed to create Service %v in namespace %v: %v", altResources.Service, test.AlternativeServingNamespace, err)
}
if err := checkResponse(t, defaultClients, defaultResources, test.PizzaPlanetText1); err != nil {
t.Error(err)
}
if err := checkResponse(t, altClients, altResources, test.PizzaPlanetText2); err != nil {
t.Error(err)
}
}
// This test is to ensure we do not leak deletion of services in other namespaces when deleting a route.
func TestConflictingRouteService(t *testing.T) {
t.Parallel()
cancel := logstream.Start(t)
defer cancel()
names := test.ResourceNames{
Service: test.AppendRandomString("conflicting-route-service"),
TrafficTarget: "chips",
Image: test.PizzaPlanet1,
}
// Create a service in a different namespace but route label points to a route in another namespace
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: test.AppendRandomString("conflicting-route-service"),
Namespace: test.AlternativeServingNamespace,
Labels: map[string]string{
serving.RouteLabelKey: names.Service,
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeExternalName,
ExternalName: "some-internal-addr",
},
}
altClients := SetupAlternativeNamespace(t)
altClients.KubeClient.Kube.CoreV1().Services(test.AlternativeServingNamespace).Create(svc)
cleanup := func() {
altClients.KubeClient.Kube.CoreV1().Services(test.AlternativeServingNamespace).Delete(svc.Name, &metav1.DeleteOptions{})
}
test.CleanupOnInterrupt(cleanup)
defer cleanup()
clients := Setup(t)
test.CleanupOnInterrupt(func() { test.TearDown(clients, names) })
defer test.TearDown(clients, names)
if _, _, err := v1a1test.CreateRunLatestServiceReady(t, clients, &names,
false /* https TODO(taragu) turn this on after helloworld test running with https */); err != nil {
t.Errorf("Failed to create Service %v in namespace %v: %v", names.Service, test.ServingNamespace, err)
}
}