Skip to content

Commit 05b62d0

Browse files
fix: Ensure logger is initialized before logging errors
Fixes a silent error in operator-controller where logs were not printed because the logger was not initialized before usage.
1 parent 00251d6 commit 05b62d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cmd/operator-controller/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"flag"
2424
"fmt"
25+
"k8s.io/klog/v2/textlogger"
2526
"net/http"
2627
"os"
2728
"path/filepath"
@@ -40,7 +41,6 @@ import (
4041
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
4142
_ "k8s.io/client-go/plugin/pkg/client/auth"
4243
"k8s.io/klog/v2"
43-
"k8s.io/klog/v2/textlogger"
4444
"k8s.io/utils/ptr"
4545
ctrl "sigs.k8s.io/controller-runtime"
4646
crcache "sigs.k8s.io/controller-runtime/pkg/cache"
@@ -136,6 +136,8 @@ func main() {
136136
os.Exit(0)
137137
}
138138

139+
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
140+
139141
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
140142
setupLog.Error(errors.New("missing TLS configuration"),
141143
"tls-cert and tls-key flags must be used together",
@@ -154,8 +156,6 @@ func main() {
154156
metricsAddr = ":8443"
155157
}
156158

157-
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
158-
159159
setupLog.Info("starting up the controller", "version info", version.String())
160160

161161
authFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s.json", authFilePrefix, apimachineryrand.String(8)))

0 commit comments

Comments
 (0)