Skip to content

Conversation

@fmuyassarov
Copy link
Member

What this PR does / why we need it:
Migrate the logging implementation from Zap to klog v2, aligning with the logging approach used by other Metal3 controllers (CAPM3, Ironic, and IPAM). This ensures consistent logging format and behavior.

With Zap

[event: pod baremetal-operator-system/baremetal-operator-controller-manager-797f5848b5-qwd94] MountVolume.SetUp failed for volume "cert" : secret "bmo-webhook-server-cert" not found
[event: certificaterequest baremetal-operator-system/baremetal-operator-serving-cert-8blrz] Certificate will be issued with an empty Issuer DN, which contravenes RFC 5280 and could break some strict clients
[event: pod baremetal-operator-system/baremetal-operator-controller-manager-797f5848b5-qwd94] Container image "ttl.sh/quay.io_metal3-io_baremetal-operator:tilt-a1e1348c338e970e" already present on machine
{"level":"info","ts":1763732778.5139532,"logger":"setup","msg":"Go Version: go1.24.9"}
{"level":"info","ts":1763732778.5140877,"logger":"setup","msg":"Go OS/Arch: linux/amd64"}
{"level":"info","ts":1763732778.5141082,"logger":"setup","msg":"Git commit: unknown"}
{"level":"info","ts":1763732778.5141249,"logger":"setup","msg":"Build time: unknown"}
{"level":"info","ts":1763732778.5141451,"logger":"setup","msg":"Component: metal3-io/baremetal-operator was not built with version info"}
{"level":"info","ts":1763732778.5144372,"logger":"setup","msg":"Manager set up with cluster scope"}
{"level":"info","ts":1763732778.5402086,"logger":"provisioner.ironic","msg":"ironic settings from environment variables","endpoint":"http://172.22.0.2:6385/v1/","ironicAuthType":"noauth","deployKernelURL":"","deployRamdiskURL":"","deployISOURL":"","liveISOForcePersistentBootDevice":"","CACertFile":"/opt/metal3/certs/ca/tls.crt","ClientCertFile":"/opt/metal3/certs/client/tls.crt","ClientPrivKeyFile":"/opt/metal3/certs/client/tls.key","TLSInsecure":false,"SkipClientSANVerify":false}
{"level":"info","ts":1763732778.5402973,"msg":"Operator Concurrency will be set to a default value of 8"}
{"level":"info","ts":1763732778.5405126,"logger":"controller-runtime.builder","msg":"Registering a validating webhook","GVK":"metal3.io/v1alpha1, Kind=BareMetalHost","path":"/validate-metal3-io-v1alpha1-baremetalhost"}
{"level":"info","ts":1763732778.5406096,"logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/validate-metal3-io-v1alpha1-baremetalhost"}
{"level":"info","ts":1763732778.540673,"logger":"controller-runtime.builder","msg":"Registering a validating webhook","GVK":"metal3.io/v1alpha1, Kind=BMCEventSubscription","path":"/validate-metal3-io-v1alpha1-bmceventsubscription"}
{"level":"info","ts":1763732778.5407052,"logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/validate-metal3-io-v1alpha1-bmceventsubscription"}
{"level":"info","ts":1763732778.5407343,"logger":"setup","msg":"starting manager"}
{"level":"info","ts":1763732778.5415323,"logger":"controller-runtime.metrics","msg":"Starting metrics server"}
{"level":"info","ts":1763732778.5416996,"msg":"starting server","name":"health probe","addr":"[::]:9440"}
{"level":"info","ts":1763732778.5419533,"logger":"controller-runtime.webhook","msg":"Starting webhook server"}
I1121 13:46:18.542544       1 leaderelection.go:257] attempting to acquire leader lease baremetal-operator-system/baremetal-operator...
{"level":"info","ts":1763732778.5430126,"logger":"controller-runtime.certwatcher","msg":"Updated current TLS certificate","cert":"/tmp/k8s-webhook-server/serving-certs/tls.crt","key":"/tmp/k8s-webhook-server/serving-certs/tls.key"}
{"level":"info","ts":1763732778.5431976,"logger":"controller-runtime.webhook","msg":"Serving webhook server","host":"","port":9443}
{"level":"info","ts":1763732778.5435364,"logger":"controller-runtime.certwatcher","msg":"Starting certificate poll+watcher","cert":"/tmp/k8s-webhook-server/serving-certs/tls.crt","key":"/tmp/k8s-webhook-server/serving-certs/tls.key","interval":10}
I1121 13:46:18.558326       1 leaderelection.go:271] successfully acquired lease baremetal-operator-system/baremetal-operator
{"level":"info","ts":1763732778.5590167,"msg":"Starting EventSource","controller":"baremetalhost","controllerGroup":"metal3.io","controllerKind":"BareMetalHost","source":"kind source: *v1.Secret"}
{"level":"info","ts":1763732778.5591114,"msg":"Starting EventSource","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription","source":"kind source: *v1alpha1.BareMetalHost"}
{"level":"info","ts":1763732778.559053,"msg":"Starting EventSource","controller":"baremetalhost","controllerGroup":"metal3.io","controllerKind":"BareMetalHost","source":"kind source: *v1alpha1.BareMetalHost"}
{"level":"info","ts":1763732778.559231,"msg":"Starting EventSource","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription","source":"kind source: *v1alpha1.BMCEventSubscription"}
{"level":"info","ts":1763732778.5594149,"msg":"Starting EventSource","controller":"hostfirmwarecomponents","controllerGroup":"metal3.io","controllerKind":"HostFirmwareComponents","source":"kind source: *v1alpha1.HostFirmwareComponents"}
{"level":"info","ts":1763732778.5593762,"msg":"Starting EventSource","controller":"hostfirmwaresettings","controllerGroup":"metal3.io","controllerKind":"HostFirmwareSettings","source":"kind source: *v1alpha1.HostFirmwareSettings"}
{"level":"info","ts":1763732778.5634055,"msg":"Starting EventSource","controller":"dataimage","controllerGroup":"metal3.io","controllerKind":"DataImage","source":"kind source: *v1alpha1.DataImage"}
{"level":"info","ts":1763732778.6602478,"msg":"Starting Controller","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription"}
{"level":"info","ts":1763732778.6603315,"msg":"Starting workers","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription","worker count":8}
{"level":"info","ts":1763732778.66039,"msg":"Starting Controller","controller":"baremetalhost","controllerGroup":"metal3.io","controllerKind":"BareMetalHost"}
{"level":"info","ts":1763732778.66044,"msg":"Starting workers","controller":"baremetalhost","controllerGroup":"metal3.io","controllerKind":"BareMetalHost","worker count":8}
{"level":"info","ts":1763732778.6667964,"msg":"Starting Controller","controller":"hostfirmwarecomponents","controllerGroup":"metal3.io","controllerKind":"HostFirmwareComponents"}
{"level":"info","ts":1763732778.666833,"msg":"Starting workers","controller":"hostfirmwarecomponents","controllerGroup":"metal3.io","controllerKind":"HostFirmwareComponents","worker count":8}
{"level":"info","ts":1763732778.6668508,"msg":"Starting Controller","controller":"hostfirmwaresettings","controllerGroup":"metal3.io","controllerKind":"HostFirmwareSettings"}
{"level":"info","ts":1763732778.666881,"msg":"Starting workers","controller":"hostfirmwaresettings","controllerGroup":"metal3.io","controllerKind":"HostFirmwareSettings","worker count":8}
{"level":"info","ts":1763732778.6670685,"msg":"Starting Controller","controller":"dataimage","controllerGroup":"metal3.io","controllerKind":"DataImage"}
{"level":"info","ts":1763732778.6670992,"msg":"Starting workers","controller":"dataimage","controllerGroup":"metal3.io","controllerKind":"DataImage","worker count":8}
{"level":"info","ts":1763732779.1781714,"logger":"controller-runtime.metrics","msg":"Serving metrics server","bindAddress":":8443","secure":true}

