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

Replace glog with klog #6830

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: 1 addition & 2 deletions addon-resizer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module k8s.io/autoscaler/addon-resizer
go 1.21

require (
github.com/golang/glog v1.2.1
github.com/google/go-cmp v0.6.0
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.52.3
Expand All @@ -12,6 +11,7 @@ require (
k8s.io/api v0.29.4
k8s.io/apimachinery v0.29.4
k8s.io/client-go v0.29.4
k8s.io/klog/v2 v2.110.1
)

require (
Expand Down Expand Up @@ -46,7 +46,6 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
2 changes: 0 additions & 2 deletions addon-resizer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
6 changes: 3 additions & 3 deletions addon-resizer/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"sync"
"time"

"github.com/golang/glog"
"k8s.io/klog/v2"
)

// HealthCheck contains information about last activity time of the monitored component.
Expand Down Expand Up @@ -51,7 +51,7 @@ func (hc *HealthCheck) Serve() {
go func() {
http.Handle("/health-check", hc)
err := http.ListenAndServe(hc.address, nil)
glog.Fatalf("Failed to start health check: %v", err)
klog.Fatalf("Failed to start health check: %v", err)
}()
}

Expand All @@ -77,7 +77,7 @@ func (hc *HealthCheck) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
_, err := w.Write([]byte("OK"))
if err != nil {
glog.Fatalf("Failed to write response message: %v", err)
klog.Fatalf("Failed to write response message: %v", err)
}
}

Expand Down
12 changes: 6 additions & 6 deletions addon-resizer/nanny/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package nanny

import (
"context"
"github.com/golang/glog"
"os"
"time"

Expand All @@ -29,6 +28,7 @@ import (
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
)

// Config is the leader configuration.
Expand All @@ -55,7 +55,7 @@ func LeadOrDie(cfg Config, clientset kubernetes.Interface, doLead func()) {

hostname, err := os.Hostname()
if err != nil {
glog.Fatalf("Unable to get hostname: %v", err)
klog.Fatalf("Unable to get hostname: %v", err)
}

lock, err := resourcelock.New(
Expand All @@ -70,7 +70,7 @@ func LeadOrDie(cfg Config, clientset kubernetes.Interface, doLead func()) {
},
)
if err != nil {
glog.Fatalf("Unable to create leader election lock: %v", err)
klog.Fatalf("Unable to create leader election lock: %v", err)
}

leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Expand All @@ -80,12 +80,12 @@ func LeadOrDie(cfg Config, clientset kubernetes.Interface, doLead func()) {
RetryPeriod: cfg.RetryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(_ context.Context) {
glog.Info("Started leading.")
klog.Info("Started leading.")
doLead()
},
OnStoppedLeading: func() {
glog.Fatalf("Lost leadership.")
klog.Fatalf("Lost leadership.")
},
},
})
}
}
6 changes: 3 additions & 3 deletions addon-resizer/nanny/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package nanny
import (
"fmt"

log "github.com/golang/glog"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/klog/v2"
)

const (
Expand Down Expand Up @@ -101,7 +101,7 @@ func computeResourceOverheadValueString(clusterSize uint64, resource Resource) s
var perResourceUnit string
_, err := fmt.Sscanf(perResourceOverhead, "%f%s", &perResourceValue, &perResourceUnit)
if err != nil && err.Error() != "EOF" {
log.Warningf(
klog.Warningf(
"Failed to parse the per resource overhead string '%s'; error=%s",
perResourceOverhead, err)
// Default to not specifying any unit to maintain existing
Expand All @@ -125,4 +125,4 @@ func calculateResources(clusterSize uint64, resources []Resource) *corev1.Resour
Limits: limits,
Requests: requests,
}
}
}
46 changes: 23 additions & 23 deletions addon-resizer/nanny/main/pod_nanny.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"path/filepath"

"github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -41,6 +40,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
)

