Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Use pkg/logging (#328)
Browse files Browse the repository at this point in the history
* Use pkg logging

* add logging config to controller and add configMAp

* Use pkg/logkey
  • Loading branch information
shashwathi authored and knative-prow-robot committed Sep 4, 2018
1 parent 66a754c commit 4dfa5da
Show file tree
Hide file tree
Showing 26 changed files with 611 additions and 125 deletions.
16 changes: 7 additions & 9 deletions Gopkg.lock

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

5 changes: 5 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ required = [
name = "github.com/knative/test-infra"
unused-packages = false
non-go = false

[[constraint]]
name = "github.com/knative/pkg"
revision = "6eff182b8784a136e0ce20e47c5efbfe40ae6059"

22 changes: 19 additions & 3 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package main

import (
"flag"
"log"
"time"

"go.uber.org/zap"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -32,14 +34,19 @@ import (
"github.com/knative/build/pkg/controller/build"
"github.com/knative/build/pkg/controller/buildtemplate"
"github.com/knative/build/pkg/controller/clusterbuildtemplate"
"github.com/knative/build/pkg/logging"

buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
informers "github.com/knative/build/pkg/client/informers/externalversions"
"github.com/knative/pkg/configmap"
"github.com/knative/pkg/logging"
"github.com/knative/pkg/logging/logkey"
"github.com/knative/pkg/signals"
)

const threadsPerController = 2
const (
threadsPerController = 2
logLevelKey = "controller"
)

var (
kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
Expand All @@ -48,8 +55,17 @@ var (

func main() {
flag.Parse()
logger := logging.NewLoggerFromDefaultConfigMap("loglevel.controller").Named("controller")
loggingConfigMap, err := configmap.Load("/etc/config-logging")
if err != nil {
log.Fatalf("Error loading logging configuration: %v", err)
}
loggingConfig, err := logging.NewConfigFromMap(loggingConfigMap)
if err != nil {
log.Fatalf("Error parsing logging configuration: %v", err)
}
logger, _ := logging.NewLoggerFromConfig(loggingConfig, logLevelKey)
defer logger.Sync()
logger = logger.With(zap.String(logkey.ControllerType, logLevelKey))

logger.Info("Starting the Build Controller")

Expand Down
6 changes: 4 additions & 2 deletions cmd/creds-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"github.com/knative/build/pkg/credentials"
"github.com/knative/build/pkg/credentials/dockercreds"
"github.com/knative/build/pkg/credentials/gitcreds"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

func main() {
flag.Parse()
logger := logging.NewLoggerFromDefaultConfigMap("loglevel.creds-init").Named("creds-init")

// ignore atomic level because we are not watching this config for any updates
logger, _ := logging.NewLogger("", "git-init")
defer logger.Sync()

builders := []credentials.Builder{dockercreds.NewBuilder(), gitcreds.NewBuilder()}
Expand Down
4 changes: 2 additions & 2 deletions cmd/git-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"os/exec"

"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -53,7 +53,7 @@ func runOrFail(logger *zap.SugaredLogger, cmd string, args ...string) {

func main() {
flag.Parse()
logger := logging.NewLoggerFromDefaultConfigMap("loglevel.git-init").Named("git-init")
logger, _ := logging.NewLogger("", "git-init")
defer logger.Sync()

// HACK HACK HACK
Expand Down
21 changes: 19 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ import (
"github.com/knative/build/pkg"
onclusterbuilder "github.com/knative/build/pkg/builder/cluster"
buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
"github.com/knative/build/pkg/logging"
"github.com/knative/build/pkg/webhook"
"github.com/knative/pkg/configmap"
"github.com/knative/pkg/logging"
"github.com/knative/pkg/logging/logkey"
"github.com/knative/pkg/signals"
)

const (
logLevelKey = "webhook"
)

func main() {

flag.Parse()
logger := logging.NewLoggerFromDefaultConfigMap("loglevel.webhook").Named("webhook")
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, _ := logging.NewLoggerFromConfig(config, logLevelKey)
defer logger.Sync()
logger = logger.With(zap.String(logkey.ControllerType, "webhook"))

logger.Info("Starting the Configuration Webhook")

Expand Down
7 changes: 7 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ spec:
"-creds-image", "github.com/knative/build/cmd/creds-init",
"-git-image", "github.com/knative/build/cmd/git-init",
]
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
volumes:
- name: config-logging
configMap:
name: config-logging
2 changes: 1 addition & 1 deletion pkg/controller/build/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

"github.com/knative/build/pkg/builder"
"github.com/knative/build/pkg/controller"
"github.com/knative/build/pkg/logging/logkey"
"github.com/knative/pkg/logging/logkey"

v1alpha1 "github.com/knative/build/pkg/apis/build/v1alpha1"

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/buildtemplate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

"github.com/knative/build/pkg/builder"
"github.com/knative/build/pkg/controller"
"github.com/knative/build/pkg/logging/logkey"
"github.com/knative/pkg/logging/logkey"

clientset "github.com/knative/build/pkg/client/clientset/versioned"
informers "github.com/knative/build/pkg/client/informers/externalversions"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clusterbuildtemplate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

"github.com/knative/build/pkg/builder"
"github.com/knative/build/pkg/controller"
"github.com/knative/build/pkg/logging/logkey"
"github.com/knative/pkg/logging/logkey"

clientset "github.com/knative/build/pkg/client/clientset/versioned"
informers "github.com/knative/build/pkg/client/informers/externalversions"
Expand Down
79 changes: 0 additions & 79 deletions pkg/logging/config.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/webhook/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

func (ac *AdmissionController) validateBuild(ctx context.Context, _ *[]jsonpatch.JsonPatchOperation, old, new genericCRD) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/build_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/mattbaird/jsonpatch"

"github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

func (ac *AdmissionController) validateBuildTemplate(ctx context.Context, _ *[]jsonpatch.JsonPatchOperation, old, new genericCRD) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.uber.org/zap"

"github.com/knative/build/pkg"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/cluster_build_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/mattbaird/jsonpatch"

"github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

func (ac *AdmissionController) validateClusterBuildTemplate(ctx context.Context, _ *[]jsonpatch.JsonPatchOperation, old, new genericCRD) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import (
"github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/build/pkg/builder"
buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
"github.com/knative/build/pkg/logging"
"github.com/knative/build/pkg/logging/logkey"
"github.com/knative/pkg/logging"
"github.com/knative/pkg/logging/logkey"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/knative/build/pkg/apis/build/v1alpha1"
"github.com/knative/build/pkg/builder/nop"
fakebuildclientset "github.com/knative/build/pkg/client/clientset/versioned/fake"
"github.com/knative/build/pkg/logging"
"github.com/knative/pkg/logging"
)

const (
Expand Down
Loading

0 comments on commit 4dfa5da

Please sign in to comment.