With klog

[event: pod baremetal-operator-system/baremetal-operator-controller-manager-74c7474589-wst4g] MountVolume.SetUp failed for volume "cert" : secret "bmo-webhook-server-cert" not found
[event: certificaterequest baremetal-operator-system/baremetal-operator-serving-cert-m6p5d] Certificate will be issued with an empty Issuer DN, which contravenes RFC 5280 and could break some strict clients
[event: pod baremetal-operator-system/baremetal-operator-controller-manager-74c7474589-wst4g] Container image "ttl.sh/quay.io_metal3-io_baremetal-operator:tilt-231f03537fe894f8" already present on machine
I1121 14:38:15.624523       1 main.go:83] "Go Version: go1.24.9" logger="setup"
I1121 14:38:15.624641       1 main.go:84] "Go OS/Arch: linux/amd64" logger="setup"
I1121 14:38:15.624648       1 main.go:85] "Git commit: unknown" logger="setup"
I1121 14:38:15.624653       1 main.go:86] "Build time: unknown" logger="setup"
I1121 14:38:15.624992       1 main.go:87] "Component: metal3-io/baremetal-operator was not built with version info" logger="setup"
I1121 14:38:15.625472       1 main.go:210] "Manager set up with cluster scope" logger="setup"
I1121 14:38:15.652880       1 factory.go:98] "ironic settings from environment variables" logger="controllers.ironic" endpoint="http://172.22.0.2:6385/v1/" ironicAuthType="noauth" deployKernelURL="" deployRamdiskURL="" deployISOURL="" liveISOForcePersistentBootDevice="" CACertFile="/opt/metal3/certs/ca/tls.crt" ClientCertFile="/opt/metal3/certs/client/tls.crt" ClientPrivKeyFile="/opt/metal3/certs/client/tls.key" TLSInsecure=false SkipClientSANVerify=false
I1121 14:38:15.652932       1 main.go:489] "Operator Concurrency will be set to a default value of 8"
I1121 14:38:15.653102       1 webhook.go:258] "Registering a validating webhook" logger="controller-runtime.builder" GVK="metal3.io/v1alpha1, Kind=BareMetalHost" path="/validate-metal3-io-v1alpha1-baremetalhost"
I1121 14:38:15.653205       1 server.go:183] "Registering webhook" logger="controller-runtime.webhook" path="/validate-metal3-io-v1alpha1-baremetalhost"
I1121 14:38:15.653272       1 webhook.go:258] "Registering a validating webhook" logger="controller-runtime.builder" GVK="metal3.io/v1alpha1, Kind=BMCEventSubscription" path="/validate-metal3-io-v1alpha1-bmceventsubscription"
I1121 14:38:15.653318       1 server.go:183] "Registering webhook" logger="controller-runtime.webhook" path="/validate-metal3-io-v1alpha1-bmceventsubscription"
I1121 14:38:15.653355       1 main.go:391] "starting manager" logger="setup"
I1121 14:38:15.653961       1 server.go:208] "Starting metrics server" logger="controller-runtime.metrics"
I1121 14:38:15.654046       1 server.go:83] "starting server" name="health probe" addr="[::]:9440"
I1121 14:38:15.654466       1 server.go:191] "Starting webhook server" logger="controller-runtime.webhook"
I1121 14:38:15.654946       1 leaderelection.go:257] attempting to acquire leader lease baremetal-operator-system/baremetal-operator...
I1121 14:38:15.655484       1 certwatcher.go:214] "Updated current TLS certificate" logger="controller-runtime.certwatcher" cert="/tmp/k8s-webhook-server/serving-certs/tls.crt" key="/tmp/k8s-webhook-server/serving-certs/tls.key"
I1121 14:38:15.655755       1 server.go:242] "Serving webhook server" logger="controller-runtime.webhook" host="" port=9443
I1121 14:38:15.655959       1 certwatcher.go:136] "Starting certificate poll+watcher" logger="controller-runtime.certwatcher" cert="/tmp/k8s-webhook-server/serving-certs/tls.crt" key="/tmp/k8s-webhook-server/serving-certs/tls.key" interval="10s"
I1121 14:38:15.669755       1 leaderelection.go:271] successfully acquired lease baremetal-operator-system/baremetal-operator
I1121 14:38:15.670535       1 controller.go:353] "Starting EventSource" controller="baremetalhost" controllerGroup="metal3.io" controllerKind="BareMetalHost" source="kind source: *v1.Secret"
I1121 14:38:15.670501       1 controller.go:353] "Starting EventSource" controller="baremetalhost" controllerGroup="metal3.io" controllerKind="BareMetalHost" source="kind source: *v1alpha1.BareMetalHost"
I1121 14:38:15.670688       1 controller.go:353] "Starting EventSource" controller="bmceventsubscription" controllerGroup="metal3.io" controllerKind="BMCEventSubscription" source="kind source: *v1alpha1.BareMetalHost"
I1121 14:38:15.670753       1 controller.go:353] "Starting EventSource" controller="hostfirmwaresettings" controllerGroup="metal3.io" controllerKind="HostFirmwareSettings" source="kind source: *v1alpha1.HostFirmwareSettings"
I1121 14:38:15.674987       1 controller.go:353] "Starting EventSource" controller="bmceventsubscription" controllerGroup="metal3.io" controllerKind="BMCEventSubscription" source="kind source: *v1alpha1.BMCEventSubscription"
I1121 14:38:15.677534       1 controller.go:353] "Starting EventSource" controller="hostfirmwarecomponents" controllerGroup="metal3.io" controllerKind="HostFirmwareComponents" source="kind source: *v1alpha1.HostFirmwareComponents"
I1121 14:38:15.677708       1 controller.go:353] "Starting EventSource" controller="dataimage" controllerGroup="metal3.io" controllerKind="DataImage" source="kind source: *v1alpha1.DataImage"
I1121 14:38:15.778338       1 controller.go:286] "Starting Controller" controller="baremetalhost" controllerGroup="metal3.io" controllerKind="BareMetalHost"
I1121 14:38:15.778412       1 controller.go:289] "Starting workers" controller="baremetalhost" controllerGroup="metal3.io" controllerKind="BareMetalHost" worker count=8
I1121 14:38:15.778661       1 controller.go:286] "Starting Controller" controller="dataimage" controllerGroup="metal3.io" controllerKind="DataImage"
I1121 14:38:15.778682       1 controller.go:286] "Starting Controller" controller="hostfirmwarecomponents" controllerGroup="metal3.io" controllerKind="HostFirmwareComponents"
I1121 14:38:15.778722       1 controller.go:289] "Starting workers" controller="dataimage" controllerGroup="metal3.io" controllerKind="DataImage" worker count=8
I1121 14:38:15.778726       1 controller.go:289] "Starting workers" controller="hostfirmwarecomponents" controllerGroup="metal3.io" controllerKind="HostFirmwareComponents" worker count=8
I1121 14:38:15.778874       1 controller.go:286] "Starting Controller" controller="hostfirmwaresettings" controllerGroup="metal3.io" controllerKind="HostFirmwareSettings"
I1121 14:38:15.778889       1 controller.go:289] "Starting workers" controller="hostfirmwaresettings" controllerGroup="metal3.io" controllerKind="HostFirmwareSettings" worker count=8
I1121 14:38:15.780105       1 controller.go:286] "Starting Controller" controller="bmceventsubscription" controllerGroup="metal3.io" controllerKind="BMCEventSubscription"
I1121 14:38:15.780151       1 controller.go:289] "Starting workers" controller="bmceventsubscription" controllerGroup="metal3.io" controllerKind="BMCEventSubscription" worker count=8
I1121 14:38:15.985150       1 server.go:247] "Serving metrics server" logger="controller-runtime.metrics" bindAddress=":8443" secure=true

