<p>I want to change config of log on Golang application which run on K8S,
I’ve tried the following code locally and it works as expected
I'm using viper to watch for config file changes</p>

<p>This is the config map with the log configuration </p>

<pre><code>apiVersion: v1
kind: ConfigMap
data:
  config.yaml: 'log.level: error'
metadata:
  name: app-config
  namespace: logger
</code></pre>

<p>In the deployment yaml I’ve added the following</p>

<pre><code>...
spec:
  containers:
    - name: gowebapp
      image: mvd/myapp:0.0.3
      ports:
        - containerPort: 80
      envFrom:
        - configMapRef:
            name: app-config
</code></pre>

<p>This is the code </p>

<pre><code>package configuration

import (
   "fmt"
   "os"
   "strings"

   "github.com/fsnotify/fsnotify"
   "github.com/sirupsen/logrus"
   "github.com/spf13/viper"
)

const (
   varLogLevel     = "log.level
"
   varPathToConfig = "config.file"
)

type Configuration struct {
   v *viper.Viper
}

func New() *Configuration {
   c := Configuration{
      v: viper.New(),
   }

   c.v.SetDefault(varPathToConfig, "./config.yaml")
   c.v.SetDefault(varLogLevel, "info")
   c.v.AutomaticEnv()
   c.v.SetConfigFile(c.GetPathToConfig())
   err := c.v.ReadInConfig() // Find and read the config file
   logrus.WithField("path", c.GetPathToConfig()).Warn("loading config")
   if _, ok := err.(*os.PathError); ok {
      logrus.Warnf("no config file '%s' not found. Using default values", c.GetPathToConfig())
   } else if err != nil { // Handle other errors that occurred while reading the config file
      panic(fmt.Errorf("fatal error while reading the config file: %s", err))
   }
   setLogLevel(c.GetLogLevel())
   c.v.WatchConfig()
   c.v.OnConfigChange(func(e fsnotify.Event) {
      logrus.WithField("file", e.Name).Warn("Config file changed")
      setLogLevel(c.GetLogLevel())
   })
   return &amp;c
}

// GetLogLevel returns the log level
func (c *Configuration) GetLogLevel() string {
   s := c.v.GetString(varLogLevel)
   return s
}

// GetPathToConfig returns the path to the config file
func (c *Configuration) GetPathToConfig() string {
   return c.v.GetString(varPathToConfig)
}

func setLogLevel(logLevel string) {
   logrus.WithField("level", logLevel).Warn("setting log level")
   level, err := logrus.ParseLevel(logLevel)
   if err != nil {
      logrus.WithField("level", logLevel).Fatalf("failed to start: %s", err.Error())
   }
   logrus.SetLevel(level)
}

</code></pre>

<p>Now when I apply the yaml file again and changing the value from <code>error</code> to <code>warn</code> or <code>debug</code> etc
Nothing change … any idea what I miss here ? </p>

<p>I see in the K8S dashboard that the config map is <strong>assigned to the application</strong> and when I change the value I see that the env was changed...</p>

<p><strong>update</strong></p>

<p>when run it locally I use the following config just for testing
but when using config map I've used the <code>data</code> entry according to the spec of configmap ...</p>

<pre><code>apiVersion: v1
kind: ConfigMap
log.level: 'warn'
#data:
#  config.yaml: 'log.level: error'
metadata:
  name: app-config

</code></pre>

<p><strong>This is how the config env looks in k8s dashboard</strong> </p>

<p><a href="https://i.stack.imgur.com/GWCUB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GWCUB.png" alt="enter image description here"></a></p>

<p>envFrom creates environment variables from the config map. There is no file that changes. If you exec into the container you'll probably see an environment variable named config.yaml or CONFIG.YAML or similar (don' t know if it works with dots).</p>

<p>You are probably better of if you mount config.yaml as a file inside your pods, like this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume" rel="nofollow noreferrer">Add ConfigMap data to a Volume</a></p>
