github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/config_util.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/datawire/dlib/dlog"
     7  	"github.com/telepresenceio/telepresence/v2/pkg/log"
     8  )
     9  
    10  func MergeAndReplace(c context.Context, defaults Config, priority Config, root bool) error {
    11  	if defaults == nil {
    12  		defaults = GetDefaultConfig()
    13  	}
    14  	defaults.Merge(priority)
    15  	ReplaceConfig(c, defaults)
    16  	return ReloadDaemonConfig(c, root)
    17  }
    18  
    19  func RestoreDefaults(c context.Context, root bool) error {
    20  	pri, err := LoadConfig(c)
    21  	if err != nil {
    22  		return err
    23  	}
    24  	return MergeAndReplace(c, nil, pri, root)
    25  }
    26  
    27  // ReloadDaemonConfig calls SetLevel with the log level defined
    28  // for the rootDaemon or userDaemon
    29  // depending on the root flag. Assumes that the config has already been reloaded.
    30  func ReloadDaemonConfig(c context.Context, root bool) error {
    31  	newCfg := GetConfig(c)
    32  	var level string
    33  	if root {
    34  		level = newCfg.LogLevels().RootDaemon.String()
    35  	} else {
    36  		level = newCfg.LogLevels().UserDaemon.String()
    37  	}
    38  	log.SetLevel(c, level)
    39  	dlog.Info(c, "Configuration reloaded")
    40  	return nil
    41  }