@metal3-io-bot metal3-io-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 27, 2025
@fmuyassarov
Copy link
Member Author

/assign @kashifest

@tuminoid
Copy link
Member

Fix the DCO and squash the commit, please.

@tuminoid
Copy link
Member

/assign @kashifest

Use /cc for requesting reviews.
/cc @kashifest

@fmuyassarov
Copy link
Member Author

Fix the DCO and squash the commit, please.

I would prefer to keep them as they are actually unless there is a valid reason to squash them.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the logging implementation from Zap to klog v2 to align with logging approaches used in other Metal3 controllers (CAPM3, Ironic, and IPAM), ensuring consistent logging format and behavior across the Metal3 ecosystem.

  • Replaces Zap logger initialization with klog v2 throughout the codebase
  • Removes Zap-specific configuration including development mode and time encoder settings
  • Updates logger naming hierarchy by removing intermediate "controllers" namespace level
  • Simplifies variable declarations in main.go by grouping them in a single var block

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
main.go Removes Zap initialization and configuration, replaces with klog.NewKlogr(), updates logger naming for controllers, and converts setupLog usage to direct klog calls in several places
pkg/provisioner/ironic/factory.go Adds newline prefixes to logging key names for multi-line formatting of ironic configuration settings
pkg/provisioner/fixture/fixture.go Replaces Zap logger initialization with klog.NewKlogr() for the fixture provisioner
go.mod Moves go.uber.org/zap from direct dependency to indirect dependency since it's no longer directly used
Comments suppressed due to low confidence (1)

