Skip to content

Commit f1586e9

Browse files
authored
Use klogr for logging (#481)
1 parent bb5cdf7 commit f1586e9

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/onsi/gomega v1.17.0
1414
github.com/pkg/errors v0.9.1
1515
github.com/ppc64le-cloud/powervs-utils v0.0.0-20210106101518-5d3f965b0344
16+
github.com/spf13/pflag v1.0.5
1617
k8s.io/api v0.22.2
1718
k8s.io/apimachinery v0.22.2
1819
k8s.io/client-go v0.22.2

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef h1:46PFijGL
9797
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
9898
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
9999
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
100-
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
101100
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
102101
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
103102
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=

main.go

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import (
2121
"os"
2222
"time"
2323

24+
"github.com/spf13/pflag"
25+
2426
"k8s.io/apimachinery/pkg/runtime"
2527
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2628
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
29+
"k8s.io/klog/v2"
30+
"k8s.io/klog/v2/klogr"
2731
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2832
ctrl "sigs.k8s.io/controller-runtime"
29-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3033

3134
infrastructurev1alpha3 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha3"
3235
infrastructurev1alpha4 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha4"
@@ -36,7 +39,9 @@ import (
3639
)
3740

3841
var (
39-
watchNamespace string
42+
watchNamespace string
43+
metricsAddr string
44+
enableLeaderElection bool
4045

4146
scheme = runtime.NewScheme()
4247
setupLog = ctrl.Log.WithName("setup")
@@ -53,21 +58,13 @@ func init() {
5358
}
5459

5560
func main() {
56-
var metricsAddr string
57-
var enableLeaderElection bool
58-
flag.StringVar(&metricsAddr, "metrics-bind-addr", ":8080", "The address the metric endpoint binds to.")
59-
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
60-
"Enable leader election for controller manager. "+
61-
"Enabling this will ensure there is only one active controller manager.")
62-
flag.StringVar(
63-
&watchNamespace,
64-
"namespace",
65-
"",
66-
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
67-
)
68-
flag.Parse()
61+
klog.InitFlags(nil)
62+
63+
initFlags(pflag.CommandLine)
64+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
65+
pflag.Parse()
6966

70-
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
67+
ctrl.SetLogger(klogr.New())
7168

7269
if watchNamespace != "" {
7370
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
@@ -128,3 +125,27 @@ func main() {
128125
os.Exit(1)
129126
}
130127
}
128+
129+
func initFlags(fs *pflag.FlagSet) {
130+
fs.StringVar(
131+
&metricsAddr,
132+
"metrics-bind-addr",
133+
":8080",
134+
"The address the metric endpoint binds to.",
135+
)
136+
137+
fs.BoolVar(
138+
&enableLeaderElection,
139+
"leader-elect",
140+
false,
141+
"Enable leader election for controller manager. "+
142+
"Enabling this will ensure there is only one active controller manager.",
143+
)
144+
145+
fs.StringVar(
146+
&watchNamespace,
147+
"namespace",
148+
"",
149+
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
150+
)
151+
}

0 commit comments

Comments
 (0)