Skip to content

Commit

Permalink
Use klog contextual logger in daemon and controller
Browse files Browse the repository at this point in the history
Signed-off-by: Yury Kulazhenkov <[email protected]>
  • Loading branch information
ykulazhenkov committed Jul 12, 2023
1 parent 7d92766 commit a838dc5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions cmd/ipam-controller/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"

"github.com/go-logr/logr"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -67,7 +66,7 @@ func NewControllerCommand() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to read config for k8s client: %v", err)
}
return RunController(logr.NewContext(ctx, klog.NewKlogr()), conf, opts)
return RunController(klog.NewContext(ctx, klog.NewKlogr()), conf, opts)
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
Expand All @@ -94,7 +93,7 @@ func NewControllerCommand() *cobra.Command {

// RunController start IPAM controller with provided options
func RunController(ctx context.Context, config *rest.Config, opts *options.Options) error {
logger := logr.FromContextOrDiscard(ctx)
logger := klog.FromContext(ctx)
ctrl.SetLogger(logger)

logger.Info("start IPAM controller",
Expand Down
4 changes: 2 additions & 2 deletions cmd/ipam-daemon/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewControllerCommand() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to read config for k8s client: %v", err)
}
return RunDaemon(logr.NewContext(ctx, klog.NewKlogr()), conf, opts)
return RunDaemon(klog.NewContext(ctx, klog.NewKlogr()), conf, opts)
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
Expand Down Expand Up @@ -105,7 +105,7 @@ func NewControllerCommand() *cobra.Command {
//
//nolint:funlen
func RunDaemon(ctx context.Context, config *rest.Config, opts *options.Options) error {
logger := logr.FromContextOrDiscard(ctx)
logger := klog.FromContext(ctx)
ctrl.SetLogger(logger)

logger.Info("start IPAM daemon",
Expand Down
3 changes: 2 additions & 1 deletion deploy/nv-ipam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
args:
- --node-name=$(NODE_NAME)
- --v=1 # log level for ipam-daemon
- --logging-format=json
- --feature-gates=ContextualLogging=true
- --bind-address=unix:///var/lib/cni/nv-ipam/daemon-socket
- --store-file=/var/lib/cni/nv-ipam/store
- --cni-daemon-socket=unix:///var/lib/cni/nv-ipam/daemon-socket
Expand Down Expand Up @@ -238,6 +238,7 @@ spec:
imagePullPolicy: IfNotPresent
command: [ "/ipam-controller" ]
args:
- --feature-gates=ContextualLogging=true
- --config-name=nvidia-k8s-ipam-config
- --config-namespace=$(POD_NAMESPACE)
- --leader-elect=true
Expand Down

0 comments on commit a838dc5

Please sign in to comment.