Skip to content

Commit

Permalink
User can specify the namespace in yaml for knative-serving (#2708)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zxxa authored and knative-prow-robot committed Jan 18, 2019
1 parent 917696f commit 3d137ac
Show file tree
Hide file tree
Showing 43 changed files with 241 additions and 97 deletions.
4 changes: 2 additions & 2 deletions cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion cmd/autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions cmd/queue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,6 +68,7 @@ var (
servingRevision string
servingRevisionKey string
servingAutoscaler string
autoscalerNamespace string
servingAutoscalerPort int
userTargetPort int
userTargetAddress string
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions config/activator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/autoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions config/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions pkg/logging/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
})
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/testing/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/v1alpha1/autoscaling/kpa/kpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions pkg/reconciler/v1alpha1/clusteringress/clusteringress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
}}
Expand Down Expand Up @@ -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,
},
Expand All @@ -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()

Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/clusteringress/config/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}}, {
Expand All @@ -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{
Expand All @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/configuration/queueing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/revision/config/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{},
Expand Down
Loading

0 comments on commit 3d137ac

Please sign in to comment.