main.go:143

  • The devLogging variable is declared and set via the --dev flag but is no longer used after removing the Zap configuration. This flag should either be removed if not needed, or the klog configuration should respect it (e.g., by setting verbosity level based on this flag).
		devLogging            bool
		runInTestMode         bool
		runInDemoMode         bool
		webhookPort           int
		restConfigQPS         float64
		restConfigBurst       int
		controllerConcurrency int
		leaseDurationSeconds  string
		renewDeadlineSeconds  string
		retryPeriodSeconds    string
	)
	// From CAPI point of view, BMO should be able to watch all namespaces
	// in case of a deployment that is not multi-tenant. If the deployment
	// is for multi-tenancy, then the BMO should watch only the provided
	// namespace.
	flag.StringVar(&watchNamespace, "namespace", os.Getenv("WATCH_NAMESPACE"),
		"Namespace that the controller watches to reconcile host resources.")
	flag.StringVar(&metricsBindAddr, "metrics-addr", ":8443",
		"The address the metric endpoint binds to.")
	flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
		"Enable leader election for controller manager. "+
			"Enabling this will ensure there is only one active controller manager.")
	flag.BoolVar(&preprovImgEnable, "build-preprov-image", false, "enable integration with the PreprovisioningImage API")
	flag.BoolVar(&devLogging, "dev", false, "enable developer logging")

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tuminoid
Copy link
Member

