Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 37 additions & 3 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"flag"
"log"
"net/http"
"time"

Expand All @@ -42,13 +43,18 @@ import (
"github.com/knative/eventing/pkg/controller/flow"
"github.com/knative/eventing/pkg/signals"

"github.com/knative/serving/pkg/configmap"
"github.com/knative/serving/pkg/logging"
"github.com/knative/serving/pkg/logging/logkey"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
)

const (
threadsPerController = 2
metricsScrapeAddr = ":9090"
metricsScrapePath = "/metrics"
logLevelKey = "controller"
)

var (
Expand All @@ -57,7 +63,20 @@ var (
)

func main() {

flag.Parse()
cm, err := configmap.Load("/etc/config-logging")
if err != nil {
log.Fatalf("Error loading logging configuration: %v", err)
}
config, err := logging.NewConfigFromMap(cm)
if err != nil {
log.Fatalf("Error parsing logging configuration: %v", err)
}
logger, atomicLevel := logging.NewLoggerFromConfig(config, logLevelKey)
defer logger.Sync()
logger = logger.With(zap.String(logkey.ControllerType, "controller"))
logger.Info("Starting the knative controller")

// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()
Expand All @@ -72,7 +91,7 @@ func main() {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
}

client, err := clientset.NewForConfig(cfg)
eventingClient, err := clientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building clientset: %s", err.Error())
}
Expand All @@ -90,9 +109,17 @@ func main() {
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
informerFactory := informers.NewSharedInformerFactory(client, time.Second*30)
informerFactory := informers.NewSharedInformerFactory(eventingClient, time.Second*30)
servingInformerFactory := servinginformers.NewSharedInformerFactory(servingClient, time.Second*30)

opt := controller.Options{
KubeClientSet: kubeClient,
ServingClientSet: servingClient,
BuildClientSet: buildClient,
ConfigMapWatcher: configMapWatcher,
Logger: logger,
}

// Add new controllers here.
ctors := []controller.Constructor{
flow.NewController,
Expand All @@ -105,7 +132,7 @@ func main() {
controllers := make([]controller.Interface, 0, len(ctors))
for _, ctor := range ctors {
controllers = append(controllers,
ctor(kubeClient, client, servingClient, restConfig, kubeInformerFactory, informerFactory, servingInformerFactory))
ctor(kubeClient, eventingClient, servingClient, restConfig, kubeInformerFactory, informerFactory, servingInformerFactory))
}

go kubeInformerFactory.Start(stopCh)
Expand Down Expand Up @@ -133,6 +160,13 @@ func main() {
}
}()

// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewDefaultWatcher(kubeClient, system.Namespace)
configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logLevelKey))
if err = configMapWatcher.Start(stopCh); err != nil {
logger.Fatalf("failed to start configuration manager: %v", err)
}

<-stopCh

// Close the http server gracefully
Expand Down
15 changes: 12 additions & 3 deletions config/500-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ spec:
- name: eventing-controller
image: github.com/knative/eventing/cmd/controller
args: [
"-logtostderr",
"-stderrthreshold", "INFO",
]
# Disable glog writing into stderr. Our code doesn't use glog
# and seeing k8s logs in addition to ours is not useful.
- "-logtostderr=false"
- "-stderrthreshold=FATAL"
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
volumes:
- name: config-logging
configMap:
name: config-logging

48 changes: 48 additions & 0 deletions config/config-logging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.

apiVersion: v1
kind: ConfigMap
metadata:
name: config-logging
namespace: knative-eventing
data:
# Common configuration for all Knative codebase
zap-logger-config: |
{
"level": "info",
"development": false,
"outputPaths": ["stdout"],
"errorOutputPaths": ["stderr"],
"encoding": "json",
"encoderConfig": {
"timeKey": "ts",
"levelKey": "level",
"nameKey": "logger",
"callerKey": "caller",
"messageKey": "msg",
"stacktraceKey": "stacktrace",
"lineEnding": "",
"levelEncoder": "",
"timeEncoder": "iso8601",
"durationEncoder": "",
"callerEncoder": ""
}
}

# Log level overrides
# For all components changes are be picked up immediately.
loglevel.controller: "info"
loglevel.webhook: "info"

Loading