@@ -27,6 +27,7 @@ import (
2727 "github.com/k3s-io/k3s/pkg/executor/embed/etcd"
2828 "github.com/k3s-io/k3s/pkg/signals"
2929 "github.com/k3s-io/k3s/pkg/util"
30+ "github.com/k3s-io/k3s/pkg/util/logger"
3031 "github.com/k3s-io/k3s/pkg/version"
3132 "github.com/k3s-io/k3s/pkg/vpn"
3233 pkgerrors "github.com/pkg/errors"
@@ -80,6 +81,7 @@ func (e *Embedded) Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node,
8081 defer cancel ()
8182
8283 klog .InitFlags (nil )
84+ klog .EnableContextualLogging (true )
8385 for {
8486 flag .Set ("v" , strconv .Itoa (cmds .LogConfig .VLevel ))
8587
@@ -170,7 +172,8 @@ func (e *Embedded) Bootstrap(ctx context.Context, nodeConfig *daemonconfig.Node,
170172}
171173
172174func (e * Embedded ) Kubelet (ctx context.Context , args []string ) error {
173- command := kubelet .NewKubeletCommand (context .Background ())
175+ ctx = logger .NewContextWithName (ctx , "kubelet" )
176+ command := kubelet .NewKubeletCommand (logger .NewContextWithName (context .Background (), "kubelet" ))
174177 command .SetArgs (args )
175178
176179 go func () {
@@ -191,6 +194,7 @@ func (e *Embedded) Kubelet(ctx context.Context, args []string) error {
191194}
192195
193196func (e * Embedded ) KubeProxy (ctx context.Context , args []string ) error {
197+ ctx = logger .NewContextWithName (ctx , "kube-proxy" )
194198 command := proxy .NewProxyCommand ()
195199 command .SetArgs (util .GetArgs (platformKubeProxyArgs (e .nodeConfig ), args ))
196200
@@ -217,6 +221,7 @@ func (*Embedded) APIServerHandlers(ctx context.Context) (authenticator.Request,
217221}
218222
219223func (e * Embedded ) APIServer (ctx context.Context , args []string ) error {
224+ ctx = logger .NewContextWithName (ctx , "kube-apiserver" )
220225 command := apiapp .NewAPIServerCommand (ctx .Done ())
221226 command .SetArgs (args )
222227
@@ -238,6 +243,7 @@ func (e *Embedded) APIServer(ctx context.Context, args []string) error {
238243}
239244
240245func (e * Embedded ) Scheduler (ctx context.Context , nodeReady <- chan struct {}, args []string ) error {
246+ ctx = logger .NewContextWithName (ctx , "kube-scheduler" )
241247 command := sapp .NewSchedulerCommand (ctx .Done ())
242248 command .SetArgs (args )
243249
@@ -260,6 +266,7 @@ func (e *Embedded) Scheduler(ctx context.Context, nodeReady <-chan struct{}, arg
260266}
261267
262268func (e * Embedded ) ControllerManager (ctx context.Context , args []string ) error {
269+ ctx = logger .NewContextWithName (ctx , "kube-controller-manager" )
263270 command := cmapp .NewControllerManagerCommand ()
264271 command .SetArgs (args )
265272
@@ -281,6 +288,7 @@ func (e *Embedded) ControllerManager(ctx context.Context, args []string) error {
281288}
282289
283290func (* Embedded ) CloudControllerManager (ctx context.Context , ccmRBACReady <- chan struct {}, args []string ) error {
291+ ctx = logger .NewContextWithName (ctx , "cloud-controller-manager" )
284292 ccmOptions , err := ccmopt .NewCloudControllerManagerOptions ()
285293 if err != nil {
286294 logrus .Fatalf ("unable to initialize command options: %v" , err )
@@ -330,6 +338,7 @@ func (e *Embedded) CurrentETCDOptions() (executor.InitialOptions, error) {
330338}
331339
332340func (e * Embedded ) ETCD (ctx context.Context , wg * sync.WaitGroup , args * executor.ETCDConfig , extraArgs []string , test executor.TestFunc ) error {
341+ ctx = logger .NewContextWithName (ctx , "etcd" )
333342 // Start a goroutine to call the provided test function until it returns true.
334343 // The test function is reponsible for ensuring that the etcd server is up
335344 // and ready to accept client requests.
@@ -356,10 +365,12 @@ func (e *Embedded) ETCD(ctx context.Context, wg *sync.WaitGroup, args *executor.
356365}
357366
358367func (e * Embedded ) Containerd (ctx context.Context , cfg * daemonconfig.Node ) error {
368+ ctx = logger .NewContextWithName (ctx , "containerd" )
359369 return executor .CloseIfNilErr (containerd .Run (ctx , cfg ), e .criReady )
360370}
361371
362372func (e * Embedded ) Docker (ctx context.Context , cfg * daemonconfig.Node ) error {
373+ ctx = logger .NewContextWithName (ctx , "cri-dockerd" )
363374 return executor .CloseIfNilErr (cridockerd .Run (ctx , cfg ), e .criReady )
364375}
365376
@@ -373,6 +384,7 @@ func (e *Embedded) CRI(ctx context.Context, cfg *daemonconfig.Node) error {
373384
374385func (e * Embedded ) CNI (ctx context.Context , wg * sync.WaitGroup , cfg * daemonconfig.Node ) error {
375386 if cfg .Flannel .Backend != flannel .BackendNone {
387+ ctx := logger .NewContextWithName (ctx , "flannel" )
376388 if (cfg .Flannel .ExternalIP ) && (len (cfg .AgentConfig .NodeExternalIPs ) == 0 ) {
377389 logrus .Warnf ("Server has flannel-external-ip flag set but this node does not set node-external-ip. Flannel will use internal address when connecting to this node." )
378390 } else if (cfg .Flannel .ExternalIP ) && (cfg .Flannel .Backend != flannel .BackendWireguardNative ) {
@@ -388,6 +400,7 @@ func (e *Embedded) CNI(ctx context.Context, wg *sync.WaitGroup, cfg *daemonconfi
388400 }
389401
390402 if ! cfg .AgentConfig .DisableNPC {
403+ ctx := logger .NewContextWithName (ctx , "kube-proxy" )
391404 if err := netpol .Run (ctx , wg , cfg ); err != nil {
392405 return err
393406 }
0 commit comments