Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions pkg/node/node.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some of our test files are using log.Logger instead of ZeroLog.Logger. Do they need to be updated as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking btw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have checked they are using same package. For the test cases, they do not validate base on log level. Might just keep them.

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ type Node struct {
uptime uptime.UptimeFuncType
}

type ZerologWriter struct {
logger zerolog.Logger
}

type StdWriter struct {
*ZerologWriter
}

type ErrWriter struct {
*ZerologWriter
}

// New will construct a node struct to perform various node function through the kubernetes api server
func New(nthConfig config.Config, clientset *kubernetes.Clientset) (*Node, error) {
drainHelper, err := getDrainHelper(nthConfig, clientset)
Expand Down Expand Up @@ -737,8 +749,8 @@ func getDrainHelper(nthConfig config.Config, clientset *kubernetes.Clientset) (*
AdditionalFilters: []drain.PodFilter{filterPodForDeletion(nthConfig.PodName, nthConfig.PodNamespace)},
DeleteEmptyDirData: nthConfig.DeleteLocalData,
Timeout: time.Duration(nthConfig.NodeTerminationGracePeriod) * time.Second,
Out: log.Logger,
ErrOut: log.Logger,
Out: &StdWriter{&ZerologWriter{logger: log.Logger}},
ErrOut: &ErrWriter{&ZerologWriter{logger: log.Logger}},
}

if nthConfig.DryRun {
Expand Down Expand Up @@ -927,6 +939,18 @@ func isDaemonSetPod(pod corev1.Pod) bool {
return false
}

func (w *StdWriter) Write(p []byte) (n int, err error) {
msg := strings.TrimRight(string(p), "\n")
w.logger.Info().Msg(msg)
return len(p), nil
}

func (w *ErrWriter) Write(p []byte) (n int, err error) {
msg := strings.TrimRight(string(p), "\n")
w.logger.Error().Msg(msg)
return len(p), nil
}

type recorderInterface interface {
AnnotatedEventf(object runtime.Object, annotations map[string]string, eventType, reason, messageFmt string, args ...interface{})
}