Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard warning logs from client-go when using ComponentStatus on K8S >= 1.19 #7946

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pkg/util/kubernetes/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"context"
"errors"
"fmt"

"strings"
"sync"
"time"
Expand Down Expand Up @@ -171,6 +170,8 @@ func getClientConfig() (*rest.Config, error) {
}

func getKubeClient(timeout time.Duration) (kubernetes.Interface, error) {
// TODO: Remove custom warning logger when we remove usage of ComponentStatus
rest.SetDefaultWarningHandler(CustomWarningLogger{})
clientConfig, err := getClientConfig()
if err != nil {
return nil, err
Expand Down
23 changes: 23 additions & 0 deletions pkg/util/kubernetes/apiserver/warning_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

// +build kubeapiserver

package apiserver

import klog "k8s.io/klog"

var supressedWarning = "v1 ComponentStatus is deprecated in v1.19+"

type CustomWarningLogger struct{}

// TODO: Remove custom warning logger when we remove usage of ComponentStatus
func (CustomWarningLogger) HandleWarningHeader(code int, agent string, message string) {
if code != 299 || len(message) == 0 || message == supressedWarning {
return
}

klog.Warning(message)
}