Fix the DCO and squash the commit, please.

I would prefer to keep them as they are actually unless there is a valid reason to squash them.

I don't think the amount of code in them warrants multiple commits.

@metal3-io-bot metal3-io-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 27, 2025
@fmuyassarov
Copy link
Member Author

fmuyassarov commented Nov 27, 2025

Fix the DCO and squash the commit, please.

I would prefer to keep them as they are actually unless there is a valid reason to squash them.

I don't think the amount of code in them warrants multiple commits.

I also don't think that amount of the code is the factor for dividing PRs into commits, but rather commits should be self-contained and functional on their own.

@fmuyassarov
Copy link
Member Author

@tuminoid it is a single commit now + I've dropped the unrelated commit from the list.

@kashifest
Copy link
Member

/approve

I am honestly not sure if the unresolved copilot review needs to be addressed or not. Looks ok to me.

@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kashifest

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 27, 2025
@metal3-io-bot metal3-io-bot removed the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2025
@fmuyassarov
Copy link
Member Author

/approve

I am honestly not sure if the unresolved copilot review needs to be addressed or not. Looks ok to me.

that's something tiny but I fixed now + rebased the tree.

@fmuyassarov
Copy link
Member Author

/approve
I am honestly not sure if the unresolved copilot review needs to be addressed or not. Looks ok to me.

that's something tiny but I fixed now + rebased the tree.

@kashifest actually it was a bad idea to fix what copilot asked 😄 , because it had no context and it broke the unit tests since they have some expectation for certain error messages in certain string. I reverted it to use Infof instead if Info.

@lentzi90
Copy link
Member

Could you comment on the resolved copilot comments that you didn't do anything about? It would be very helpful for the review to know why the comment was not addressed. I may have similar comments otherwise 😉

@fmuyassarov
Copy link
Member Author

Could you comment on the resolved copilot comments that you didn't do anything about? It would be very helpful for the review to know why the comment was not addressed. I may have similar comments otherwise 😉

Sure. The reason I skipped those suggestions is that I want to maintain the same ordering and structure of the logging context. In the current implementation, the setup context is only added for certain log messages, not all of them. If you look at the PR description, you can see how it behaved previously with zap and how it works now with klog. I tried to keep the context consistent with the original behavior, which is why I skipped all of those Copilot comments.

