Skip to content

Commit d96c886

Browse files
committed
fix: Address all govet printf issues across the codebase
Signed-off-by: wei-chenglai <[email protected]>
1 parent 0b75a70 commit d96c886

File tree

9 files changed

+24
-23
lines changed

9 files changed

+24
-23
lines changed

pkg/controllers/binding/binding_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (c *ResourceBindingController) syncBinding(ctx context.Context, binding *wo
137137
}
138138

139139
msg := fmt.Sprintf("Sync work of resourceBinding(%s/%s) successful.", binding.Namespace, binding.Name)
140-
klog.V(4).Infof(msg)
140+
klog.V(4).Info(msg)
141141
c.EventRecorder.Event(binding, corev1.EventTypeNormal, events.EventReasonSyncWorkSucceed, msg)
142142
c.EventRecorder.Event(workload, corev1.EventTypeNormal, events.EventReasonSyncWorkSucceed, msg)
143143
return controllerruntime.Result{}, nil

pkg/controllers/binding/cluster_resource_binding_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (c *ClusterResourceBindingController) syncBinding(ctx context.Context, bind
136136
}
137137

138138
msg := fmt.Sprintf("Sync work of clusterResourceBinding(%s) successful.", binding.GetName())
139-
klog.V(4).Infof(msg)
139+
klog.V(4).Info(msg)
140140
c.EventRecorder.Event(binding, corev1.EventTypeNormal, events.EventReasonSyncWorkSucceed, msg)
141141
c.EventRecorder.Event(workload, corev1.EventTypeNormal, events.EventReasonSyncWorkSucceed, msg)
142142
return controllerruntime.Result{}, nil

pkg/controllers/federatedhpa/federatedhpa_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func (c *FHPAController) scaleForTargetCluster(ctx context.Context, clusters []s
517517
if err != nil {
518518
errMsg := fmt.Sprintf("couldn't convert selector into a corresponding internal selector object: %v", err)
519519
c.EventRecorder.Event(hpa, corev1.EventTypeWarning, "InvalidSelector", errMsg)
520-
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "InvalidSelector", errMsg)
520+
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "InvalidSelector", "%s", errMsg)
521521
continue
522522
}
523523

@@ -633,7 +633,7 @@ func (c *FHPAController) computeReplicasForMetrics(ctx context.Context, hpa *aut
633633
// return an error and set the condition of the hpa based on the first invalid metric.
634634
// Otherwise set the condition as scaling active as we're going to scale
635635
if invalidMetricsCount >= len(metricSpecs) || (invalidMetricsCount > 0 && replicas < specReplicas) {
636-
setCondition(hpa, invalidMetricCondition.Type, invalidMetricCondition.Status, invalidMetricCondition.Reason, invalidMetricCondition.Message)
636+
setCondition(hpa, invalidMetricCondition.Type, invalidMetricCondition.Status, invalidMetricCondition.Reason, "%s", invalidMetricCondition.Message)
637637
return -1, "", statuses, time.Time{}, invalidMetricError
638638
}
639639
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionTrue, "ValidMetricFound", "the HPA was able to successfully calculate a replica count from %s", metric)
@@ -678,7 +678,7 @@ func (c *FHPAController) validateAndParseSelector(hpa *autoscalingv1alpha1.Feder
678678
if err != nil {
679679
errMsg := fmt.Sprintf("couldn't convert selector into a corresponding internal selector object: %v", err)
680680
c.EventRecorder.Event(hpa, corev1.EventTypeWarning, "InvalidSelector", errMsg)
681-
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "InvalidSelector", errMsg)
681+
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "InvalidSelector", "%s", errMsg)
682682
return nil, errors.New(errMsg)
683683
}
684684

