Skip to content
Open
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
4 changes: 2 additions & 2 deletions pkg/reconciler/knativeserving/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestTransformers(t *testing.T) {
},
},
},
expected: 3,
expected: 4,
}, {
name: "Available contour ingress",
instance: servingv1beta1.KnativeServing{
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestTransformers(t *testing.T) {
},
},
},
expected: 4,
expected: 5,
}}

for _, tt := range tests {
Expand Down
28 changes: 27 additions & 1 deletion pkg/reconciler/knativeserving/ingress/kourier.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ingress
import (
"context"
"fmt"
"strings"

mf "github.com/manifestival/manifestival"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -34,13 +35,16 @@ const (
kourierGatewayServiceName = "kourier"
kourierDefaultVolumeName = "kourier-bootstrap"
kourierGatewayDeploymentNames = "3scale-kourier-gateway"
kourierDefaultNamespace = "knative-serving"
kourierBootstrapDataKey = "envoy-bootstrap.yaml"
)

var kourierControllerDeploymentNames = sets.NewString("3scale-kourier-control", "net-kourier-controller")

func kourierTransformers(_ context.Context, instance *v1beta1.KnativeServing) []mf.Transformer {
return []mf.Transformer{
replaceGatewayNamespace(),
replaceBootstrapNamespace(),
configureGatewayService(instance),
configureBootstrapConfigMap(instance),
}
Expand Down Expand Up @@ -74,6 +78,28 @@ func replaceGatewayNamespace() mf.Transformer {
}
}

// replaceBootstrapNamespace updates namespace references embedded in Kourier's
// default bootstrap configuration.
func replaceBootstrapNamespace() mf.Transformer {
return func(u *unstructured.Unstructured) error {
if u.GetKind() != "ConfigMap" || u.GetName() != kourierDefaultVolumeName {
return nil
}

configMap := &v1.ConfigMap{}
if err := scheme.Scheme.Convert(u, configMap, nil); err != nil {
return err
}

if bootstrap, found := configMap.Data[kourierBootstrapDataKey]; found {
configMap.Data[kourierBootstrapDataKey] = strings.ReplaceAll(
bootstrap, kourierDefaultNamespace, configMap.GetNamespace())
}

return scheme.Scheme.Convert(configMap, u, nil)
}
}

func configureGatewayService(instance *v1beta1.KnativeServing) mf.Transformer {
return func(u *unstructured.Unstructured) error {
if u.GetKind() != "Service" || u.GetName() != kourierGatewayServiceName {
Expand Down Expand Up @@ -121,7 +147,7 @@ func configureGatewayService(instance *v1beta1.KnativeServing) mf.Transformer {
}
}

// configureBootstrapConfigMap sets Kourier GW's bootstrap configmap name.
// configureBootstrapConfigMap sets Kourier GW's bootstrap ConfigMap name.
func configureBootstrapConfigMap(instance *v1beta1.KnativeServing) mf.Transformer {
return func(u *unstructured.Unstructured) error {
if u.GetKind() == "Deployment" && u.GetName() == kourierGatewayDeploymentNames {
Expand Down
56 changes: 56 additions & 0 deletions pkg/reconciler/knativeserving/ingress/kourier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ingress

import (
"fmt"
"strings"
"testing"

mf "github.com/manifestival/manifestival"
Expand Down Expand Up @@ -182,6 +183,61 @@ func TestTransformKourierManifest(t *testing.T) {
}
}

func TestReplaceBootstrapNamespace(t *testing.T) {
const customNamespace = "custom-serving"

client := fake.New()
manifest, err := mf.NewManifest("testdata/kodata/ingress/1.9/kourier/kourier.yaml", mf.UseClient(client))
if err != nil {
t.Fatalf("Failed to read manifest: %v", err)
}

before := bootstrapConfigMap(t, manifest)
defaultControllerAddress := "net-kourier-controller." + kourierDefaultNamespace
if bootstrap := before.Data[kourierBootstrapDataKey]; !strings.Contains(bootstrap, defaultControllerAddress) {
t.Fatalf("Bootstrap config does not contain default controller address %q", defaultControllerAddress)
}

manifest, err = manifest.Transform(
mf.InjectNamespace(customNamespace),
replaceBootstrapNamespace(),
)
if err != nil {
t.Fatalf("Failed to transform manifest: %v", err)
}

after := bootstrapConfigMap(t, manifest)
if after.Namespace != customNamespace {
t.Fatalf("Bootstrap ConfigMap namespace = %q, want %q", after.Namespace, customNamespace)
}
bootstrap := after.Data[kourierBootstrapDataKey]
if strings.Contains(bootstrap, kourierDefaultNamespace) {
t.Fatalf("Bootstrap config still contains default namespace %q", kourierDefaultNamespace)
}
if want := "net-kourier-controller." + customNamespace; !strings.Contains(bootstrap, want) {
t.Fatalf("Bootstrap config does not contain controller address %q", want)
}
}

func bootstrapConfigMap(t *testing.T, manifest mf.Manifest) *v1.ConfigMap {
t.Helper()

for _, u := range manifest.Resources() {
if u.GetKind() != "ConfigMap" || u.GetName() != kourierDefaultVolumeName {
continue
}

configMap := &v1.ConfigMap{}
if err := scheme.Scheme.Convert(&u, configMap, nil); err != nil {
t.Fatalf("Failed to convert bootstrap ConfigMap: %v", err)
}
return configMap
}

t.Fatal("Bootstrap ConfigMap not found")
return nil
}

func verifyGatewayServiceTypeNodePortHTTP(t *testing.T, u *unstructured.Unstructured, expHTTPPort int32) {
if u.GetKind() == "Service" && u.GetName() == kourierGatewayServiceName {
svc := &v1.Service{}
Expand Down
Loading