Direct calls to klog.Info() bypass the logger hierarchy and won't include the "setup" logger context that setupLog provides. Consider using setupLog.Info() instead for consistency with other setup-related log messages in this function (e.g., lines 182, 192, 259, etc.).

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, to me the example output looks much better with zap. That is structured logging that can be parsed easily to filter out specific fields and so on.

@lentzi90
Copy link
Member

It feels to me like we are here trying to switch to a different logger, that is supposed to behave differently, but we still want to keep the behavior the way it was. Not adjusting unit tests, etc. This is not a good idea.
If we want to switch, let's do it properly.
/hold

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 28, 2025
@fmuyassarov
Copy link
Member Author

It feels to me like we are here trying to switch to a different logger, that is supposed to behave differently, but we still want to keep the behavior the way it was. Not adjusting unit tests, etc. This is not a good idea. If we want to switch, let's do it properly. /hold

Sure, but what shall we fix? I don't get it. All CI tests have passed, no?

@lentzi90
Copy link
Member

How about this:

Using klog.Infof() with format strings is not idiomatic for structured logging with klog v2. The recommended approach is to use klog.Info() (or a logger's .Info() method) with key-value pairs for structured logging. Consider changing this to use structured logging, e.g., setupLog.Info("warning: use of insecure cipher detected", "cipher", cipher).

You replied to this that it doesn't make sense because it breaks unit tests. So my interpretation is that we are here trying to keep the behavior even when that is not idiomatic or recommended. This is what I mean we should fix. Either update the unit tests and address the comment or explain why this comment is wrong.

@fmuyassarov
Copy link
Member Author

You replied to this that it doesn't make sense because it breaks unit tests. So my interpretation is that we are here trying to keep the behavior even when that is not idiomatic or recommended. This is what I mean we should fix. Either update the unit tests and address the comment or explain why this comment is wrong.

I can try and I think I replied here that it broke the CI due to it expecting specific string.

Anyways, If I address and use the suggestion of copilot,

diff --git a/main.go b/main.go
index 15652755..2eacfd59 100644
--- a/main.go
+++ b/main.go
@@ -447,7 +447,7 @@ func GetTLSOptionOverrideFuncs(options TLSOptions) ([]func(*tls.Config), error)
                for _, cipher := range tlsCipherSuites {
                        for _, insecureCipherName := range insecureCipherValues {
                                if insecureCipherName == cipher {
-                                       klog.Infof("warning: use of insecure cipher '%s' detected.", cipher)
+                                       klog.Info("warning: use of insecure cipher detected", "cipher", cipher)
                                }
                        }
                }
(END)

It breaks the test because we are checking for string value in the error message. However, Infof takes a format string and arguments similar to fmt.Printf.

go test -coverprofile=cover.out  ./...
--- FAIL: TestTLSInsecureCiperSuite (0.00s)
    --- FAIL: TestTLSInsecureCiperSuite/test_insecure_cipher_suite_passed_as_TLS_flag (0.00s)
        main_test.go:45:
            Expected
                <string>: I1128 12:17:53.257404   54613 main.go:450] warning: use of insecure cipher detectedcipherTLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256

            to contain substring
                <string>: use of insecure cipher 'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256' detected.
FAIL

@lentzi90
Copy link
Member

It looks like we are missing some config options to make klog format the messages properly.

@fmuyassarov
Copy link
Member Author

@lentzi90 I've addressed your comments. PTAL.

This commit removes the dependencies on go.uber.org/zap and
sigs.k8s.io/controller-runtime/pkg/log/zap, replacing them with
klog v2. Other Metal3 controllers—including CAPM3, Ironic, and IPAM—
already use klog v2, so this change aligns the logging approach across
the project and ensures a consistent logging format.

Signed-off-by: Feruzjon Muyassarov <[email protected]>
@fmuyassarov
Copy link
Member Author

/retest

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still three places where setupLog is changed to klog. I think we should stick to setupLog for those.
I am still also concerned about the change in format. Changing to klog is fine and for the better, but we should configure it to have similar output format. I have no issue with the change in the timestamp format, but we should keep the nice json format that makes it easy to parse with tools.

Current main:

