From 3d137ac726e7f3c6c17040fb6f0f3b68456508ae Mon Sep 17 00:00:00 2001 From: zxxa Date: Fri, 18 Jan 2019 22:33:32 +0800 Subject: [PATCH] User can specify the namespace in yaml for knative-serving (#2708) * User can specify the namespace in yaml for knative-serving * use getter method for namespaces * add default namespaces for test * panic if the SYSTEM_NAMESPACE environment variable isn't set This makes `pkg/system` panic if `SYSTEM_NAMESPACE` is not set. For tests, it exposes a simple library you can link to set this variable to a suitable namespace. * update namespace in crd_checks.go * change test ns knative-serving to knative-testing * use environment value set the autoscaler namespaces * queue get env from system.Namespace * update the test case to match the new environment value --- cmd/activator/main.go | 4 +-- cmd/autoscaler/main.go | 2 +- cmd/controller/main.go | 2 +- cmd/queue/main.go | 5 +-- cmd/webhook/main.go | 4 +-- config/activator.yaml | 4 +++ config/autoscaler.yaml | 5 +++ config/controller.yaml | 5 +++ config/webhook.yaml | 5 +++ pkg/logging/config_test.go | 13 +++---- pkg/reconciler/testing/table.go | 1 + .../autoscaling/kpa/kpa_scaler_test.go | 1 + .../v1alpha1/autoscaling/kpa/kpa_test.go | 3 +- .../clusteringress/clusteringress_test.go | 11 +++--- .../clusteringress/config/istio_test.go | 6 ++-- .../clusteringress/resources/names/names.go | 7 ---- .../resources/virtual_service.go | 2 +- .../resources/virtual_service_test.go | 3 +- .../v1alpha1/configuration/queueing_test.go | 2 +- .../revision/config/controller_test.go | 6 ++-- .../v1alpha1/revision/config/network_test.go | 28 +++++++-------- .../revision/config/observability_test.go | 6 ++-- .../v1alpha1/revision/queueing_test.go | 12 +++---- .../revision/resources/deploy_test.go | 32 +++++++++++++++++ .../v1alpha1/revision/resources/queue.go | 4 +++ .../v1alpha1/revision/resources/queue_test.go | 17 +++++++++ .../v1alpha1/revision/revision_test.go | 30 ++++++++-------- .../v1alpha1/route/config/domain_test.go | 6 ++-- .../v1alpha1/route/queueing_test.go | 4 +-- .../route/resources/cluster_ingress.go | 2 +- .../route/resources/cluster_ingress_test.go | 6 ++-- pkg/reconciler/v1alpha1/route/route_test.go | 24 ++++++------- pkg/system/names.go | 35 +++++++++++++++++-- pkg/system/testing/names.go | 28 +++++++++++++++ test/config/300-controller.yaml | 5 +++ test/conformance/blue_green_test.go | 1 + test/conformance/single_threaded_test.go | 1 + test/e2e/autoscale_test.go | 1 + test/e2e/build_test.go | 1 + test/upgrade/service_postdowngrade_test.go | 1 + test/upgrade/service_postupgrade_test.go | 1 + test/upgrade/service_preupgrade_test.go | 1 + test/upgrade/upgrade.go | 1 + 43 files changed, 241 insertions(+), 97 deletions(-) create mode 100644 pkg/system/testing/names.go diff --git a/cmd/activator/main.go b/cmd/activator/main.go index 45833eb7b04f..f4231f07eda1 100644 --- a/cmd/activator/main.go +++ b/cmd/activator/main.go @@ -150,7 +150,7 @@ func main() { stopCh := signals.SetupSignalHandler() // Open a websocket connection to the autoscaler - autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.cluster.local:%s", "autoscaler", system.Namespace, "8080") + autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.cluster.local:%s", "autoscaler", system.Namespace(), "8080") logger.Infof("Connecting to autoscaler at %s", autoscalerEndpoint) statSink = websocket.NewDurableSendingConnection(autoscalerEndpoint) go statReporter(stopCh) @@ -177,7 +177,7 @@ func main() { } // Watch the logging config map and dynamically update logging levels. - configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace) + configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace()) configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, component)) // Watch the observability config map and dynamically update metrics exporter. configMapWatcher.Watch(metrics.ObservabilityConfigName, metrics.UpdateExporterFromConfigMap(component, logger)) diff --git a/cmd/autoscaler/main.go b/cmd/autoscaler/main.go index fa1adc9c92e5..5a6b13cab675 100644 --- a/cmd/autoscaler/main.go +++ b/cmd/autoscaler/main.go @@ -94,7 +94,7 @@ func main() { } // Watch the logging config map and dynamically update logging levels. - configMapWatcher := configmap.NewInformedWatcher(kubeClientSet, system.Namespace) + configMapWatcher := configmap.NewInformedWatcher(kubeClientSet, system.Namespace()) configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, component)) // Watch the observability config map and dynamically update metrics exporter. configMapWatcher.Watch(metrics.ObservabilityConfigName, metrics.UpdateExporterFromConfigMap(component, logger)) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 7b0f85788296..8234d8b6b55d 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -118,7 +118,7 @@ func main() { logger.Fatalf("Version check failed: %v", err) } - configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace) + configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace()) opt := reconciler.Options{ KubeClientSet: kubeClient, diff --git a/cmd/queue/main.go b/cmd/queue/main.go index 615785616ddb..2a1f45a4801a 100644 --- a/cmd/queue/main.go +++ b/cmd/queue/main.go @@ -39,7 +39,6 @@ import ( "github.com/knative/serving/pkg/logging" "github.com/knative/serving/pkg/queue" "github.com/knative/serving/pkg/queue/health" - "github.com/knative/serving/pkg/system" "github.com/knative/serving/pkg/utils" "go.opencensus.io/exporter/prometheus" "go.opencensus.io/stats/view" @@ -69,6 +68,7 @@ var ( servingRevision string servingRevisionKey string servingAutoscaler string + autoscalerNamespace string servingAutoscalerPort int userTargetPort int userTargetAddress string @@ -94,6 +94,7 @@ func initEnv() { servingNamespace = util.GetRequiredEnvOrFatal("SERVING_NAMESPACE", logger) servingRevision = util.GetRequiredEnvOrFatal("SERVING_REVISION", logger) servingAutoscaler = util.GetRequiredEnvOrFatal("SERVING_AUTOSCALER", logger) + autoscalerNamespace = util.GetRequiredEnvOrFatal("SYSTEM_NAMESPACE", logger) servingAutoscalerPort = util.MustParseIntEnvOrFatal("SERVING_AUTOSCALER_PORT", logger) containerConcurrency = util.MustParseIntEnvOrFatal("CONTAINER_CONCURRENCY", logger) revisionTimeoutSeconds = util.MustParseIntEnvOrFatal("REVISION_TIMEOUT_SECONDS", logger) @@ -276,7 +277,7 @@ func main() { }() // Open a websocket connection to the autoscaler - autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.%s:%d", servingAutoscaler, system.Namespace, utils.GetClusterDomainName(), servingAutoscalerPort) + autoscalerEndpoint := fmt.Sprintf("ws://%s.%s.svc.%s:%d", servingAutoscaler, autoscalerNamespace, utils.GetClusterDomainName(), servingAutoscalerPort) logger.Infof("Connecting to autoscaler at %s", autoscalerEndpoint) statSink = websocket.NewDurableSendingConnection(autoscalerEndpoint) go statReporter() diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 18f6d0f40435..93e72281fdf1 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -81,7 +81,7 @@ func main() { } // Watch the logging config map and dynamically update logging levels. - configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace) + configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace()) configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, component)) if err = configMapWatcher.Start(stopCh); err != nil { logger.Fatalf("failed to start configuration manager: %v", err) @@ -90,7 +90,7 @@ func main() { options := webhook.ControllerOptions{ ServiceName: "webhook", DeploymentName: "webhook", - Namespace: system.Namespace, + Namespace: system.Namespace(), Port: 443, SecretName: "webhook-certs", WebhookName: "webhook.serving.knative.dev", diff --git a/config/activator.yaml b/config/activator.yaml index 4500b36944ee..02ea748d3cac 100644 --- a/config/activator.yaml +++ b/config/activator.yaml @@ -61,6 +61,10 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace volumeMounts: - name: config-logging mountPath: /etc/config-logging diff --git a/config/autoscaler.yaml b/config/autoscaler.yaml index 5a8bd629527c..ceed1029318f 100644 --- a/config/autoscaler.yaml +++ b/config/autoscaler.yaml @@ -56,6 +56,11 @@ spec: mountPath: /etc/config-logging - name: config-observability mountPath: /etc/config-observability + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace volumes: - name: config-autoscaler configMap: diff --git a/config/controller.yaml b/config/controller.yaml index aeb3384c87c3..36e5e9f77673 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -50,6 +50,11 @@ spec: volumeMounts: - name: config-logging mountPath: /etc/config-logging + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace volumes: - name: config-logging configMap: diff --git a/config/webhook.yaml b/config/webhook.yaml index 68e5a5315ca9..eb037c98f124 100644 --- a/config/webhook.yaml +++ b/config/webhook.yaml @@ -49,6 +49,11 @@ spec: volumeMounts: - name: config-logging mountPath: /etc/config-logging + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace volumes: - name: config-logging configMap: diff --git a/pkg/logging/config_test.go b/pkg/logging/config_test.go index 9f8c21a86643..39b062ace5ee 100644 --- a/pkg/logging/config_test.go +++ b/pkg/logging/config_test.go @@ -24,6 +24,7 @@ import ( "github.com/ghodss/yaml" "github.com/knative/pkg/logging" "github.com/knative/serving/pkg/system" + _ "github.com/knative/serving/pkg/system/testing" "go.uber.org/zap" "go.uber.org/zap/zapcore" corev1 "k8s.io/api/core/v1" @@ -119,7 +120,7 @@ func TestNewLogger(t *testing.T) { func TestNewConfigNoEntry(t *testing.T) { c, err := NewConfigFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, }) @@ -139,7 +140,7 @@ func TestNewConfig(t *testing.T) { wantLevel := zapcore.InfoLevel c, err := NewConfigFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, Data: map[string]string{ @@ -187,7 +188,7 @@ func TestNewLoggerFromConfig(t *testing.T) { func TestEmptyLevel(t *testing.T) { c, err := NewConfigFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, Data: map[string]string{ @@ -207,7 +208,7 @@ func TestInvalidLevel(t *testing.T) { wantCfg := "{\"level\": \"error\",\n\"outputPaths\": [\"stdout\"],\n\"errorOutputPaths\": [\"stderr\"],\n\"encoding\": \"json\"}" _, err := NewConfigFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, Data: map[string]string{ @@ -225,7 +226,7 @@ func getTestConfig() (*logging.Config, string, string) { wantLevel := "debug" c, _ := NewConfigFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, Data: map[string]string{ @@ -245,7 +246,7 @@ func TestUpdateLevelFromConfigMap(t *testing.T) { cm := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: "config-logging", }, Data: map[string]string{ diff --git a/pkg/reconciler/testing/table.go b/pkg/reconciler/testing/table.go index 818338adcd81..4f4bed21580f 100644 --- a/pkg/reconciler/testing/table.go +++ b/pkg/reconciler/testing/table.go @@ -27,6 +27,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/knative/pkg/controller" "github.com/knative/pkg/kmeta" + _ "github.com/knative/serving/pkg/system/testing" // Setup system.Namespace() "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler_test.go b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler_test.go index 2294ae568876..a02ebbfad3bf 100644 --- a/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler_test.go +++ b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler_test.go @@ -30,6 +30,7 @@ import ( fakeKna "github.com/knative/serving/pkg/client/clientset/versioned/fake" revisionresources "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/resources" "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/resources/names" + _ "github.com/knative/serving/pkg/system/testing" v1 "k8s.io/api/apps/v1" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go index 4b78c08e9e1e..23aa47c99821 100644 --- a/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go +++ b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go @@ -33,6 +33,7 @@ import ( "github.com/knative/serving/pkg/reconciler" revisionresources "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/resources" "github.com/knative/serving/pkg/system" + _ "github.com/knative/serving/pkg/system/testing" "go.uber.org/atomic" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -59,7 +60,7 @@ var ( func newConfigWatcher() configmap.Watcher { return configmap.NewStaticWatcher(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: autoscaler.ConfigName, }, Data: configMapData, diff --git a/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go b/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go index 7e235f70e5ec..bb8d2b58a5f4 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go +++ b/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go @@ -42,6 +42,7 @@ import ( fakeclientset "github.com/knative/serving/pkg/client/clientset/versioned/fake" informers "github.com/knative/serving/pkg/client/informers/externalversions" "github.com/knative/serving/pkg/reconciler" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/pkg/reconciler/v1alpha1/clusteringress/config" "github.com/knative/serving/pkg/reconciler/v1alpha1/clusteringress/resources" . "github.com/knative/serving/pkg/reconciler/v1alpha1/testing" @@ -154,7 +155,7 @@ func TestReconcile(t *testing.T) { &v1alpha3.VirtualService{ ObjectMeta: metav1.ObjectMeta{ Name: "reconcile-virtualservice", - Namespace: system.Namespace, + Namespace: system.Namespace(), Labels: map[string]string{ networking.IngressLabelKey: "reconcile-virtualservice", serving.RouteLabelKey: "test-route", @@ -195,7 +196,7 @@ func TestReconcile(t *testing.T) { }}, WantEvents: []string{ Eventf(corev1.EventTypeNormal, "Updated", "Updated status for VirtualService %q/%q", - system.Namespace, "reconcile-virtualservice"), + system.Namespace(), "reconcile-virtualservice"), }, Key: "reconcile-virtualservice", }} @@ -286,7 +287,7 @@ func newTestSetup(t *testing.T, configs ...*corev1.ConfigMap) ( { ObjectMeta: metav1.ObjectMeta{ Name: config.IstioConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: originGateways, }, @@ -295,7 +296,7 @@ func newTestSetup(t *testing.T, configs ...*corev1.ConfigMap) ( cms = append(cms, cm) } - configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace} + configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace()} sharedClient = fakesharedclientset.NewSimpleClientset() servingClient = fakeclientset.NewSimpleClientset() @@ -392,7 +393,7 @@ func TestGlobalResyncOnUpdateGatewayConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.IstioConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: newGateways, } diff --git a/pkg/reconciler/v1alpha1/clusteringress/config/istio_test.go b/pkg/reconciler/v1alpha1/clusteringress/config/istio_test.go index 37c3dfeac3f5..814cad1de5f3 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/config/istio_test.go +++ b/pkg/reconciler/v1alpha1/clusteringress/config/istio_test.go @@ -47,7 +47,7 @@ func TestGatewayConfiguration(t *testing.T) { wantIstio: (*Istio)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: IstioConfigName, }, }}, { @@ -56,7 +56,7 @@ func TestGatewayConfiguration(t *testing.T) { wantIstio: (*Istio)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: IstioConfigName, }, Data: map[string]string{ @@ -74,7 +74,7 @@ func TestGatewayConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: IstioConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go b/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go index 83f298da955c..fff85dc965ce 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go +++ b/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go @@ -18,15 +18,8 @@ package names import ( "github.com/knative/serving/pkg/apis/networking/v1alpha1" - "github.com/knative/serving/pkg/reconciler" - "github.com/knative/serving/pkg/system" ) -// K8sGatewayFullname is the fully-qualified name of Knative shared gateway. -var K8sGatewayFullname = reconciler.GetK8sServiceFullname( - "knative-shared-gateway", - system.Namespace) - // VirtualService returns the name of the VirtualService child resource for given ClusterIngress. func VirtualService(i *v1alpha1.ClusterIngress) string { return i.Name diff --git a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go index 320328bb4107..009951c1b49e 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go +++ b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go @@ -40,7 +40,7 @@ func MakeVirtualService(ci *v1alpha1.ClusterIngress, gateways []string) *v1alpha vs := &v1alpha3.VirtualService{ ObjectMeta: metav1.ObjectMeta{ Name: names.VirtualService(ci), - Namespace: system.Namespace, + Namespace: system.Namespace(), OwnerReferences: []metav1.OwnerReference{*kmeta.NewControllerRef(ci)}, Annotations: ci.ObjectMeta.Annotations, }, diff --git a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go index 18a0ab37359b..4440afaf1ed2 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go +++ b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go @@ -27,6 +27,7 @@ import ( "github.com/knative/serving/pkg/apis/networking" "github.com/knative/serving/pkg/apis/networking/v1alpha1" "github.com/knative/serving/pkg/apis/serving" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/pkg/system" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -45,7 +46,7 @@ func TestMakeVirtualServiceSpec_CorrectMetadata(t *testing.T) { } expected := metav1.ObjectMeta{ Name: "test-ingress", - Namespace: system.Namespace, + Namespace: system.Namespace(), Labels: map[string]string{ networking.IngressLabelKey: "test-ingress", serving.RouteLabelKey: "test-route", diff --git a/pkg/reconciler/v1alpha1/configuration/queueing_test.go b/pkg/reconciler/v1alpha1/configuration/queueing_test.go index 93fc76ede835..85fdbd70fca2 100644 --- a/pkg/reconciler/v1alpha1/configuration/queueing_test.go +++ b/pkg/reconciler/v1alpha1/configuration/queueing_test.go @@ -101,7 +101,7 @@ func newTestController(t *testing.T, servingObjects ...runtime.Object) ( configMapWatcher := configmap.NewStaticWatcher(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: gc.ConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{}, }) diff --git a/pkg/reconciler/v1alpha1/revision/config/controller_test.go b/pkg/reconciler/v1alpha1/revision/config/controller_test.go index cbca86cb7362..b91b5155d527 100644 --- a/pkg/reconciler/v1alpha1/revision/config/controller_test.go +++ b/pkg/reconciler/v1alpha1/revision/config/controller_test.go @@ -55,7 +55,7 @@ func TestControllerConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ControllerConfigName, }, Data: map[string]string{ @@ -74,7 +74,7 @@ func TestControllerConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ControllerConfigName, }, Data: map[string]string{ @@ -88,7 +88,7 @@ func TestControllerConfiguration(t *testing.T) { wantController: (*Controller)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ControllerConfigName, }, Data: map[string]string{}, diff --git a/pkg/reconciler/v1alpha1/revision/config/network_test.go b/pkg/reconciler/v1alpha1/revision/config/network_test.go index 7028d0d136c2..933223aa6d8d 100644 --- a/pkg/reconciler/v1alpha1/revision/config/network_test.go +++ b/pkg/reconciler/v1alpha1/revision/config/network_test.go @@ -47,7 +47,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: &Network{}, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, }}, { @@ -56,7 +56,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -68,7 +68,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: &Network{}, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -80,7 +80,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -92,7 +92,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -104,7 +104,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -116,7 +116,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -128,7 +128,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: (*Network)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -140,7 +140,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: &Network{}, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -152,7 +152,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: &Network{}, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -164,7 +164,7 @@ func TestNetworkConfiguration(t *testing.T) { wantController: &Network{}, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -178,7 +178,7 @@ func TestNetworkConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -192,7 +192,7 @@ func TestNetworkConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ @@ -206,7 +206,7 @@ func TestNetworkConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: NetworkConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/revision/config/observability_test.go b/pkg/reconciler/v1alpha1/revision/config/observability_test.go index 57d8096f7a55..2b2d6b467c73 100644 --- a/pkg/reconciler/v1alpha1/revision/config/observability_test.go +++ b/pkg/reconciler/v1alpha1/revision/config/observability_test.go @@ -52,7 +52,7 @@ func TestObservabilityConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ObservabilityConfigName, }, Data: map[string]string{ @@ -71,7 +71,7 @@ func TestObservabilityConfiguration(t *testing.T) { }, config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ObservabilityConfigName, }, }, @@ -81,7 +81,7 @@ func TestObservabilityConfiguration(t *testing.T) { wantController: (*Observability)(nil), config: &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: ObservabilityConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/revision/queueing_test.go b/pkg/reconciler/v1alpha1/revision/queueing_test.go index 6e5b4aa964e1..95851cc0bda7 100644 --- a/pkg/reconciler/v1alpha1/revision/queueing_test.go +++ b/pkg/reconciler/v1alpha1/revision/queueing_test.go @@ -122,7 +122,7 @@ func getTestControllerConfigMap() *corev1.ConfigMap { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.ControllerConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ "queueSidecarImage": testQueueImage, @@ -149,7 +149,7 @@ func newTestController(t *testing.T, stopCh <-chan struct{}, servingObjects ...r cachingClient = fakecachingclientset.NewSimpleClientset() dynamicClient = fakedynamicclientset.NewSimpleDynamicClient(runtime.NewScheme()) - configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace} + configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace()} opt := rclr.Options{ KubeClientSet: kubeClient, @@ -186,11 +186,11 @@ func newTestController(t *testing.T, stopCh <-chan struct{}, servingObjects ...r getTestControllerConfigMap(), { ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.NetworkConfigName, }}, { ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: logging.ConfigName, }, Data: map[string]string{ @@ -198,7 +198,7 @@ func newTestController(t *testing.T, stopCh <-chan struct{}, servingObjects ...r "loglevel.queueproxy": "info", }}, { ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -207,7 +207,7 @@ func newTestController(t *testing.T, stopCh <-chan struct{}, servingObjects ...r "logging.fluentd-sidecar-output-config": testFluentdSidecarOutputConfig, }}, { ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: autoscaler.ConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/revision/resources/deploy_test.go b/pkg/reconciler/v1alpha1/revision/resources/deploy_test.go index 85546245a850..9a6bd5bac9eb 100644 --- a/pkg/reconciler/v1alpha1/revision/resources/deploy_test.go +++ b/pkg/reconciler/v1alpha1/revision/resources/deploy_test.go @@ -27,6 +27,8 @@ import ( "github.com/knative/serving/pkg/apis/serving/v1alpha1" "github.com/knative/serving/pkg/autoscaler" "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/config" + "github.com/knative/serving/pkg/system" + _ "github.com/knative/serving/pkg/system/testing" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -147,6 +149,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8888", // Match user port + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -235,6 +240,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -326,6 +334,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -421,6 +432,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -525,6 +539,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -627,6 +644,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -731,6 +751,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -831,6 +854,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, @@ -922,6 +948,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, { Name: FluentdContainerName, @@ -1085,6 +1114,9 @@ func TestMakePodSpec(t *testing.T) { }, { Name: "USER_PORT", Value: "8080", + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }}, Volumes: []corev1.Volume{varLogVolume}, diff --git a/pkg/reconciler/v1alpha1/revision/resources/queue.go b/pkg/reconciler/v1alpha1/revision/resources/queue.go index faa956f75853..c38236d7ace1 100644 --- a/pkg/reconciler/v1alpha1/revision/resources/queue.go +++ b/pkg/reconciler/v1alpha1/revision/resources/queue.go @@ -24,6 +24,7 @@ import ( "github.com/knative/serving/pkg/autoscaler" "github.com/knative/serving/pkg/queue" "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/config" + "github.com/knative/serving/pkg/system" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -135,6 +136,9 @@ func makeQueueContainer(rev *v1alpha1.Revision, loggingConfig *logging.Config, a }, { Name: "USER_PORT", Value: strconv.Itoa(int(userPort)), + }, { + Name: system.NamespaceEnvKey, + Value: system.Namespace(), }}, } } diff --git a/pkg/reconciler/v1alpha1/revision/resources/queue_test.go b/pkg/reconciler/v1alpha1/revision/resources/queue_test.go index 00cf97fc0deb..7268a5fbe7fe 100644 --- a/pkg/reconciler/v1alpha1/revision/resources/queue_test.go +++ b/pkg/reconciler/v1alpha1/revision/resources/queue_test.go @@ -26,6 +26,8 @@ import ( "github.com/knative/serving/pkg/apis/serving/v1alpha1" "github.com/knative/serving/pkg/autoscaler" "github.com/knative/serving/pkg/reconciler/v1alpha1/revision/config" + "github.com/knative/serving/pkg/system" + _ "github.com/knative/serving/pkg/system/testing" "go.uber.org/zap/zapcore" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -106,6 +108,9 @@ func TestMakeQueueContainer(t *testing.T) { }, { Name: "USER_PORT", Value: strconv.Itoa(v1alpha1.DefaultUserPort), + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, }, { @@ -174,6 +179,9 @@ func TestMakeQueueContainer(t *testing.T) { }, { Name: "USER_PORT", Value: strconv.Itoa(v1alpha1.DefaultUserPort), + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, }, { @@ -246,6 +254,9 @@ func TestMakeQueueContainer(t *testing.T) { }, { Name: "USER_PORT", Value: strconv.Itoa(v1alpha1.DefaultUserPort), + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, }, { @@ -316,6 +327,9 @@ func TestMakeQueueContainer(t *testing.T) { }, { Name: "USER_PORT", Value: strconv.Itoa(v1alpha1.DefaultUserPort), + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, }, { @@ -381,6 +395,9 @@ func TestMakeQueueContainer(t *testing.T) { }, { Name: "USER_PORT", Value: strconv.Itoa(v1alpha1.DefaultUserPort), + }, { + Name: "SYSTEM_NAMESPACE", + Value: system.Namespace(), }}, }, }} diff --git a/pkg/reconciler/v1alpha1/revision/revision_test.go b/pkg/reconciler/v1alpha1/revision/revision_test.go index 59928c79b59f..6b66fbef5b74 100644 --- a/pkg/reconciler/v1alpha1/revision/revision_test.go +++ b/pkg/reconciler/v1alpha1/revision/revision_test.go @@ -140,7 +140,7 @@ func newTestControllerWithConfig(t *testing.T, controllerConfig *config.Controll cachingClient = fakecachingclientset.NewSimpleClientset() dynamicClient = fakedynamic.NewSimpleDynamicClient(runtime.NewScheme()) - configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace} + configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace()} opt := rclr.Options{ KubeClientSet: kubeClient, @@ -177,12 +177,12 @@ func newTestControllerWithConfig(t *testing.T, controllerConfig *config.Controll var cms []*corev1.ConfigMap cms = append(cms, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.NetworkConfigName, }, }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: logging.ConfigName, }, Data: map[string]string{ @@ -191,7 +191,7 @@ func newTestControllerWithConfig(t *testing.T, controllerConfig *config.Controll }, }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -201,7 +201,7 @@ func newTestControllerWithConfig(t *testing.T, controllerConfig *config.Controll }, }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: autoscaler.ConfigName, }, Data: map[string]string{ @@ -401,7 +401,7 @@ func TestUpdateRevWithWithUpdatedLoggingURL(t *testing.T) { kubeClient, servingClient, cachingClient, _, controller, kubeInformer, servingInformer, cachingInformer, watcher, _ := newTestControllerWithConfig(t, controllerConfig, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -420,7 +420,7 @@ func TestUpdateRevWithWithUpdatedLoggingURL(t *testing.T) { // Update controllers logging URL watcher.OnChange(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -517,14 +517,14 @@ func TestNoQueueSidecarImageUpdateFail(t *testing.T) { watcher.OnChange(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: "config-controller", - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{}, }) createRevision(t, kubeClient, kubeInformer, servingClient, servingInformer, cachingClient, cachingInformer, controller, rev) // Look for the revision deployment. - _, err := kubeClient.AppsV1().Deployments(system.Namespace).Get(rev.Name, metav1.GetOptions{}) + _, err := kubeClient.AppsV1().Deployments(system.Namespace()).Get(rev.Name, metav1.GetOptions{}) if !apierrs.IsNotFound(err) { t.Errorf("Expected revision deployment %s to not exist.", rev.Name) } @@ -580,7 +580,7 @@ func getPodAnnotationsForConfig(t *testing.T, configMapValue string, configAnnot watcher.OnChange(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.NetworkConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ config.IstioOutboundIPRangesKey: configMapValue, @@ -622,7 +622,7 @@ func TestGlobalResyncOnConfigMapUpdate(t *testing.T) { configMapToUpdate: corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.NetworkConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ "istio.sidecar.includeOutboundIPRanges": "10.0.0.1/24", @@ -638,7 +638,7 @@ func TestGlobalResyncOnConfigMapUpdate(t *testing.T) { expected: "", configMapToUpdate: corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -658,7 +658,7 @@ func TestGlobalResyncOnConfigMapUpdate(t *testing.T) { expected: "http://log-here.test.com?filter=", configMapToUpdate: corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -677,7 +677,7 @@ func TestGlobalResyncOnConfigMapUpdate(t *testing.T) { expected: "newFluentdImage", configMapToUpdate: corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ObservabilityConfigName, }, Data: map[string]string{ @@ -703,7 +703,7 @@ func TestGlobalResyncOnConfigMapUpdate(t *testing.T) { expected: "myAwesomeQueueImage", configMapToUpdate: corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: config.ControllerConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/route/config/domain_test.go b/pkg/reconciler/v1alpha1/route/config/domain_test.go index 6fa228118874..99cac43248a9 100644 --- a/pkg/reconciler/v1alpha1/route/config/domain_test.go +++ b/pkg/reconciler/v1alpha1/route/config/domain_test.go @@ -62,7 +62,7 @@ func TestSelectorMatches(t *testing.T) { func TestNewConfigNoEntry(t *testing.T) { _, err := NewDomainFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: DomainConfigName, }, }) @@ -74,7 +74,7 @@ func TestNewConfigNoEntry(t *testing.T) { func TestNewConfigBadYaml(t *testing.T) { c, err := NewDomainFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: DomainConfigName, }, Data: map[string]string{ @@ -105,7 +105,7 @@ func TestNewConfig(t *testing.T) { } c, err := NewDomainFromConfigMap(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Namespace: system.Namespace, + Namespace: system.Namespace(), Name: DomainConfigName, }, Data: map[string]string{ diff --git a/pkg/reconciler/v1alpha1/route/queueing_test.go b/pkg/reconciler/v1alpha1/route/queueing_test.go index 42918d6ad34d..203029632e2d 100644 --- a/pkg/reconciler/v1alpha1/route/queueing_test.go +++ b/pkg/reconciler/v1alpha1/route/queueing_test.go @@ -64,7 +64,7 @@ func TestNewRouteCallsSyncHandler(t *testing.T) { configMapWatcher := configmap.NewStaticWatcher(&corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", @@ -73,7 +73,7 @@ func TestNewRouteCallsSyncHandler(t *testing.T) { }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: gc.ConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{}, }) diff --git a/pkg/reconciler/v1alpha1/route/resources/cluster_ingress.go b/pkg/reconciler/v1alpha1/route/resources/cluster_ingress.go index 67c6cccab387..b2058086020c 100644 --- a/pkg/reconciler/v1alpha1/route/resources/cluster_ingress.go +++ b/pkg/reconciler/v1alpha1/route/resources/cluster_ingress.go @@ -163,7 +163,7 @@ func addInactive(r *v1alpha1.HTTPClusterIngressPath, ns string, inactive []traff } r.Splits = append(r.Splits, v1alpha1.ClusterIngressBackendSplit{ ClusterIngressBackend: v1alpha1.ClusterIngressBackend{ - ServiceNamespace: system.Namespace, + ServiceNamespace: system.Namespace(), ServiceName: activator.K8sServiceName, ServicePort: intstr.FromInt(int(revisionresources.ServicePort)), }, diff --git a/pkg/reconciler/v1alpha1/route/resources/cluster_ingress_test.go b/pkg/reconciler/v1alpha1/route/resources/cluster_ingress_test.go index fada4ba67700..e140df142cc6 100644 --- a/pkg/reconciler/v1alpha1/route/resources/cluster_ingress_test.go +++ b/pkg/reconciler/v1alpha1/route/resources/cluster_ingress_test.go @@ -28,6 +28,8 @@ import ( "github.com/knative/serving/pkg/apis/serving/v1alpha1" "github.com/knative/serving/pkg/reconciler/v1alpha1/clusteringress" "github.com/knative/serving/pkg/reconciler/v1alpha1/route/traffic" + "github.com/knative/serving/pkg/system" + _ "github.com/knative/serving/pkg/system/testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -368,7 +370,7 @@ func TestMakeClusterIngressRule_InactiveTarget(t *testing.T) { Paths: []netv1alpha1.HTTPClusterIngressPath{{ Splits: []netv1alpha1.ClusterIngressBackendSplit{{ ClusterIngressBackend: netv1alpha1.ClusterIngressBackend{ - ServiceNamespace: "knative-serving", + ServiceNamespace: system.Namespace(), ServiceName: "activator-service", ServicePort: intstr.FromInt(80), }, @@ -420,7 +422,7 @@ func TestMakeClusterIngressRule_TwoInactiveTargets(t *testing.T) { Paths: []netv1alpha1.HTTPClusterIngressPath{{ Splits: []netv1alpha1.ClusterIngressBackendSplit{{ ClusterIngressBackend: netv1alpha1.ClusterIngressBackend{ - ServiceNamespace: "knative-serving", + ServiceNamespace: system.Namespace(), ServiceName: "activator-service", ServicePort: intstr.FromInt(80), }, diff --git a/pkg/reconciler/v1alpha1/route/route_test.go b/pkg/reconciler/v1alpha1/route/route_test.go index 6bfbcae23454..69f680df2823 100644 --- a/pkg/reconciler/v1alpha1/route/route_test.go +++ b/pkg/reconciler/v1alpha1/route/route_test.go @@ -142,7 +142,7 @@ func getTestRevisionForConfig(config *v1alpha1.Configuration) *v1alpha1.Revision func getActivatorDestinationWeight(w int) v1alpha3.DestinationWeight { return v1alpha3.DestinationWeight{ Destination: v1alpha3.Destination{ - Host: rclr.GetK8sServiceFullname(activator.K8sServiceName, system.Namespace), + Host: rclr.GetK8sServiceFullname(activator.K8sServiceName, system.Namespace()), Port: v1alpha3.PortSelector{ Number: 80, }, @@ -177,7 +177,7 @@ func newTestSetup(t *testing.T, configs ...*corev1.ConfigMap) ( { ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", @@ -187,7 +187,7 @@ func newTestSetup(t *testing.T, configs ...*corev1.ConfigMap) ( { ObjectMeta: metav1.ObjectMeta{ Name: gc.ConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{}, }, @@ -196,7 +196,7 @@ func newTestSetup(t *testing.T, configs ...*corev1.ConfigMap) ( cms = append(cms, cm) } - configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace} + configMapWatcher = &configmap.ManualWatcher{Namespace: system.Namespace()} servingClient = fakeclientset.NewSimpleClientset() // Create informer factories with fake clients. The second parameter sets the @@ -331,7 +331,7 @@ func TestCreateRouteForOneReserveRevision(t *testing.T) { Paths: []netv1alpha1.HTTPClusterIngressPath{{ Splits: []netv1alpha1.ClusterIngressBackendSplit{{ ClusterIngressBackend: netv1alpha1.ClusterIngressBackend{ - ServiceNamespace: "knative-serving", + ServiceNamespace: system.Namespace(), ServiceName: "activator-service", ServicePort: intstr.FromInt(80), }, @@ -510,7 +510,7 @@ func TestCreateRouteWithOneTargetReserve(t *testing.T) { Percent: 90, }, { ClusterIngressBackend: netv1alpha1.ClusterIngressBackend{ - ServiceNamespace: "knative-serving", + ServiceNamespace: system.Namespace(), ServiceName: "activator-service", ServicePort: intstr.FromInt(80), }, @@ -815,7 +815,7 @@ func TestUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", @@ -830,7 +830,7 @@ func TestUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ "newdefault.net": "", @@ -847,7 +847,7 @@ func TestUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ "mytestdomain.com": "selector:\n app: prod", @@ -887,7 +887,7 @@ func TestGlobalResyncOnUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", @@ -902,7 +902,7 @@ func TestGlobalResyncOnUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", @@ -917,7 +917,7 @@ func TestGlobalResyncOnUpdateDomainConfigMap(t *testing.T) { domainConfig := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: config.DomainConfigName, - Namespace: system.Namespace, + Namespace: system.Namespace(), }, Data: map[string]string{ defaultDomainSuffix: "", diff --git a/pkg/system/names.go b/pkg/system/names.go index a81a1fff6509..06ae5f5e7655 100644 --- a/pkg/system/names.go +++ b/pkg/system/names.go @@ -16,8 +16,37 @@ limitations under the License. package system +import ( + "fmt" + "os" +) + const ( - // Namespace holds the K8s namespace where our serving system - // components run. - Namespace = "knative-serving" + NamespaceEnvKey = "SYSTEM_NAMESPACE" ) + +// Namespace holds the K8s namespace where our serving system +// components run. +func Namespace() string { + if ns := os.Getenv(NamespaceEnvKey); ns != "" { + return ns + } + + panic(fmt.Sprintf(`The environment variable %q is not set + +If this is a process running on Kubernetes, then it should be using the downward +API to initialize this variable via: + + env: + - name: %s + valueFrom: + fieldRef: + fieldPath: metadata.namespace + +If this is a Go unit test consuming system.Namespace() then it should add the +following import: + +import ( + _ "github.com/knative/serving/pkg/system/testing" +)`, NamespaceEnvKey, NamespaceEnvKey)) +} diff --git a/pkg/system/testing/names.go b/pkg/system/testing/names.go new file mode 100644 index 000000000000..67d626ee77d3 --- /dev/null +++ b/pkg/system/testing/names.go @@ -0,0 +1,28 @@ +/* +Copyright 2018 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 + + https://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 testing + +import ( + "os" + + "github.com/knative/serving/pkg/system" +) + +func init() { + os.Setenv(system.NamespaceEnvKey, "knative-testing") + +} diff --git a/test/config/300-controller.yaml b/test/config/300-controller.yaml index 8c8db6877986..44ee7abb50c5 100644 --- a/test/config/300-controller.yaml +++ b/test/config/300-controller.yaml @@ -35,3 +35,8 @@ spec: # This is the Go import path for the binary that is containerized # and substituted here. image: github.com/knative/serving/test/controller + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace diff --git a/test/conformance/blue_green_test.go b/test/conformance/blue_green_test.go index 521d80df0c02..77da1e86d95b 100644 --- a/test/conformance/blue_green_test.go +++ b/test/conformance/blue_green_test.go @@ -27,6 +27,7 @@ import ( pkgTest "github.com/knative/pkg/test" "github.com/knative/pkg/test/logging" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" "golang.org/x/sync/errgroup" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/test/conformance/single_threaded_test.go b/test/conformance/single_threaded_test.go index 3e5b011fdbea..1c70c472e1d2 100644 --- a/test/conformance/single_threaded_test.go +++ b/test/conformance/single_threaded_test.go @@ -30,6 +30,7 @@ import ( pkgTest "github.com/knative/pkg/test" "github.com/knative/pkg/test/logging" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/test/e2e/autoscale_test.go b/test/e2e/autoscale_test.go index cc8b184a7511..a8c6730022db 100644 --- a/test/e2e/autoscale_test.go +++ b/test/e2e/autoscale_test.go @@ -28,6 +28,7 @@ import ( pkgTest "github.com/knative/pkg/test" "github.com/knative/pkg/test/logging" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" "github.com/pkg/errors" "golang.org/x/sync/errgroup" diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 3ba9254282d5..d7b270a51469 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -36,6 +36,7 @@ import ( pkgTest "github.com/knative/pkg/test" "github.com/knative/pkg/test/logging" "github.com/knative/serving/pkg/apis/serving/v1alpha1" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" ) diff --git a/test/upgrade/service_postdowngrade_test.go b/test/upgrade/service_postdowngrade_test.go index 609262fa5340..70f8651e7a3f 100644 --- a/test/upgrade/service_postdowngrade_test.go +++ b/test/upgrade/service_postdowngrade_test.go @@ -23,6 +23,7 @@ import ( "github.com/knative/pkg/test/logging" serviceresourcenames "github.com/knative/serving/pkg/reconciler/v1alpha1/service/resources/names" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" "github.com/knative/serving/test/e2e" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/test/upgrade/service_postupgrade_test.go b/test/upgrade/service_postupgrade_test.go index ae97a1b33098..a5ffc043fc34 100644 --- a/test/upgrade/service_postupgrade_test.go +++ b/test/upgrade/service_postupgrade_test.go @@ -23,6 +23,7 @@ import ( "github.com/knative/pkg/test/logging" serviceresourcenames "github.com/knative/serving/pkg/reconciler/v1alpha1/service/resources/names" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" "github.com/knative/serving/test/e2e" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/test/upgrade/service_preupgrade_test.go b/test/upgrade/service_preupgrade_test.go index 089e7e825688..ad55b7f95df9 100644 --- a/test/upgrade/service_preupgrade_test.go +++ b/test/upgrade/service_preupgrade_test.go @@ -23,6 +23,7 @@ import ( "github.com/knative/pkg/test/logging" serviceresourcenames "github.com/knative/serving/pkg/reconciler/v1alpha1/service/resources/names" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" "github.com/knative/serving/test/e2e" ) diff --git a/test/upgrade/upgrade.go b/test/upgrade/upgrade.go index caeb72b7e506..b9cd9d8b3b7d 100644 --- a/test/upgrade/upgrade.go +++ b/test/upgrade/upgrade.go @@ -28,6 +28,7 @@ import ( pkgTest "github.com/knative/pkg/test" "github.com/knative/pkg/test/logging" "github.com/knative/serving/pkg/apis/serving/v1alpha1" + _ "github.com/knative/serving/pkg/system/testing" "github.com/knative/serving/test" )