@@ -693,7 +693,7 @@ func (c *FHPAController) validateAndParseSelector(hpa *autoscalingv1alpha1.Feder
693693
if len(selectingHpas) > 1 {
694694
errMsg := fmt.Sprintf("pods by selector %v are controlled by multiple HPAs: %v", selector, selectingHpas)
695695
c.EventRecorder.Event(hpa, corev1.EventTypeWarning, "AmbiguousSelector", errMsg)
696-
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "AmbiguousSelector", errMsg)
696+
setCondition(hpa, autoscalingv2.ScalingActive, corev1.ConditionFalse, "AmbiguousSelector", "%s", errMsg)
697697
return nil, errors.New(errMsg)
698698
}
699699

@@ -969,9 +969,9 @@ func (c *FHPAController) normalizeDesiredReplicas(hpa *autoscalingv1alpha1.Feder
969969
desiredReplicas, condition, reason := convertDesiredReplicasWithRules(currentReplicas, stabilizedRecommendation, minReplicas, hpa.Spec.MaxReplicas)
970970

971971
if desiredReplicas == stabilizedRecommendation {
972-
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionFalse, condition, reason)
972+
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionFalse, condition, "%s", reason)
973973
} else {
974-
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionTrue, condition, reason)
974+
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionTrue, condition, "%s", reason)
975975
}
976976

977977
return desiredReplicas
@@ -1007,15 +1007,15 @@ func (c *FHPAController) normalizeDesiredReplicasWithBehaviors(hpa *autoscalingv
10071007
normalizationArg.DesiredReplicas = stabilizedRecommendation
10081008
if stabilizedRecommendation != prenormalizedDesiredReplicas {
10091009
// "ScaleUpStabilized" || "ScaleDownStabilized"
1010-
setCondition(hpa, autoscalingv2.AbleToScale, corev1.ConditionTrue, reason, message)
1010+
setCondition(hpa, autoscalingv2.AbleToScale, corev1.ConditionTrue, reason, "%s", message)
10111011
} else {
10121012
setCondition(hpa, autoscalingv2.AbleToScale, corev1.ConditionTrue, "ReadyForNewScale", "recommended size matches current size")
10131013
}
10141014
desiredReplicas, reason, message := c.convertDesiredReplicasWithBehaviorRate(normalizationArg)
10151015
if desiredReplicas == stabilizedRecommendation {
1016-
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionFalse, reason, message)
1016+
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionFalse, reason, "%s", message)
10171017
} else {
1018-
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionTrue, reason, message)
1018+
setCondition(hpa, autoscalingv2.ScalingLimited, corev1.ConditionTrue, reason, "%s", message)
10191019
}
10201020

10211021
return desiredReplicas

pkg/karmadactl/cmdinit/kubernetes/statefulset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestCommandInitIOption_etcdVolume(t *testing.T) {
6363
t.Run(tt.name, func(t *testing.T) {
6464
_, got := tt.opt.etcdVolume()
6565
if (got == nil) != tt.claimIsNil {
66-
t.Errorf(tt.errorMsg)
66+
t.Error(tt.errorMsg)
6767
}
6868
})
6969
}