{"level":"info","ts":1764817462.027348,"logger":"setup","msg":"Go Version: go1.24.11"}
{"level":"info","ts":1764817462.027371,"logger":"setup","msg":"Go OS/Arch: linux/amd64"}
{"level":"info","ts":1764817462.0273771,"logger":"setup","msg":"Git commit: unknown"}
{"level":"info","ts":1764817462.0273826,"logger":"setup","msg":"Build time: unknown"}
{"level":"info","ts":1764817462.027388,"logger":"setup","msg":"Component: metal3-io/baremetal-operator was not built with version info"}
{"level":"info","ts":1764817462.0274692,"logger":"setup","msg":"Manager set up with multiple namespaces to watch","namespaces":"basic-ops,external-inspection,externally-provisioned,inspection,live-iso-ops,provisioning-ops,re-inspection,automated-cleaning,upgrade-bmo,upgrade-ironic"}
...
{"level":"info","ts":1764817463.04442,"msg":"Starting Controller","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription"}
{"level":"info","ts":1764817463.0443861,"msg":"Starting Controller","controller":"hostfirmwaresettings","controllerGroup":"metal3.io","controllerKind":"HostFirmwareSettings"}
{"level":"info","ts":1764817463.0444293,"msg":"Starting workers","controller":"hostfirmwaresettings","controllerGroup":"metal3.io","controllerKind":"HostFirmwareSettings","worker count":8}
{"level":"info","ts":1764817463.0444257,"msg":"Starting workers","controller":"bmceventsubscription","controllerGroup":"metal3.io","controllerKind":"BMCEventSubscription","worker count":8}

This PR:

I1203 08:36:54.537138       1 main.go:82] "Go Version: go1.24.9" logger="setup"
I1203 08:36:54.537240       1 main.go:83] "Go OS/Arch: linux/amd64" logger="setup"
I1203 08:36:54.537245       1 main.go:84] "Git commit: unknown" logger="setup"
I1203 08:36:54.537249       1 main.go:85] "Build time: unknown" logger="setup"
I1203 08:36:54.537254       1 main.go:86] "Component: metal3-io/baremetal-operator was not built with version info" logger="setup"
I1203 08:36:54.537358       1 main.go:200] "Manager set up with multiple namespaces to watch" logger="setup" namespaces="basic-ops,external-inspection,externally-provisioned,inspection,live-iso-ops,provisioning-ops,re-inspection,automated-cleaning,upgrade-bmo,upgrade-ironic"
...
I1203 08:36:55.555709       1 controller.go:289] "Starting workers" controller="baremetalhost" controllerGroup="metal3.io" controllerKind="BareMetalHost" worker count=8
I1203 08:36:55.555714       1 controller.go:289] "Starting workers" controller="hostfirmwarecomponents" controllerGroup="metal3.io" controllerKind="HostFirmwareComponents" worker count=8
I1203 08:36:55.555661       1 controller.go:286] "Starting Controller" controller="hostfirmwaresettings" controllerGroup="metal3.io" controllerKind="HostFirmwareSettings"
I1203 08:36:55.555661       1 controller.go:286] "Starting Controller" controller="bmceventsubscription" controllerGroup="metal3.io" controllerKind="BMCEventSubscription"

@dtantsur
Copy link
Member

dtantsur commented Dec 4, 2025

Honestly, I'd rather have the format parseable by humans by default (i.e. klog) but maybe it's only me.

@shenwei66
Copy link

In my opinion,klog is batter than zag.

@lentzi90
Copy link
Member

lentzi90 commented Dec 9, 2025

I am also fine, and supportive of switching to klog. I would however prefer to not change the format at the same time. But if the community wants to change the format, fine.
The three places where setupLog was changed to klog are still there and I want either an explanation for why or that they are reverted.

Copy link
Member

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the consistency of the logs in the org right now? We don't want to be logging four different ways and formats.

@fmuyassarov
Copy link
Member Author

How is the consistency of the logs in the org right now? We don't want to be logging four different ways and formats.

unfortunately that's already the case and i want to fix that as well a long the way.

@fmuyassarov
Copy link
Member Author

If people are really keen on parsing the logs of BMO, I will check how to have the JSON format. Don't recall if there is a flag but will test and confirm.

@tuminoid
Copy link
Member

tuminoid commented Dec 9, 2025

How is the consistency of the logs in the org right now? We don't want to be logging four different ways and formats.

unfortunately that's already the case and i want to fix that as well a long the way.

For that reason we need consensus where to take the logging. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants