Skip to content

Commit 4dc36a6

Browse files
committed
External-ccm: Use appropriate method for printf-style log calls
zap's sugared logger `Fatal`/`Error`/`Info`/`Debug` methods treat their first argument as a plain string, not a format string. Passing format verbs like `%s`/`%v` without the 'f' suffix causes them to appear literally in log output instead of being interpolated. Example of a log with no printf formatting we can see today: ``` 2026-03-06T21:08:01.983Z FATAL FSS csi-controller-driver/oci-csi-controller-driver.go:56 Failed to run the CSI driver for %s.FSS {"component": "csi-controller", "error": "failed to remove unix domain socket file /var/run/shared-tmpfs/csi-fss.sock"} ``` Also removed a duplicated error from a log in `node_info_controller.go` where `err` was attached to the log both with `zap.Error(err)` and through a (broken) printf-style `%v`. Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
1 parent fecd842 commit 4dc36a6

7 files changed

Lines changed: 10 additions & 10 deletions

File tree

cmd/oci-csi-controller-driver/csi-controller-driver/oci-csi-controller-driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ func StartControllerDriver(csioptions csioptions.CSIOptions, csiDriver driver.CS
5454
drv, err = driver.NewControllerDriver(logger, *controllerDriverConfig)
5555
}
5656
if err != nil {
57-
logger.With(zap.Error(err)).Fatal("Failed to create %s controller driver.", csiDriver)
57+
logger.With(zap.Error(err)).Fatalf("Failed to create %s controller driver.", csiDriver)
5858
}
5959
if err := drv.Run(); err != nil {
60-
logger.With(zap.Error(err)).Fatal("Failed to run the CSI driver for %s.", csiDriver)
60+
logger.With(zap.Error(err)).Fatalf("Failed to run the CSI driver for %s.", csiDriver)
6161
}
6262

6363
logger.Info("CSI driver exited")

pkg/cloudprovider/providers/oci/load_balancer_spec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ func getPreserveSource(logger *zap.SugaredLogger, svc *v1.Service) (bool, error)
696696
if svc.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeCluster {
697697
_, ok := svc.Annotations[ServiceAnnotationNetworkLoadBalancerIsPreserveSource]
698698
if ok {
699-
logger.Error("error : externalTrafficPolicy is set to Cluster and the %s annotation is set", ServiceAnnotationNetworkLoadBalancerIsPreserveSource)
699+
logger.Errorf("error : externalTrafficPolicy is set to Cluster and the %s annotation is set", ServiceAnnotationNetworkLoadBalancerIsPreserveSource)
700700
return false, fmt.Errorf("%s annotation cannot be set when externalTrafficPolicy is set to Cluster", ServiceAnnotationNetworkLoadBalancerIsPreserveSource)
701701
}
702702
}
@@ -715,7 +715,7 @@ func getPreserveSourceAnnotation(logger *zap.SugaredLogger, svc *v1.Service) (bo
715715
if annotationString, ok := svc.Annotations[ServiceAnnotationNetworkLoadBalancerIsPreserveSource]; ok {
716716
enable, err := strconv.ParseBool(annotationString)
717717
if err != nil {
718-
logger.Error("failed to to parse %s annotation value - %s", ServiceAnnotationNetworkLoadBalancerIsPreserveSource, annotationString)
718+
logger.Errorf("failed to to parse %s annotation value - %s", ServiceAnnotationNetworkLoadBalancerIsPreserveSource, annotationString)
719719
return false, fmt.Errorf("failed to to parse %s annotation value - %s", ServiceAnnotationNetworkLoadBalancerIsPreserveSource, annotationString)
720720
}
721721
return enable, nil

pkg/cloudprovider/providers/oci/node_info_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (nic *NodeInfoController) processItem(key string) error {
188188
return err
189189
})
190190
if err != nil {
191-
logger.With(zap.Error(err)).Error("Error in applying patch in node %v", err)
191+
logger.With(zap.Error(err)).Error("Error in applying patch in node")
192192
return err
193193
}
194194

pkg/oci/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (c *client) Networking(ociClientConfig *OCIClientConfig) NetworkingInterfac
403403

404404
err = configureCustomTransport(c.logger, &network.BaseClient)
405405
if err != nil {
406-
c.logger.Error("Failed configure custom transport for Network Client %v", err)
406+
c.logger.Errorf("Failed configure custom transport for Network Client %v", err)
407407
return nil
408408
}
409409

@@ -443,7 +443,7 @@ func (c *client) Identity(ociClientConfig *OCIClientConfig) IdentityInterface {
443443

444444
err = configureCustomTransport(c.logger, &identity.BaseClient)
445445
if err != nil {
446-
c.logger.Error("Failed configure custom transport for Identity Client %v", err)
446+
c.logger.Errorf("Failed configure custom transport for Identity Client %v", err)
447447
return nil
448448
}
449449

pkg/oci/client/load_balancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (c *loadbalancerClientStruct) GetLoadBalancerByName(ctx context.Context, co
115115
if *lb.DisplayName == name && *lb.CompartmentId == compartmentID {
116116
return lb, err
117117
}
118-
logger.Info("LB name to OCID cache stale record. Actual display name: %s, compartment %s", *lb.DisplayName, *lb.CompartmentId)
118+
logger.Infof("LB name to OCID cache stale record. Actual display name: %s, compartment %s", *lb.DisplayName, *lb.CompartmentId)
119119
} else {
120120
logger.Info("LB name to OCID cache failed to get LB or the response contained unexpected nil value")
121121
}

pkg/oci/client/network_load_balancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (c *networkLoadbalancer) GetLoadBalancerByName(ctx context.Context, compart
8888
if *lb.DisplayName == name && *lb.CompartmentId == compartmentID {
8989
return lb, err
9090
}
91-
logger.Info("NLB name to OCID cache stale record. Actual display name: %s, compartment %s", *lb.DisplayName, *lb.CompartmentId)
91+
logger.Infof("NLB name to OCID cache stale record. Actual display name: %s, compartment %s", *lb.DisplayName, *lb.CompartmentId)
9292
} else {
9393
logger.Info("NLB name to OCID cache failed to get LB or the response contained unexpected nil value")
9494
}

pkg/util/disk/mount_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func MountWithEncrypt(logger *zap.SugaredLogger, source string, target string, f
4949
mountArgs, mountArgsLogStr := MakeMountArgs(source, target, fstype, options)
5050
mountArgsLogStr = EncryptionMountCommand + " " + mountArgsLogStr
5151

52-
logger.Debug("Mounting cmd (%s) with arguments (%s)", EncryptionMountCommand, mountArgsLogStr)
52+
logger.Debugf("Mounting cmd (%s) with arguments (%s)", EncryptionMountCommand, mountArgsLogStr)
5353
command := exec.Command(EncryptionMountCommand, mountArgs...)
5454
output, err := command.CombinedOutput()
5555
if err != nil {

0 commit comments

Comments
 (0)