Skip to content

Commit 8a34998

Browse files
committed
Fix log initialization
Use proper flags and remove use of logrus and klog Signed-off-by: Todd Short <[email protected]>
1 parent c54b571 commit 8a34998

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

cmd/catalogd/main.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"time"
3030

3131
"github.com/containers/image/v5/types"
32-
"github.com/sirupsen/logrus"
3332
"github.com/spf13/cobra"
3433
corev1 "k8s.io/api/core/v1"
3534
"k8s.io/apimachinery/pkg/fields"
@@ -41,7 +40,6 @@ import (
4140
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
4241
"k8s.io/client-go/metadata"
4342
_ "k8s.io/client-go/plugin/pkg/client/auth"
44-
"k8s.io/klog/v2"
4543
"k8s.io/klog/v2/textlogger"
4644
"k8s.io/utils/ptr"
4745
ctrl "sigs.k8s.io/controller-runtime"
@@ -139,14 +137,17 @@ func init() {
139137
// adds version subcommand
140138
catalogdCmd.AddCommand(versionCommand)
141139

140+
// Add log verbosity flags
141+
logConfig := textlogger.NewConfig()
142+
logConfig.AddFlags(flag.CommandLine)
143+
142144
// Add other flags
143-
klog.InitFlags(flag.CommandLine)
144145
flags.AddGoFlagSet(flag.CommandLine)
145146
features.CatalogdFeatureGate.AddFlag(flags)
146147

147148
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
148149
utilruntime.Must(ocv1.AddToScheme(scheme))
149-
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
150+
ctrl.SetLogger(textlogger.NewLogger(logConfig))
150151
}
151152

152153
func main() {
@@ -190,10 +191,6 @@ func validateConfig(cfg *config) error {
190191
}
191192

192193
func run(ctx context.Context) error {
193-
if klog.V(4).Enabled() {
194-
logrus.SetLevel(logrus.DebugLevel)
195-
}
196-
197194
authFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s.json", authFilePrefix, apimachineryrand.String(8)))
198195

199196
protocol := "http://"

cmd/operator-controller/main.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"time"
3030

3131
"github.com/containers/image/v5/types"
32-
"github.com/sirupsen/logrus"
3332
"github.com/spf13/cobra"
3433
corev1 "k8s.io/api/core/v1"
3534
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
@@ -39,7 +38,6 @@ import (
3938
apimachineryrand "k8s.io/apimachinery/pkg/util/rand"
4039
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
4140
_ "k8s.io/client-go/plugin/pkg/client/auth"
42-
"k8s.io/klog/v2"
4341
"k8s.io/klog/v2/textlogger"
4442
"k8s.io/utils/ptr"
4543
ctrl "sigs.k8s.io/controller-runtime"
@@ -148,15 +146,16 @@ func init() {
148146
//adds version sub command
149147
operatorControllerCmd.AddCommand(versionCommand)
150148

151-
klog.InitFlags(flag.CommandLine)
149+
// Add log verbosity flags
150+
logConfig := textlogger.NewConfig()
151+
logConfig.AddFlags(flag.CommandLine)
152152

153-
//add klog flags to flagset
154153
flags.AddGoFlagSet(flag.CommandLine)
155154

156155
//add feature gate flags to flagset
157156
features.OperatorControllerFeatureGate.AddFlag(flags)
158157

159-
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
158+
ctrl.SetLogger(textlogger.NewLogger(logConfig))
160159
}
161160
func validateMetricsFlags() error {
162161
if (cfg.certFile != "" && cfg.keyFile == "") || (cfg.certFile == "" && cfg.keyFile != "") {
@@ -179,10 +178,6 @@ func validateMetricsFlags() error {
179178
return nil
180179
}
181180
func run() error {
182-
if klog.V(4).Enabled() {
183-
logrus.SetLevel(logrus.DebugLevel)
184-
}
185-
186181
setupLog.Info("starting up the controller", "version info", version.String())
187182

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

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require (
2121
github.com/operator-framework/helm-operator-plugins v0.8.0
2222
github.com/operator-framework/operator-registry v1.51.0
2323
github.com/prometheus/client_golang v1.22.0
24-
github.com/sirupsen/logrus v1.9.3
2524
github.com/spf13/cobra v1.9.1
2625
github.com/stretchr/testify v1.10.0
2726
golang.org/x/exp v0.0.0-20250228200357-dead58393ab7
@@ -187,6 +186,7 @@ require (
187186
github.com/sigstore/fulcio v1.6.4 // indirect
188187
github.com/sigstore/rekor v1.3.8 // indirect
189188
github.com/sigstore/sigstore v1.8.12 // indirect
189+
github.com/sirupsen/logrus v1.9.3 // indirect
190190
github.com/smallstep/pkcs7 v0.1.1 // indirect
191191
github.com/spf13/cast v1.7.0 // indirect
192192
github.com/spf13/pflag v1.0.6 // indirect

0 commit comments

Comments
 (0)