Skip to content

Commit

Permalink
Merge pull request #251 from sergeykonkin/add-log-options
Browse files Browse the repository at this point in the history
🌱 Add log options from k8s.io/component-base/logs
  • Loading branch information
k8s-ci-robot authored May 30, 2024
2 parents d0f83a2 + 689e7b0 commit 5eb79f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
k8s.io/apimachinery v0.29.3
k8s.io/cli-runtime v0.29.3
k8s.io/client-go v0.29.3
k8s.io/component-base v0.29.3
k8s.io/klog/v2 v2.110.1
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/cluster-api v1.7.2
Expand Down Expand Up @@ -188,7 +189,6 @@ require (
k8s.io/apiextensions-apiserver v0.29.3 // indirect
k8s.io/apiserver v0.29.3 // indirect
k8s.io/cluster-bootstrap v0.29.3 // indirect
k8s.io/component-base v0.29.3 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubectl v0.29.3 // indirect
oras.land/oras-go v1.2.5-0.20240123054708-2afb6872ee1a // indirect
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/component-base/logs"
logsv1 "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
"k8s.io/klog/v2"
addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1"
chartcontroller "sigs.k8s.io/cluster-api-addon-provider-helm/controllers/helmchartproxy"
Expand Down Expand Up @@ -62,6 +65,7 @@ var (
webhookPort int
webhookCertDir string
diagnosticsOptions = flags.DiagnosticsOptions{}
logOptions = logs.NewOptions()
)

func init() {
Expand All @@ -73,6 +77,8 @@ func init() {

// InitFlags initializes the flags.
func InitFlags(fs *pflag.FlagSet) {
logsv1.AddFlags(logOptions, fs)

fs.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")

Expand Down Expand Up @@ -141,6 +147,11 @@ func main() {
}
}

if err := logsv1.ValidateAndApply(logOptions, nil); err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

// klog.Background will automatically use the right logger.
ctrl.SetLogger(klog.Background())

Expand Down

0 comments on commit 5eb79f5

Please sign in to comment.