Skip to content

Commit db8617f

Browse files
authored
main.go: switch to klog-based logger (#419)
Signed-off-by: Joe Lanford <[email protected]>
1 parent 433a127 commit db8617f

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

cmd/manager/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import (
3434
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3535
"k8s.io/client-go/metadata"
3636
_ "k8s.io/client-go/plugin/pkg/client/auth"
37+
"k8s.io/klog/v2"
38+
"k8s.io/klog/v2/textlogger"
3739
ctrl "sigs.k8s.io/controller-runtime"
3840
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
3941
"sigs.k8s.io/controller-runtime/pkg/healthz"
40-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4142
"sigs.k8s.io/controller-runtime/pkg/metrics"
4243
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
4344
crwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -104,10 +105,8 @@ func main() {
104105
flag.StringVar(&keyFile, "tls-key", "", "The key file used for serving catalog contents over HTTPS. Requires tls-cert.")
105106
flag.IntVar(&webhookPort, "webhook-server-port", 9443, "The port that the mutating webhook server serves at.")
106107
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of CA certificate to use for verifying HTTPS connections to image registries.")
107-
opts := zap.Options{
108-
Development: true,
109-
}
110-
opts.BindFlags(flag.CommandLine)
108+
109+
klog.InitFlags(flag.CommandLine)
111110

112111
// Combine both flagsets and parse them
113112
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
@@ -119,7 +118,7 @@ func main() {
119118
os.Exit(0)
120119
}
121120

122-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
121+
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
123122

124123
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
125124
setupLog.Error(nil, "unable to configure TLS certificates: tls-cert and tls-key flags must be used together")

config/base/manager/manager.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ spec:
6262
- --http2-disable
6363
- --upstream=http://127.0.0.1:8080/
6464
- --logtostderr=true
65-
- --v=0
6665
ports:
6766
- containerPort: 7443
6867
protocol: TCP

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
k8s.io/apiserver v0.31.1
2424
k8s.io/client-go v0.31.1
2525
k8s.io/component-base v0.31.1
26+
k8s.io/klog/v2 v2.130.1
2627
sigs.k8s.io/controller-runtime v0.19.0
2728
sigs.k8s.io/yaml v1.4.0
2829
)
@@ -63,7 +64,6 @@ require (
6364
github.com/go-git/go-billy/v5 v5.5.0 // indirect
6465
github.com/go-git/go-git/v5 v5.12.0 // indirect
6566
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
66-
github.com/go-logr/zapr v1.3.0 // indirect
6767
github.com/go-openapi/analysis v0.23.0 // indirect
6868
github.com/go-openapi/errors v0.22.0 // indirect
6969
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@@ -135,8 +135,6 @@ require (
135135
go.mongodb.org/mongo-driver v1.14.0 // indirect
136136
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
137137
go.opencensus.io v0.24.0 // indirect
138-
go.uber.org/multierr v1.11.0 // indirect
139-
go.uber.org/zap v1.27.0 // indirect
140138
golang.org/x/crypto v0.27.0 // indirect
141139
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
142140
golang.org/x/net v0.29.0 // indirect
@@ -157,7 +155,6 @@ require (
157155
gopkg.in/warnings.v0 v0.1.2 // indirect
158156
gopkg.in/yaml.v2 v2.4.0 // indirect
159157
gopkg.in/yaml.v3 v3.0.1 // indirect
160-
k8s.io/klog/v2 v2.130.1 // indirect
161158
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
162159
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
163160
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

internal/controllers/core/clustercatalog_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
6565
l := log.FromContext(ctx).WithName("catalogd-controller")
6666
ctx = log.IntoContext(ctx, l)
6767

68-
l.V(1).Info("reconcile starting")
69-
defer l.V(1).Info("reconcile ending")
68+
l.Info("reconcile starting")
69+
defer l.Info("reconcile ending")
7070

7171
existingCatsrc := v1alpha1.ClusterCatalog{}
7272
if err := r.Client.Get(ctx, req.NamespacedName, &existingCatsrc); err != nil {

test/upgrade/unpack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
5959
defer cancel()
6060
substrings := []string{
6161
"reconcile ending",
62-
fmt.Sprintf(`"ClusterCatalog": {"name":"%s"}`, testClusterCatalogName),
62+
fmt.Sprintf(`ClusterCatalog=%q`, testClusterCatalogName),
6363
}
6464
found, err := watchPodLogsForSubstring(logCtx, &managerPod, "manager", substrings...)
6565
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)