@@ -31,10 +31,10 @@ import (
31
31
"time"
32
32
33
33
"github.com/avast/retry-go"
34
+ "github.com/k0sproject/k0s/cmd/internal"
34
35
workercmd "github.com/k0sproject/k0s/cmd/worker"
35
36
"github.com/k0sproject/k0s/internal/pkg/dir"
36
37
"github.com/k0sproject/k0s/internal/pkg/file"
37
- k0slog "github.com/k0sproject/k0s/internal/pkg/log"
38
38
"github.com/k0sproject/k0s/internal/pkg/sysinfo"
39
39
"github.com/k0sproject/k0s/internal/sync/value"
40
40
"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
@@ -67,7 +67,10 @@ import (
67
67
type command config.CLIOptions
68
68
69
69
func NewControllerCmd () * cobra.Command {
70
- var ignorePreFlightChecks bool
70
+ var (
71
+ debugFlags internal.DebugFlags
72
+ ignorePreFlightChecks bool
73
+ )
71
74
72
75
cmd := & cobra.Command {
73
76
Use : "controller [join-token]" ,
@@ -80,12 +83,8 @@ func NewControllerCmd() *cobra.Command {
80
83
or CLI flag:
81
84
$ k0s controller --token-file [path_to_file]
82
85
Note: Token can be passed either as a CLI argument or as a flag` ,
83
- Args : cobra .MaximumNArgs (1 ),
84
- PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
85
- logrus .SetOutput (cmd .OutOrStdout ())
86
- k0slog .SetInfoLevel ()
87
- return config .CallParentPersistentPreRun (cmd , args )
88
- },
86
+ Args : cobra .MaximumNArgs (1 ),
87
+ PersistentPreRun : debugFlags .Run ,
89
88
RunE : func (cmd * cobra.Command , args []string ) error {
90
89
opts , err := config .GetCmdOpts (cmd )
91
90
if err != nil {
@@ -114,19 +113,23 @@ func NewControllerCmd() *cobra.Command {
114
113
115
114
ctx , cancel := signal .NotifyContext (cmd .Context (), os .Interrupt , syscall .SIGINT , syscall .SIGTERM )
116
115
defer cancel ()
117
- return c .start (ctx )
116
+ return c .start (ctx , debugFlags . IsDebug () )
118
117
},
119
118
}
120
119
121
120
// append flags
121
+ pflags := cmd .PersistentFlags ()
122
+ debugFlags .LongRunning ().AddToFlagSet (pflags )
123
+ pflags .AddFlagSet (config .GetPersistentFlagSet ())
124
+ pflags .AddFlagSet (config .GetControllerFlags ())
125
+ pflags .AddFlagSet (config .GetWorkerFlags ())
126
+
122
127
cmd .Flags ().BoolVar (& ignorePreFlightChecks , "ignore-pre-flight-checks" , false , "continue even if pre-flight checks fail" )
123
- cmd .Flags ().AddFlagSet (config .GetPersistentFlagSet ())
124
- cmd .PersistentFlags ().AddFlagSet (config .GetControllerFlags ())
125
- cmd .PersistentFlags ().AddFlagSet (config .GetWorkerFlags ())
128
+
126
129
return cmd
127
130
}
128
131
129
- func (c * command ) start (ctx context.Context ) error {
132
+ func (c * command ) start (ctx context.Context , debug bool ) error {
130
133
perfTimer := performance .NewTimer ("controller-start" ).Buffer ().Start ()
131
134
132
135
nodeConfig , err := c .K0sVars .NodeConfig ()
@@ -247,8 +250,8 @@ func (c *command) start(ctx context.Context) error {
247
250
nodeComponents .Add (ctx , & cplb.Keepalived {
248
251
K0sVars : c .K0sVars ,
249
252
Config : cplbCfg .Keepalived ,
250
- DetailedLogging : c . Debug ,
251
- LogConfig : c . Debug ,
253
+ DetailedLogging : debug ,
254
+ LogConfig : debug ,
252
255
KubeConfigPath : c .K0sVars .AdminKubeConfigPath ,
253
256
APIPort : nodeConfig .Spec .API .Port ,
254
257
})
0 commit comments