overall/logging: new trace log level
- new root flag '--trace' with precedence over '--verbose' - some new trace logs - migrated some debug logs to trace logs to reduce debug verbosity
This commit is contained in:
parent
da0b23331f
commit
11cc797922
@ -315,7 +315,7 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string, createClusterOpts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("PortFilterMap: %+v", portFilterMap)
|
log.Tracef("PortFilterMap: %+v", portFilterMap)
|
||||||
|
|
||||||
/********************
|
/********************
|
||||||
* *
|
* *
|
||||||
|
@ -45,6 +45,7 @@ import (
|
|||||||
// RootFlags describes a struct that holds flags that can be set on root level of the command
|
// RootFlags describes a struct that holds flags that can be set on root level of the command
|
||||||
type RootFlags struct {
|
type RootFlags struct {
|
||||||
debugLogging bool
|
debugLogging bool
|
||||||
|
traceLogging bool
|
||||||
version bool
|
version bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ func init() {
|
|||||||
// add persistent flags (present to all subcommands)
|
// add persistent flags (present to all subcommands)
|
||||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k3d/config.yaml)")
|
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.k3d/config.yaml)")
|
||||||
rootCmd.PersistentFlags().BoolVar(&flags.debugLogging, "verbose", false, "Enable verbose output (debug logging)")
|
rootCmd.PersistentFlags().BoolVar(&flags.debugLogging, "verbose", false, "Enable verbose output (debug logging)")
|
||||||
|
rootCmd.PersistentFlags().BoolVar(&flags.traceLogging, "trace", false, "Enable super verbose output (trace logging)")
|
||||||
|
|
||||||
// add local flags
|
// add local flags
|
||||||
rootCmd.Flags().BoolVar(&flags.version, "version", false, "Show k3d and default k3s version")
|
rootCmd.Flags().BoolVar(&flags.version, "version", false, "Show k3d and default k3s version")
|
||||||
@ -121,10 +123,14 @@ func init() {
|
|||||||
|
|
||||||
// initLogging initializes the logger
|
// initLogging initializes the logger
|
||||||
func initLogging() {
|
func initLogging() {
|
||||||
if flags.debugLogging {
|
if flags.traceLogging {
|
||||||
|
log.SetLevel(log.TraceLevel)
|
||||||
|
} else if flags.debugLogging {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
} else {
|
} else {
|
||||||
switch logLevel := strings.ToUpper(os.Getenv("LOG_LEVEL")); logLevel {
|
switch logLevel := strings.ToUpper(os.Getenv("LOG_LEVEL")); logLevel {
|
||||||
|
case "TRACE":
|
||||||
|
log.SetLevel(log.TraceLevel)
|
||||||
case "DEBUG":
|
case "DEBUG":
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
case "WARN":
|
case "WARN":
|
||||||
@ -150,6 +156,7 @@ func initLogging() {
|
|||||||
LogLevels: []log.Level{
|
LogLevels: []log.Level{
|
||||||
log.InfoLevel,
|
log.InfoLevel,
|
||||||
log.DebugLevel,
|
log.DebugLevel,
|
||||||
|
log.TraceLevel,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
log.SetFormatter(&log.TextFormatter{
|
log.SetFormatter(&log.TextFormatter{
|
||||||
|
@ -277,7 +277,6 @@ func ClusterCreate(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
|
|||||||
servers := ""
|
servers := ""
|
||||||
for _, node := range cluster.Nodes {
|
for _, node := range cluster.Nodes {
|
||||||
if node.Role == k3d.ServerRole {
|
if node.Role == k3d.ServerRole {
|
||||||
log.Debugf("Node NAME: %s", node.Name)
|
|
||||||
if servers == "" {
|
if servers == "" {
|
||||||
servers = node.Name
|
servers = node.Name
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,7 @@ func GetHostIP(ctx context.Context, rtime rt.Runtime, cluster *k3d.Cluster) (net
|
|||||||
// Docker Runtime
|
// Docker Runtime
|
||||||
if rtime == rt.Docker {
|
if rtime == rt.Docker {
|
||||||
|
|
||||||
log.Debugf("Runtime GOOS: %s", runtime.GOOS)
|
log.Tracef("Runtime GOOS: %s", runtime.GOOS)
|
||||||
|
|
||||||
// "native" Docker on Linux
|
// "native" Docker on Linux
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
@ -81,11 +81,14 @@ func resolveHostnameFromInside(ctx context.Context, rtime rt.Runtime, node *k3d.
|
|||||||
submatches := map[string]string{}
|
submatches := map[string]string{}
|
||||||
scanner := bufio.NewScanner(logreader)
|
scanner := bufio.NewScanner(logreader)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
log.Tracef("Scanning Log Line '%s'", scanner.Text())
|
||||||
match := nsLookupAddressRegexp.FindStringSubmatch(scanner.Text())
|
match := nsLookupAddressRegexp.FindStringSubmatch(scanner.Text())
|
||||||
if len(match) == 0 {
|
if len(match) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
log.Tracef("-> Match(es): '%+v'", match)
|
||||||
submatches = util.MapSubexpNames(nsLookupAddressRegexp.SubexpNames(), match)
|
submatches = util.MapSubexpNames(nsLookupAddressRegexp.SubexpNames(), match)
|
||||||
|
log.Tracef(" -> Submatch(es): %+v", submatches)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if _, ok := submatches["ip"]; !ok {
|
if _, ok := submatches["ip"]; !ok {
|
||||||
|
@ -194,7 +194,7 @@ func KubeconfigGet(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.C
|
|||||||
// set current-context to new context name
|
// set current-context to new context name
|
||||||
kc.CurrentContext = newContextName
|
kc.CurrentContext = newContextName
|
||||||
|
|
||||||
log.Debugf("Modified Kubeconfig: %+v", kc)
|
log.Tracef("Modified Kubeconfig: %+v", kc)
|
||||||
|
|
||||||
return kc, nil
|
return kc, nil
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ func KubeconfigWriteToPath(ctx context.Context, kubeconfig *clientcmdapi.Config,
|
|||||||
// KubeconfigMerge merges a new kubeconfig into an existing kubeconfig and returns the result
|
// KubeconfigMerge merges a new kubeconfig into an existing kubeconfig and returns the result
|
||||||
func KubeconfigMerge(ctx context.Context, newKubeConfig *clientcmdapi.Config, existingKubeConfig *clientcmdapi.Config, outPath string, overwriteConflicting bool, updateCurrentContext bool) error {
|
func KubeconfigMerge(ctx context.Context, newKubeConfig *clientcmdapi.Config, existingKubeConfig *clientcmdapi.Config, outPath string, overwriteConflicting bool, updateCurrentContext bool) error {
|
||||||
|
|
||||||
log.Debugf("Merging new KubeConfig:\n%+v\n>>> into existing KubeConfig:\n%+v", newKubeConfig, existingKubeConfig)
|
log.Tracef("Merging new Kubeconfig:\n%+v\n>>> into existing Kubeconfig:\n%+v", newKubeConfig, existingKubeConfig)
|
||||||
|
|
||||||
// Overwrite values in existing kubeconfig
|
// Overwrite values in existing kubeconfig
|
||||||
for k, v := range newKubeConfig.Clusters {
|
for k, v := range newKubeConfig.Clusters {
|
||||||
@ -276,7 +276,12 @@ func KubeconfigMerge(ctx context.Context, newKubeConfig *clientcmdapi.Config, ex
|
|||||||
existingKubeConfig.CurrentContext = newKubeConfig.CurrentContext
|
existingKubeConfig.CurrentContext = newKubeConfig.CurrentContext
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Merged KubeConfig:\n%+v", existingKubeConfig)
|
kubeconfigYaml, err := clientcmd.Write(*existingKubeConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("Merged Kubeconfig:\n%+v", existingKubeConfig)
|
||||||
|
} else {
|
||||||
|
log.Tracef("Merged Kubeconfig:\n%s", kubeconfigYaml)
|
||||||
|
}
|
||||||
|
|
||||||
return KubeconfigWrite(ctx, existingKubeConfig, outPath)
|
return KubeconfigWrite(ctx, existingKubeConfig, outPath)
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ func NodeCreateMulti(ctx context.Context, runtime runtimes.Runtime, nodes []*k3d
|
|||||||
|
|
||||||
// NodeCreate creates a new containerized k3s node
|
// NodeCreate creates a new containerized k3s node
|
||||||
func NodeCreate(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, createNodeOpts k3d.NodeCreateOpts) error {
|
func NodeCreate(ctx context.Context, runtime runtimes.Runtime, node *k3d.Node, createNodeOpts k3d.NodeCreateOpts) error {
|
||||||
log.Debugf("Creating node from spec\n%+v", node)
|
log.Tracef("Creating node from spec\n%+v", node)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CONFIGURATION
|
* CONFIGURATION
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
// createContainer creates a new docker container from translated specs
|
// createContainer creates a new docker container from translated specs
|
||||||
func createContainer(ctx context.Context, dockerNode *NodeInDocker, name string) error {
|
func createContainer(ctx context.Context, dockerNode *NodeInDocker, name string) error {
|
||||||
|
|
||||||
log.Debugf("Creating docker container with translated config\n%+v\n", dockerNode) // TODO: remove?
|
log.Tracef("Creating docker container with translated config\n%+v\n", dockerNode)
|
||||||
|
|
||||||
// initialize docker client
|
// initialize docker client
|
||||||
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||||
@ -65,7 +65,7 @@ func createContainer(ctx context.Context, dockerNode *NodeInDocker, name string)
|
|||||||
log.Errorf("Failed to create container '%s'", name)
|
log.Errorf("Failed to create container '%s'", name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugln("Created container", resp.ID)
|
log.Debugf("Created container %s (ID: %s)", name, resp.ID)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func (d Docker) GetKubeconfig(ctx context.Context, node *k3d.Node) (io.ReadClose
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Container Details: %+v", container)
|
log.Tracef("Container Details: %+v", container)
|
||||||
|
|
||||||
reader, _, err := docker.CopyFromContainer(ctx, container.ID, "/output/kubeconfig.yaml")
|
reader, _, err := docker.CopyFromContainer(ctx, container.ID, "/output/kubeconfig.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -373,7 +373,7 @@ func executeInNode(ctx context.Context, node *k3d.Node, cmd []string) (*types.Hi
|
|||||||
|
|
||||||
// if still running, continue loop
|
// if still running, continue loop
|
||||||
if execInfo.Running {
|
if execInfo.Running {
|
||||||
log.Debugf("Exec process '%+v' still running in node '%s'.. sleeping for 1 second...", cmd, node.Name)
|
log.Tracef("Exec process '%+v' still running in node '%s'.. sleeping for 1 second...", cmd, node.Name)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) {
|
|||||||
hostConfig.Privileged = true
|
hostConfig.Privileged = true
|
||||||
|
|
||||||
/* Volumes */
|
/* Volumes */
|
||||||
log.Debugf("Volumes: %+v", node.Volumes)
|
|
||||||
hostConfig.Binds = node.Volumes
|
hostConfig.Binds = node.Volumes
|
||||||
// containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before
|
// containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user