Skip to content

Commit

Permalink
cherry-pick kubernetes#6035 + merge conflicts into 1.26
Browse files Browse the repository at this point in the history
  • Loading branch information
k8s-ci-robot authored and madufresneelastic committed Aug 28, 2023
1 parent 3a87017 commit 0d3dc40
Show file tree
Hide file tree
Showing 11 changed files with 795 additions and 3 deletions.
15 changes: 15 additions & 0 deletions cluster-autoscaler/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ this document:
* [I'm running cluster with nodes in multiple zones for HA purposes. Is that supported by Cluster Autoscaler?](#im-running-cluster-with-nodes-in-multiple-zones-for-ha-purposes-is-that-supported-by-cluster-autoscaler)
* [How can I monitor Cluster Autoscaler?](#how-can-i-monitor-cluster-autoscaler)
* [How can I increase the information that the CA is logging?](#how-can-i-increase-the-information-that-the-ca-is-logging)
* [How can I change the log format that the CA outputs?](#how-can-i-change-the-log-format-that-the-ca-outputs)
* [How can I see all the events from Cluster Autoscaler?](#how-can-i-see-all-events-from-cluster-autoscaler)
* [How can I scale my cluster to just 1 node?](#how-can-i-scale-my-cluster-to-just-1-node)
* [How can I scale a node group to 0?](#how-can-i-scale-a-node-group-to-0)
Expand Down Expand Up @@ -931,6 +932,20 @@ or infrastructure endpoints, then setting a value of `--v=9` will show all the i
HTTP calls made. Be aware that using verbosity levels higher than `--v=1` will generate
an increased amount of logs, prepare your deployments and storage accordingly.
### How Can I change the log format that the CA outputs?
There are 2 log format options, `text` and `json`. By default (`text`), the Cluster Autoscaler will output
logs in the [klog native format](https://kubernetes.io/docs/concepts/cluster-administration/system-logs/#klog-output).
```
I0823 17:15:11.472183 29944 main.go:569] Cluster Autoscaler 1.28.0-beta.0
```
Alternatively, adding the flag `--logging-format=json` changes the
[log output to json](https://kubernetes.io/docs/concepts/cluster-administration/system-logs/#klog-output).
```
{"ts":1692825334994.433,"caller":"cluster-autoscaler/main.go:569","msg":"Cluster Autoscaler 1.28.0-beta.0\n","v":1}
```
### What events are emitted by CA?
Whenever Cluster Autoscaler adds or removes nodes it will create events
Expand Down
1 change: 1 addition & 0 deletions cluster-autoscaler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cluster-autoscaler/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand Down
22 changes: 19 additions & 3 deletions cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import (
kube_flag "k8s.io/component-base/cli/flag"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/component-base/config/options"
"k8s.io/component-base/logs"
logsapi "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/component-base/metrics/legacyregistry"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -483,13 +486,26 @@ func run(healthCheck *metrics.HealthCheck, debuggingSnapshotter debuggingsnapsho

func main() {
klog.InitFlags(nil)
featureGate := utilfeature.DefaultMutableFeatureGate
loggingConfig := logsapi.NewLoggingConfiguration()

if err := logsapi.AddFeatureGates(featureGate); err != nil {
klog.Fatalf("Failed to add logging feature flags: %v", err)
}

logsapi.AddFlags(loggingConfig, pflag.CommandLine)
featureGate.AddFlag(pflag.CommandLine)
kube_flag.InitFlags()

if err := logsapi.ValidateAndApply(loggingConfig, featureGate); err != nil {
klog.Fatalf("Failed to validate and apply logging configuration: %v", err)
}

logs.InitLogs()

leaderElection := defaultLeaderElectionConfiguration()
leaderElection.LeaderElect = true

options.BindLeaderElectionFlags(&leaderElection, pflag.CommandLine)
utilfeature.DefaultMutableFeatureGate.AddFlag(pflag.CommandLine)
kube_flag.InitFlags()

healthCheck := metrics.NewHealthCheck(*maxInactivityTimeFlag, *maxFailingTimeFlag)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions cluster-autoscaler/vendor/github.com/go-logr/zapr/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d3dc40

Please sign in to comment.