var (
Expand Down Expand Up @@ -80,25 +80,25 @@ var (

func main() {
// First log our starting config, and then set up.
glog.Infof("Invoked by %v", os.Args)
glog.Infof("Version: %s", nanny.AddonResizerVersion)
klog.Infof("Invoked by %v", os.Args)
klog.Infof("Version: %s", nanny.AddonResizerVersion)
flag.Parse()

// Perform further validation of flags.
if *deployment == "" {
glog.Fatal("Must specify a deployment.")
klog.Fatal("Must specify a deployment.")
}

if *threshold < 0 || *threshold > 100 {
glog.Fatalf("Threshold must be between 0 and 100 inclusive. It is %d.", *threshold)
klog.Fatalf("Threshold must be between 0 and 100 inclusive. It is %d.", *threshold)
}

if *minClusterSize < 2 {
glog.Fatalf("minClusterSize must be greater than 1. It is set to %d.", *minClusterSize)
klog.Fatalf("minClusterSize must be greater than 1. It is set to %d.", *minClusterSize)
}

glog.Infof("Watching namespace: %s, pod: %s, container: %s.", *podNamespace, *podName, *containerName)
glog.Infof("storage: %s, extra_storage: %s", *baseStorage, *storagePerResource)
klog.Infof("Watching namespace: %s, pod: %s, container: %s.", *podNamespace, *podName, *containerName)
klog.Infof("storage: %s, extra_storage: %s", *baseStorage, *storagePerResource)

// Set up work objects.
config := kubeconfig(*kubeconfigPath)
Expand All @@ -108,7 +108,7 @@ func main() {

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
// Use protobufs to improve performance.
config.ContentType = "application/vnd.kubernetes.protobuf"
Expand All @@ -130,9 +130,9 @@ func main() {
} else {
nannycfg, err := loadNannyConfiguration(*configDir, nannyConfigurationFromFlags)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
glog.Infof("cpu: %s, extra_cpu: %s, memory: %s, extra_memory: %s", nannycfg.BaseCPU, nannycfg.CPUPerNode, nannycfg.BaseMemory, nannycfg.MemoryPerNode)
klog.Infof("cpu: %s, extra_cpu: %s, memory: %s, extra_memory: %s", nannycfg.BaseCPU, nannycfg.CPUPerNode, nannycfg.BaseMemory, nannycfg.MemoryPerNode)
resources = updateResources(nannycfg, *baseStorage)
}

Expand All @@ -148,11 +148,11 @@ func main() {
MinClusterSize: *minClusterSize,
}
} else {
glog.Fatalf("Estimator %s not supported", *estimator)
klog.Fatalf("Estimator %s not supported", *estimator)
}

if *scalingMode != nanny.NodeProportional && *scalingMode != nanny.ContainerProportional {
glog.Fatalf("scaling mode %s not supported", *scalingMode)
klog.Fatalf("scaling mode %s not supported", *scalingMode)
}

period := time.Duration(*pollPeriod) * time.Millisecond
Expand All @@ -167,7 +167,7 @@ func main() {
if !*runOnControlPlane || !*leaderElectionEnable {
start()
} else {
glog.Info("Leader Election Enabled.")
klog.Info("Leader Election Enabled.")
nanny.LeadOrDie(
nanny.Config{
LeaseDuration: *leaderElectionLeaseDuration,
Expand Down Expand Up @@ -202,10 +202,10 @@ func loadNannyConfiguration(configDir string, defaultConfig *nannyconfigalpha.Na
configMapConfig := &nannyconfigalpha.NannyConfiguration{}
data, err := ioutil.ReadFile(path)
if err != nil {
glog.V(0).Infof("Failed to read data from config file %q: %v, using default parameters", path, err)
klog.V(0).Infof("Failed to read data from config file %q: %v, using default parameters", path, err)
} else if configMapConfig, err = decodeNannyConfiguration(data, codecs); err != nil {
configMapConfig = &nannyconfigalpha.NannyConfiguration{}
glog.V(0).Infof("Unable to decode Nanny Configuration from config map, using default parameters")
klog.V(0).Infof("Unable to decode Nanny Configuration from config map, using default parameters")
}
nannyconfigalpha.SetDefaults_NannyConfiguration(configMapConfig)
// overwrite defaults with config map parameters
Expand Down Expand Up @@ -266,7 +266,7 @@ func updateResources(nannycfg *nannyconfig.NannyConfiguration, baseStorage strin
})
}

glog.Infof("Resources: %+v", resources)
klog.Infof("Resources: %+v", resources)
return resources
}

Expand Down Expand Up @@ -305,13 +305,13 @@ func (n *nannyConfigUpdater) CurrentResources() ([]nanny.Resource, error) {

nannycfg, err := n.clientset.CoreV1().ConfigMaps(n.namespace).Get(context.Background(), n.nannyConfigMapName, metav1.GetOptions{})
if err != nil {
glog.V(0).Infof("Failed to get config map %s: %v, using default parameters", n.nannyConfigMapName, err)
klog.V(0).Infof("Failed to get config map %s: %v, using default parameters", n.nannyConfigMapName, err)
} else {
data := []byte(nannycfg.Data["NannyConfiguration"])
configMapConfig, err = decodeNannyConfiguration(data, codecs)
if err != nil {
configMapConfig = &nannyconfigalpha.NannyConfiguration{}
glog.V(0).Infof("Unable to decode Nanny Configuration from config map, using default parameters: %v", err)
klog.V(0).Infof("Unable to decode Nanny Configuration from config map, using default parameters: %v", err)
}
}

Expand All @@ -325,14 +325,14 @@ func kubeconfig(configPath string) *rest.Config {
var config *rest.Config
var err error
if configPath == "" {
glog.V(1).Info("Using InClusterConfig")
klog.V(1).Info("Using InClusterConfig")
config, err = rest.InClusterConfig()
} else {
glog.V(1).Infof("Using kubeconfig file: %s", configPath)
klog.V(1).Infof("Using kubeconfig file: %s", configPath)
config, err = clientcmd.BuildConfigFromFlags("", configPath)
}
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return config
}
}
22 changes: 11 additions & 11 deletions addon-resizer/nanny/nanny_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"encoding/json"
"time"

log "github.com/golang/glog"
inf "gopkg.in/inf.v0"
corev1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/addon-resizer/healthcheck"
"k8s.io/klog/v2"
)

type operation int
Expand Down Expand Up @@ -121,7 +121,7 @@ func PollAPIServer(k8s KubernetesClient, est ResourceEstimator, hc *healthcheck.
if runOnControlPlane {
resources, err := nannyConfigUpdater.CurrentResources()
if err != nil {
log.Fatal(err)
klog.Fatal(err)
}
est = est.updatedResourceEstimator(resources)
}
Expand Down Expand Up @@ -150,15 +150,15 @@ func updateResources(k8s KubernetesClient, est ResourceEstimator, now, lastChang
}

if err != nil {
log.Error(err)
klog.Error(err)
return noChange
}
log.V(4).Infof("The cluster size is %d", num)
klog.V(4).Infof("The cluster size is %d", num)

// Query the apiserver for this pod's information.
resources, err := k8s.ContainerResources()
if err != nil {
log.Errorf("Error while querying apiserver for resources: %v", err)
klog.Errorf("Error while querying apiserver for resources: %v", err)
return noChange
}

Expand All @@ -168,23 +168,23 @@ func updateResources(k8s KubernetesClient, est ResourceEstimator, now, lastChang
// If there's a difference, go ahead and set the new values.
overwriteRes, op := shouldOverwriteResources(int64(threshold), resources.Limits, resources.Requests, expResources.Limits, expResources.Requests)
if !overwriteRes {
if log.V(4) {
log.V(4).Infof("Resources are within the expected limits. Actual: %+v Expected: %+v", jsonOrValue(*resources), jsonOrValue(*expResources))
if klog.V(4).Enabled() {
klog.V(4).Infof("Resources are within the expected limits. Actual: %+v Expected: %+v", jsonOrValue(*resources), jsonOrValue(*expResources))
}
return noChange
}

if (op == scaleDown && now.Before(lastChange.Add(scaleDownDelay))) ||
(op == scaleUp && now.Before(lastChange.Add(scaleUpDelay))) {
if prevResult != postpone {
log.Infof("Resources are not within the expected limits, Actual: %+v, accepted range: %+v. Skipping resource update because of scale up/down delay", jsonOrValue(*resources), jsonOrValue(*expResources))
klog.Infof("Resources are not within the expected limits, Actual: %+v, accepted range: %+v. Skipping resource update because of scale up/down delay", jsonOrValue(*resources), jsonOrValue(*expResources))
}
return postpone
}

log.Infof("Resources are not within the expected limits, updating the deployment. Actual: %+v Expected: %+v. Resource will be updated.", jsonOrValue(*resources), jsonOrValue(*expResources))
klog.Infof("Resources are not within the expected limits, updating the deployment. Actual: %+v Expected: %+v. Resource will be updated.", jsonOrValue(*resources), jsonOrValue(*expResources))
if err := k8s.UpdateDeployment(expResources); err != nil {
log.Error(err)
klog.Error(err)
return noChange
}
return overwrite
Expand All @@ -196,4 +196,4 @@ func jsonOrValue(val interface{}) interface{} {
return val
}
return string(bytes)
}
}
Loading