From 18f067f5ff34d5247b916ca6643209e47cfebf0a Mon Sep 17 00:00:00 2001 From: xu zhao Date: Mon, 7 Jan 2019 17:40:57 +0800 Subject: [PATCH] use getter method for namespaces --- cmd/activator/main.go | 4 +-- cmd/autoscaler/main.go | 2 +- cmd/controller/main.go | 2 +- cmd/queue/main.go | 2 +- cmd/webhook/main.go | 4 +-- pkg/logging/config_test.go | 12 ++++---- .../v1alpha1/autoscaling/kpa/kpa_test.go | 2 +- .../clusteringress/clusteringress_test.go | 10 +++---- .../clusteringress/config/istio_test.go | 6 ++-- .../clusteringress/resources/names/names.go | 2 +- .../resources/virtual_service.go | 2 +- .../resources/virtual_service_test.go | 2 +- .../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 ++++---- .../v1alpha1/revision/revision_test.go | 20 ++++++------- .../v1alpha1/route/config/domain_test.go | 6 ++-- .../v1alpha1/route/queueing_test.go | 4 +-- .../route/resources/cluster_ingress.go | 2 +- pkg/reconciler/v1alpha1/route/route_test.go | 20 ++++++------- pkg/system/names.go | 15 ++++------ 23 files changed, 84 insertions(+), 87 deletions(-) diff --git a/cmd/activator/main.go b/cmd/activator/main.go index f038a7bb0d23..5470c4d877bf 100644 --- a/cmd/activator/main.go +++ b/cmd/activator/main.go @@ -141,7 +141,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) @@ -168,7 +168,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 53373c8b9203..868268164511 100644 --- a/cmd/autoscaler/main.go +++ b/cmd/autoscaler/main.go @@ -89,7 +89,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 588c05460506..b027399fd5bc 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -112,7 +112,7 @@ func main() { logger.Fatalf("Error building caching clientset: %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 a0f393f4007c..e3941bd2864e 100644 --- a/cmd/queue/main.go +++ b/cmd/queue/main.go @@ -302,7 +302,7 @@ func main() { }() // Open a websocket connection to the autoscaler - autoscalerEndpoint := fmt.Sprintf("ws://%s.%s:%d", servingAutoscaler, system.Namespace, servingAutoscalerPort) + autoscalerEndpoint := fmt.Sprintf("ws://%s.%s:%d", servingAutoscaler, system.Namespace(), 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 eb4d520c9a12..8cc483150073 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -70,7 +70,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) @@ -79,7 +79,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/pkg/logging/config_test.go b/pkg/logging/config_test.go index 9f8c21a86643..603fc6e97105 100644 --- a/pkg/logging/config_test.go +++ b/pkg/logging/config_test.go @@ -119,7 +119,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 +139,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 +187,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 +207,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 +225,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 +245,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/v1alpha1/autoscaling/kpa/kpa_test.go b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go index 4b78c08e9e1e..e163eeb9c345 100644 --- a/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go +++ b/pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go @@ -59,7 +59,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 6d28b14a4f9d..4c39f71ae6da 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go +++ b/pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go @@ -154,7 +154,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 +195,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 +286,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 +295,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() @@ -389,7 +389,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..c5811e330634 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go +++ b/pkg/reconciler/v1alpha1/clusteringress/resources/names/names.go @@ -25,7 +25,7 @@ import ( // K8sGatewayFullname is the fully-qualified name of Knative shared gateway. var K8sGatewayFullname = reconciler.GetK8sServiceFullname( "knative-shared-gateway", - system.Namespace) + system.Namespace()) // VirtualService returns the name of the VirtualService child resource for given ClusterIngress. func VirtualService(i *v1alpha1.ClusterIngress) string { diff --git a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service.go index c71115395271..3f7e7a80d59b 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 29c699c7315d..7cb003e69ec3 100644 --- a/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go +++ b/pkg/reconciler/v1alpha1/clusteringress/resources/virtual_service_test.go @@ -45,7 +45,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 3d2eb31fa249..f9437d35a993 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/revision_test.go b/pkg/reconciler/v1alpha1/revision/revision_test.go index 59928c79b59f..440ca52dc0d9 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, diff --git a/pkg/reconciler/v1alpha1/route/config/domain_test.go b/pkg/reconciler/v1alpha1/route/config/domain_test.go index 8b8a906acf7e..53bf850412c5 100644 --- a/pkg/reconciler/v1alpha1/route/config/domain_test.go +++ b/pkg/reconciler/v1alpha1/route/config/domain_test.go @@ -61,7 +61,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, }, }) @@ -73,7 +73,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{ @@ -104,7 +104,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 eebf3807bb46..ed64ca964352 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/route_test.go b/pkg/reconciler/v1alpha1/route/route_test.go index bf09bb79d650..6c0bdf8da77b 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 @@ -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 85ef512ed291..1bf518fe8f08 100644 --- a/pkg/system/names.go +++ b/pkg/system/names.go @@ -18,15 +18,12 @@ package system import "os" -var ( - // Namespace holds the K8s namespace where our build system - // components run. - Namespace string +const ( + NamespaceEnvKey = "SYSTEM_NAMESPACE" ) -func init() { - Namespace = os.Getenv("SYSTEM_NAMESPACE") - if Namespace == "" { - Namespace = "knative-serving" - } +// Namespace holds the K8s namespace where our build system +// components run. +func Namespace() string { + return os.Getenv(NamespaceEnvKey) }