Skip to content

Commit 3da92c9

Browse files
committed
Fewer domain levels for knative services domain
Patch domain-template in config to ensure ksvcs are direct subdomain of the cluster domain. This is useful when using with wild-card certificates. Signed-off-by: Matej Vašek <matejvasek@gmail.com>
1 parent 4f14a28 commit 3da92c9

7 files changed

Lines changed: 47 additions & 25 deletions

File tree

e2e/e2e_core_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestCore_Deploy_Basic(t *testing.T) {
100100
clean(t, name, Namespace)
101101
}()
102102

103-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
103+
if !waitFor(t, ksvcUrl(name)) {
104104
t.Fatal("function did not deploy correctly")
105105
}
106106
}
@@ -129,7 +129,7 @@ func TestCore_Deploy_Template(t *testing.T) {
129129

130130
// The default implementation responds with HTTP 200 and the string
131131
// "testcore-deploy-template" for all requests.
132-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
132+
if !waitFor(t, ksvcUrl(name),
133133
withContentMatch(name)) {
134134
t.Fatal("function did not update correctly")
135135
}
@@ -178,7 +178,7 @@ func TestCore_Update(t *testing.T) {
178178
defer func() {
179179
clean(t, name, Namespace)
180180
}()
181-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
181+
if !waitFor(t, ksvcUrl(name)) {
182182
t.Fatal("function did not deploy correctly")
183183
}
184184

@@ -198,7 +198,7 @@ func TestCore_Update(t *testing.T) {
198198
if err := newCmd(t, "deploy").Run(); err != nil {
199199
t.Fatal(err)
200200
}
201-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
201+
if !waitFor(t, ksvcUrl(name),
202202
withContentMatch("UPDATED")) {
203203
t.Fatal("function did not update correctly")
204204
}
@@ -228,7 +228,7 @@ func TestCore_Describe(t *testing.T) {
228228
t.Fatalf("deploy error. %v", err)
229229
}
230230

231-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
231+
if !waitFor(t, ksvcUrl(name)) {
232232
t.Fatal("function did not deploy correctly")
233233
}
234234

@@ -308,7 +308,7 @@ func TestCore_Invoke(t *testing.T) {
308308
defer func() {
309309
clean(t, name, Namespace)
310310
}()
311-
if !waitFor(t, fmt.Sprintf("http://%s.%s.%s", name, Namespace, Domain)) {
311+
if !waitFor(t, ksvcUrl(name)) {
312312
t.Fatal("function did not deploy correctly")
313313
}
314314

@@ -334,7 +334,7 @@ func TestCore_Delete(t *testing.T) {
334334
defer func() {
335335
clean(t, name, Namespace)
336336
}()
337-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
337+
if !waitFor(t, ksvcUrl(name)) {
338338
t.Fatal("function did not deploy correctly")
339339
}
340340

e2e/e2e_matrix_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestMatrix_Deploy(t *testing.T) {
106106
}
107107

108108
// Ensure the Function comes up
109-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
109+
if !waitFor(t, ksvcUrl(name),
110110
withWaitTimeout(timeout),
111111
withTemplate(template)) {
112112
t.Fatal("function did not deploy correctly")
@@ -142,7 +142,7 @@ func TestMatrix_Remote(t *testing.T) {
142142
}
143143

144144
// Ensure the Function comes up
145-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
145+
if !waitFor(t, ksvcUrl(name),
146146
withWaitTimeout(timeout),
147147
withTemplate(template)) {
148148
t.Fatal("function did not deploy correctly")

e2e/e2e_metadata_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestMetadata_Envs_Add(t *testing.T) {
137137
defer func() {
138138
clean(t, name, Namespace)
139139
}()
140-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
140+
if !waitFor(t, ksvcUrl(name),
141141
withContentMatch("OK")) {
142142
t.Fatal("handler failed")
143143
}
@@ -194,7 +194,7 @@ func TestMetadata_Envs_Remove(t *testing.T) {
194194
defer func() {
195195
clean(t, name, Namespace)
196196
}()
197-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
197+
if !waitFor(t, ksvcUrl(name),
198198
withContentMatch("OK")) {
199199
t.Fatal("handler failed")
200200
}
@@ -230,7 +230,7 @@ func TestMetadata_Envs_Remove(t *testing.T) {
230230
if err := newCmd(t, "deploy").Run(); err != nil {
231231
t.Fatal(err)
232232
}
233-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
233+
if !waitFor(t, ksvcUrl(name),
234234
withContentMatch("OK")) {
235235
t.Fatal("handler failed")
236236
}
@@ -268,7 +268,7 @@ func TestMetadata_Labels_Add(t *testing.T) {
268268
defer func() {
269269
clean(t, name, Namespace)
270270
}()
271-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
271+
if !waitFor(t, ksvcUrl(name)) {
272272
t.Fatal("function did not deploy correctly")
273273
}
274274

@@ -318,7 +318,7 @@ func TestMetadata_Labels_Remove(t *testing.T) {
318318
defer func() {
319319
clean(t, name, Namespace)
320320
}()
321-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
321+
if !waitFor(t, ksvcUrl(name)) {
322322
t.Fatal("function did not deploy correctly")
323323
}
324324

@@ -350,7 +350,7 @@ func TestMetadata_Labels_Remove(t *testing.T) {
350350
if err := newCmd(t, "deploy").Run(); err != nil {
351351
t.Fatal(err)
352352
}
353-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
353+
if !waitFor(t, ksvcUrl(name)) {
354354
t.Fatal("function did not redeploy correctly")
355355
}
356356

@@ -494,7 +494,7 @@ func Handle(w http.ResponseWriter, _ *http.Request) {
494494
}()
495495

496496
// Verify the function has access to all volumes
497-
if !waitFor(t, fmt.Sprintf("http://%s.%s.%s", name, Namespace, Domain),
497+
if !waitFor(t, ksvcUrl(name),
498498
withContentMatch("OK")) {
499499
t.Fatal("function failed to access volumes correctly")
500500
}
@@ -555,7 +555,7 @@ func Handle(w http.ResponseWriter, _ *http.Request) {
555555
t.Fatal(err)
556556
}
557557

558-
if !waitFor(t, fmt.Sprintf("http://%s.%s.%s", name, Namespace, Domain),
558+
if !waitFor(t, ksvcUrl(name),
559559
withContentMatch("OK")) {
560560
t.Fatal("function failed after volume removal")
561561
}
@@ -601,7 +601,7 @@ func TestMetadata_Subscriptions(t *testing.T) {
601601
}
602602
defer clean(t, subscriberName, Namespace)
603603

604-
subscriberURL := fmt.Sprintf("http://%s.%s.%s", subscriberName, Namespace, Domain)
604+
subscriberURL := ksvcUrl(subscriberName)
605605
if !waitFor(t, subscriberURL, withTemplate("cloudevents")) {
606606
t.Fatal("subscriber not ready")
607607
}

e2e/e2e_podman_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package e2e
55

66
import (
7-
"fmt"
87
"testing"
98
)
109

@@ -32,7 +31,7 @@ func TestPodman_Pack(t *testing.T) {
3231
clean(t, name, Namespace)
3332
}()
3433

35-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
34+
if !waitFor(t, ksvcUrl(name)) {
3635
t.Fatal("function did not deploy correctly")
3736
}
3837
}
@@ -61,7 +60,7 @@ func TestPodman_S2I(t *testing.T) {
6160
clean(t, name, Namespace)
6261
}()
6362

64-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
63+
if !waitFor(t, ksvcUrl(name)) {
6564
t.Fatal("function did not deploy correctly")
6665
}
6766
}

e2e/e2e_remote_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestRemote_Deploy(t *testing.T) {
3535
clean(t, name, Namespace)
3636
}()
3737

38-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain)) {
38+
if !waitFor(t, ksvcUrl(name)) {
3939
t.Fatal("function did not deploy correctly")
4040
}
4141
}
@@ -67,7 +67,7 @@ func TestRemote_Source(t *testing.T) {
6767
clean(t, name, Namespace)
6868
}()
6969

70-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
70+
if !waitFor(t, ksvcUrl(name),
7171
withContentMatch(name)) {
7272
t.Fatal("function did not deploy correctly")
7373
}
@@ -112,7 +112,7 @@ func TestRemote_Ref(t *testing.T) {
112112
clean(t, name, Namespace)
113113
}()
114114

115-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
115+
if !waitFor(t, ksvcUrl(name),
116116
withContentMatch(name)) {
117117
t.Fatal("function did not deploy correctly")
118118
}
@@ -159,7 +159,7 @@ func TestRemote_Dir(t *testing.T) {
159159
clean(t, name, Namespace)
160160
}()
161161

162-
if !waitFor(t, fmt.Sprintf("http://%v.%s.%s", name, Namespace, Domain),
162+
if !waitFor(t, ksvcUrl(name),
163163
withContentMatch(name)) {
164164
t.Fatal("function did not deploy correctly")
165165
}

e2e/e2e_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strconv"
2525
"strings"
2626
"testing"
27+
"text/template"
2728
"time"
2829

2930
fn "knative.dev/func/pkg/functions"
@@ -1216,3 +1217,22 @@ func parseRunJSON(t *testing.T, cmd *exec.Cmd) string {
12161217
t.Cleanup(func() { stdoutWriter.Close() })
12171218
return address
12181219
}
1220+
1221+
func ksvcUrl(name string) string {
1222+
// TODO get `default-external-scheme` from the config in cluster
1223+
const ksvcDefaultExternalScheme = `http`
1224+
// TODO get `domain-template` from the config in cluster
1225+
const ksvcDomainTemplate = `{{.Name}}-{{.Namespace}}-ksvc.{{.Domain}}`
1226+
t, err := template.New("").Parse(ksvcDomainTemplate)
1227+
if err != nil {
1228+
panic(err)
1229+
}
1230+
var buf bytes.Buffer
1231+
err = t.Execute(&buf, struct {
1232+
Name, Namespace, Domain string
1233+
}{name, Namespace, Domain})
1234+
if err != nil {
1235+
panic(err)
1236+
}
1237+
return ksvcDefaultExternalScheme + `://` + buf.String()
1238+
}

hack/cluster.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ networking() {
255255
--type merge \
256256
--patch '{"data":{"ingress-class":"contour.ingress.networking.knative.dev"}}'
257257

258+
echo "Patch domain-template"
259+
$KUBECTL patch -n knative-serving cm/config-network --patch '{"data":{"domain-template":"{{.Name}}-{{.Namespace}}-ksvc.{{.Domain}}"}}'
260+
258261
echo "Patching contour to prefer duals-tack"
259262
kubectl patch -n contour-external svc/envoy --type merge --patch '{"spec":{"ipFamilyPolicy":"PreferDualStack"}}'
260263

0 commit comments

Comments
 (0)