Skip to content

Commit

Permalink
cilium-operator.Dockerfile: set klog logging values from cilium-ope…
Browse files Browse the repository at this point in the history
…rator

`klog`, which is used by the Kubernetes libraries consumed by `cilium-operator`,
always tries to log to a file in `/tmp`. Since the `cilium-operator` container
image is built off of `scratch`, such a directory does not exist. If the
directory does not exist, `klog` exits and causes `cilium-operator` to crash.
To not crash, do not log to any directories, and instead set the `logtostderr`
value within `klog` to `true` so that it does not log to a directory.

Fixes: cilium#7006

Signed-off by: Ian Vernon <ian@cilium.io>
  • Loading branch information
Ian Vernon authored and borkmann committed Feb 13, 2019
1 parent dc3cb06 commit eee2e8d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/klog"
)

var (
Expand Down Expand Up @@ -110,6 +111,15 @@ func init() {
option.BindEnv(option.DisableCiliumEndpointCRDName)

viper.BindPFlags(flags)

// Make sure that klog logging variables are initialized so that we can
// update them from this file.
klog.InitFlags(nil)

// Make sure klog (used by the client-go dependency) logs to stderr, as it
// will try to log to directories that may not exist in the cilium-operator
// container (/tmp) and cause the cilium-operator to exit.
flag.Set("logtostderr", "true")
}

// initConfig reads in config file and ENV variables if set.
Expand All @@ -130,11 +140,6 @@ func initConfig() {
func runOperator(cmd *cobra.Command) {
logging.SetupLogging([]string{}, map[string]string{}, "cilium-operator", viper.GetBool("debug"))

// Make sure glog (used by the client-go dependency) logs to stderr, as it
// will try to log to directories that may not exist in the cilium-operator
// container and cause the cilium-operator to exit.
flag.Set("logtostderr", "true")

log.Infof("Cilium Operator %s", version.Version)

if err := kvstore.Setup(kvStore, kvStoreOpts); err != nil {
Expand Down

0 comments on commit eee2e8d

Please sign in to comment.