pkg/karmadactl/register/register.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,20 +846,20 @@ func (o *CommandRegisterOption) constructKubeConfig(bootstrapClient *kubeclient.
846846
if err != nil {
847847
return nil, err
848848
}
849-
klog.V(1).Infof(fmt.Sprintf("Waiting for the client certificate %s to be issued", csrName))
849+
klog.V(1).Infof("Waiting for the client certificate %s to be issued", csrName)
850850
err = wait.PollUntilContextTimeout(context.TODO(), 1*time.Second, o.Timeout, false, func(context.Context) (done bool, err error) {
851851
csrOK, err := bootstrapClient.CertificatesV1().CertificateSigningRequests().Get(context.TODO(), csrName, metav1.GetOptions{})
852852
if err != nil {
853853
return false, fmt.Errorf("failed to get the cluster csr %s. err: %v", csrName, err)
854854
}
855855

856856
if csrOK.Status.Certificate != nil {
857-
klog.V(1).Infof(fmt.Sprintf("Signing certificate of csr %s successfully", csrName))
857+
klog.V(1).Infof("Signing certificate of csr %s successfully", csrName)
858858
cert = csrOK.Status.Certificate
859859
return true, nil
860860
}
861861

862-
klog.V(1).Infof(fmt.Sprintf("Waiting for the client certificate of csr %s to be issued", csrName))
862+
klog.V(1).Infof("Waiting for the client certificate of csr %s to be issued", csrName)
863863
klog.V(1).Infof("Approve the CSR %s manually by executing `kubectl certificate approve %s` on the control plane\nOr enable the agentcsrapproving controller of karmada-controller-manager to automatically approve agent CSR.", csrName, csrName)
864864
return false, nil
865865
})

pkg/util/lifted/lua/string_safe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func strFind(L *lua.LState) int {
152152

153153
mds, err := pm.Find(pattern, unsafeFastStringToReadOnlyBytes(str), init, 1)
154154
if err != nil {
155-
L.RaiseError(err.Error())
155+
L.RaiseError("%s", err.Error())
156156
}
157157
if len(mds) == 0 {
158158
L.Push(lua.LNil)
@@ -231,7 +231,7 @@ func strGmatch(L *lua.LState) int {
231231
validateStrParamsLen(L, pattern)
232232
mds, err := pm.Find(pattern, []byte(str), 0, -1)
233233
if err != nil {
234-
L.RaiseError(err.Error())
234+
L.RaiseError("%s", err.Error())
235235
}
236236
L.Push(L.Get(lua.UpvalueIndex(1)))
237237
ud := L.NewUserData()
@@ -270,7 +270,7 @@ func strMatch(L *lua.LState) int {
270270

271271
mds, err := pm.Find(pattern, unsafeFastStringToReadOnlyBytes(str), offset, 1)
272272
if err != nil {
273-
L.RaiseError(err.Error())
273+
L.RaiseError("%s", err.Error())
274274
}
275275
if len(mds) == 0 {
276276
L.Push(lua.LNil)
@@ -382,7 +382,7 @@ func raiseErrorIfContextIsDone(L *lua.LState) {
382382

383383
select {
384384
case <-L.Context().Done():
385-
L.RaiseError(L.Context().Err().Error())
385+
L.RaiseError("%s", L.Context().Err().Error())
386386
default:
387387
}
388388
}

pkg/util/lifted/scheduler/cache/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ limitations under the License.
2121
package cache
2222

2323
import (
24+
"errors"
2425
"fmt"
2526
"sync"
2627
"time"
@@ -296,7 +297,7 @@ func (cache *cacheImpl) UpdateSnapshot(nodeSnapshot *Snapshot) error {
296297
// We will try to recover by re-creating the lists for the next scheduling cycle, but still return an
297298
// error to surface the problem, the error will likely cause a failure to the current scheduling cycle.
298299
cache.updateNodeInfoSnapshotList(nodeSnapshot, true)
299-
return fmt.Errorf(errMsg)
300+
return errors.New(errMsg)
300301
}
301302

302303
return nil

pkg/util/lifted/selectors/bimultimap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestAssociations(t *testing.T) {
235235
// Run consistency check after every operation.
236236
err := consistencyCheck(multimap)
237237
if err != nil {
238-
t.Fatalf(err.Error())
238+
t.Fatal(err.Error())
239239
}
240240
}
241241
for _, expect := range tc.want {
@@ -261,7 +261,7 @@ func TestEfficientAssociation(t *testing.T) {
261261

262262
err := forwardSelect(key("hpa-1"), key("pod-1"), key("pod-2"))(m)
263263
if err != nil {
264-
t.Errorf(err.Error())
264+
t.Error(err.Error())
265265
}
266266
}
267267

pkg/util/overridemanager/overridemanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func applyFieldOverriders(rawObj *unstructured.Unstructured, FieldOverriders []p
424424
}
425425
if kind != reflect.String {
426426
errMsg := fmt.Sprintf("Get object's value by overrider's path(%s) is not string", FieldOverriders[index].FieldPath)
427-
klog.Errorf(errMsg)
427+
klog.Error(errMsg)
428428
return errors.New(errMsg)
429429
}
430430
dataBytes := []byte(res.(string))

0 commit comments

Comments
 (0)