Skip to content

Commit 8e11f4b

Browse files
committed
feat: Fix string formats causing PR pipeline to fail
1 parent 86dfc35 commit 8e11f4b

File tree

13 files changed

+54
-54
lines changed

13 files changed

+54
-54
lines changed

aitelemetry/telemetrywrapper_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func handleGetCloud(w http.ResponseWriter, req *http.Request) {
8787
w.Write([]byte(getCloudResponse))
8888
}
8989

90-
func initTelemetry(t *testing.T) (TelemetryHandle, TelemetryHandle) {
90+
func initTelemetry() (TelemetryHandle, TelemetryHandle) {
9191
th1, err1 := NewAITelemetry(httpURL, "00ca2a73-c8d6-4929-a0c2-cf84545ec225", aiConfig)
9292
if err1 != nil {
9393
fmt.Printf("Error initializing AI telemetry: %v", err1)
@@ -118,7 +118,7 @@ func TestEmptyAIKey(t *testing.T) {
118118
func TestNewAITelemetry(t *testing.T) {
119119
var err error
120120

121-
th1, th2 := initTelemetry(t)
121+
th1, th2 := initTelemetry()
122122
if th1 == nil {
123123
t.Errorf("Error initializing AI telemetry: %v", err)
124124
}
@@ -129,7 +129,7 @@ func TestNewAITelemetry(t *testing.T) {
129129
}
130130

131131
func TestTrackMetric(t *testing.T) {
132-
th1, th2 := initTelemetry(t)
132+
th1, th2 := initTelemetry()
133133

134134
metric := Metric{
135135
Name: "test",
@@ -143,7 +143,7 @@ func TestTrackMetric(t *testing.T) {
143143
}
144144

145145
func TestTrackLog(t *testing.T) {
146-
th1, th2 := initTelemetry(t)
146+
th1, th2 := initTelemetry()
147147

148148
report := Report{
149149
Message: "test",
@@ -157,7 +157,7 @@ func TestTrackLog(t *testing.T) {
157157
}
158158

159159
func TestTrackEvent(t *testing.T) {
160-
th1, th2 := initTelemetry(t)
160+
th1, th2 := initTelemetry()
161161

162162
event := Event{
163163
EventName: "testEvent",
@@ -172,14 +172,14 @@ func TestTrackEvent(t *testing.T) {
172172
}
173173

174174
func TestFlush(t *testing.T) {
175-
th1, th2 := initTelemetry(t)
175+
th1, th2 := initTelemetry()
176176

177177
th1.Flush()
178178
th2.Flush()
179179
}
180180

181181
func TestClose(t *testing.T) {
182-
th1, th2 := initTelemetry(t)
182+
th1, th2 := initTelemetry()
183183

184184
th1.Close(10)
185185
th2.Close(10)

cni/network/network.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ func (plugin *NetPlugin) getPodInfo(args string) (name, ns string, err error) {
281281
if len(k8sNamespace) == 0 {
282282
errMsg := "Pod Namespace not specified in CNI Args"
283283
logger.Error(errMsg)
284-
return "", "", plugin.Errorf(errMsg)
284+
return "", "", plugin.Errorf("%s", errMsg)
285285
}
286286

287287
k8sPodName := string(podCfg.K8S_POD_NAME)
288288
if len(k8sPodName) == 0 {
289289
errMsg := "Pod Name not specified in CNI Args"
290290
logger.Error(errMsg)
291-
return "", "", plugin.Errorf(errMsg)
291+
return "", "", plugin.Errorf("%s", errMsg)
292292
}
293293

294294
return k8sPodName, k8sNamespace, nil
@@ -450,14 +450,14 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
450450
if len(k8sContainerID) == 0 {
451451
errMsg := "Container ID not specified in CNI Args"
452452
logger.Error(errMsg)
453-
return plugin.Errorf(errMsg)
453+
return plugin.Errorf("%s", errMsg)
454454
}
455455

456456
k8sIfName := args.IfName
457457
if len(k8sIfName) == 0 {
458458
errMsg := "Interfacename not specified in CNI Args"
459459
logger.Error(errMsg)
460-
return plugin.Errorf(errMsg)
460+
return plugin.Errorf("%s", errMsg)
461461
}
462462

463463
platformInit(nwCfg)
@@ -520,7 +520,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
520520
errMsg := fmt.Sprintf("received multiple NC results %+v from CNS while dualnic feature is not supported", ipamAddResult.interfaceInfo)
521521
logger.Error("received multiple NC results from CNS while dualnic feature is not supported",
522522
zap.Any("results", ipamAddResult.interfaceInfo))
523-
return plugin.Errorf(errMsg)
523+
return plugin.Errorf("%s", errMsg)
524524
}
525525
} else {
526526
// when nwcfg.multitenancy (use multitenancy flag for swift v1 only) is false
@@ -790,7 +790,7 @@ func (plugin *NetPlugin) createEpInfo(opt *createEpInfoOpt) (*network.EndpointIn
790790
epPolicies, err := getPoliciesFromRuntimeCfg(opt.nwCfg, opt.ipamAddResult.ipv6Enabled) // not specific to delegated or infra
791791
if err != nil {
792792
logger.Error("failed to get policies from runtime configurations", zap.Error(err))
793-
return nil, plugin.Errorf(err.Error())
793+
return nil, plugin.Errorf("%s", err.Error())
794794
}
795795
endpointInfo.EndpointPolicies = append(endpointInfo.EndpointPolicies, epPolicies...)
796796

@@ -1228,14 +1228,14 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
12281228
if len(k8sNamespace) == 0 {
12291229
errMsg := "Required parameter Pod Namespace not specified in CNI Args during UPDATE"
12301230
logger.Error(errMsg)
1231-
return plugin.Errorf(errMsg)
1231+
return plugin.Errorf("%s", errMsg)
12321232
}
12331233

12341234
k8sPodName := string(podCfg.K8S_POD_NAME)
12351235
if len(k8sPodName) == 0 {
12361236
errMsg := "Required parameter Pod Name not specified in CNI Args during UPDATE"
12371237
logger.Error(errMsg)
1238-
return plugin.Errorf(errMsg)
1238+
return plugin.Errorf("%s", errMsg)
12391239
}
12401240

12411241
// Initialize values from network config.
@@ -1245,7 +1245,7 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
12451245
if _, err = plugin.nm.GetNetworkInfo(networkID); err != nil {
12461246
errMsg := fmt.Sprintf("Failed to query network during CNI UPDATE: %v", err)
12471247
logger.Error(errMsg)
1248-
return plugin.Errorf(errMsg)
1248+
return plugin.Errorf("%s", errMsg)
12491249
}
12501250

12511251
// Query the existing endpoint since this is an update.
@@ -1272,21 +1272,21 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
12721272
if orchestratorContext, err = json.Marshal(podInfo); err != nil {
12731273
logger.Error("Marshalling KubernetesPodInfo failed",
12741274
zap.Error(err))
1275-
return plugin.Errorf(err.Error())
1275+
return plugin.Errorf("%s", err.Error())
12761276
}
12771277

12781278
cnsclient, err := cnscli.New(nwCfg.CNSUrl, defaultRequestTimeout)
12791279
if err != nil {
12801280
logger.Error("failed to initialized cns client",
12811281
zap.String("url", nwCfg.CNSUrl),
12821282
zap.String("error", err.Error()))
1283-
return plugin.Errorf(err.Error())
1283+
return plugin.Errorf("%s", err.Error())
12841284
}
12851285

12861286
if targetNetworkConfig, err = cnsclient.GetNetworkContainer(context.TODO(), orchestratorContext); err != nil {
12871287
logger.Info("GetNetworkContainer failed",
12881288
zap.Error(err))
1289-
return plugin.Errorf(err.Error())
1289+
return plugin.Errorf("%s", err.Error())
12901290
}
12911291

12921292
logger.Info("Network config received from cns",

cns/service/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ func main() {
10201020

10211021
var localServerURL string
10221022
if config.Server.Port != "" {
1023-
localServerURL = fmt.Sprintf(defaultLocalServerIP + ":" + config.Server.Port)
1023+
localServerURL = fmt.Sprintf("%s", defaultLocalServerIP+":"+config.Server.Port)
10241024
} else {
10251025
localServerURL = fmt.Sprintf(defaultLocalServerIP + ":" + defaultLocalServerPort)
10261026
}

npm/ipsm/ipsm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (ipsMgr *IpsetManager) run(entry *ipsEntry) (int, error) {
215215
errfmt := fmt.Errorf("error running command: [%s %v] Stderr: [%w, %s]",
216216
cmdName, strings.Join(cmdArgs, " "), err, strings.TrimSuffix(string(output), "\n"))
217217
if exitCode > 0 {
218-
metrics.SendErrorLogAndMetric(util.IpsmID, errfmt.Error())
218+
metrics.SendErrorLogAndMetric(util.IpsmID, "%s", errfmt.Error())
219219
}
220220

221221
return exitCode, errfmt

npm/ipsm/ipsm_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,26 +547,26 @@ func TestDestroyNpmIpsets(t *testing.T) {
547547
err := ipsMgr.CreateSetNoLock(testSet1Name, []string{"nethash"})
548548
if err != nil {
549549
t.Errorf("TestDestroyNpmIpsets failed @ ipsMgr.createSet")
550-
t.Errorf(err.Error())
550+
t.Errorf("%s", err.Error())
551551
}
552552

553553
err = ipsMgr.CreateSetNoLock(testSet2Name, []string{"nethash"})
554554
if err != nil {
555555
t.Errorf("TestDestroyNpmIpsets failed @ ipsMgr.createSet")
556-
t.Errorf(err.Error())
556+
t.Errorf("%s", err.Error())
557557
}
558558

559559
// expect prometheus to add this entry, but remove it when destroying npm sets
560560
err = ipsMgr.AddToSet(testSet1Name, "1.2.3.4", util.IpsetNetHashFlag, "")
561561
if err != nil {
562562
t.Errorf("TestDestroyNpmIpsets failed @ ipsMgr.addToSet")
563-
t.Errorf(err.Error())
563+
t.Errorf("%s", err.Error())
564564
}
565565

566566
err = ipsMgr.DestroyNpmIpsets()
567567
if err != nil {
568568
t.Errorf("TestDestroyNpmIpsets failed @ ipsMgr.DestroyNpmIpsets")
569-
t.Errorf(err.Error())
569+
t.Errorf("%s", err.Error())
570570
}
571571
}
572572

npm/iptm/iptm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (iptMgr *IptablesManager) addAllRulesToChains() error {
362362
msg = "Error: failed to add main chains with invalid rule length"
363363
}
364364

365-
metrics.SendErrorLogAndMetric(util.IptmID, msg)
365+
metrics.SendErrorLogAndMetric(util.IptmID, "%s", msg)
366366
return err
367367
}
368368
}

npm/metrics/ai-utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func SendLog(operationID int, msg string, printLog bool) {
106106
CustomDimensions: make(map[string]string),
107107
}
108108
if printLog {
109-
klog.Infof(msg)
109+
klog.Infof("%s", msg)
110110
}
111111
if th == nil {
112112
return

npm/pkg/dataplane/dataplane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func (dp *DataPlane) addPolicies(netPols []*policies.NPMNetworkPolicy) error {
508508
// this should never happen because bootup phase is for windows, but just in case, we don't want to applyDataplaneNow() or else there will be a deadlock on dp.applyInfo
509509
msg := fmt.Sprintf("[DataPlane] [%s] at risk of improperly applying a policy which is removed then readded", contextAddNetPolPrecaution)
510510
klog.Warning(msg)
511-
metrics.SendErrorLogAndMetric(util.DaemonDataplaneID, msg)
511+
metrics.SendErrorLogAndMetric(util.DaemonDataplaneID, "%s", msg)
512512
} else {
513513
// prevent #2977
514514
if err := dp.applyDataPlaneNow(contextAddNetPolPrecaution); err != nil {

npm/pkg/dataplane/debug/converter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestGetSetType(t *testing.T) {
179179
actualType := c.getSetType(test.inputSetName, test.inputMapName)
180180
diff := cmp.Diff(test.expected, actualType)
181181
if diff != "" {
182-
t.Fatalf(diff)
182+
t.Fatalf("%s", diff)
183183
}
184184
})
185185
}

npm/pkg/dataplane/ipsets/dirtycache.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import (
1010
)
1111

1212
/*
13-
dirtyCacheInterface will maintain the dirty cache.
14-
It may maintain membersToAdd and membersToDelete.
15-
Members are either IPs, CIDRs, IP-Port pairs, or prefixed set names if the parent is a list.
16-
17-
Assumptions:
18-
- if the set becomes dirty via update or destroy, then the set WAS in the kernel before
19-
- if the set becomes dirty via create, then the set was NOT in the kernel before
20-
21-
Usage:
22-
- create, addMember, deleteMember, and destroy are idempotent
23-
- create should not be called if the set becomes dirty via add/delete or the set is removed from the deleteCache via add/update
24-
- deleteMember should not be called if the set is in the deleteCache
25-
- deleteMember is safe to call on members in the kernel and members added via addMember
26-
- deleteMember is also safe to call on members not in the kernel if the set isn't in the kernel yet (became dirty via create)
27-
28-
Examples of Expected Behavior:
29-
- if a set is created and then destroyed, that set will not be in the dirty cache anymore
30-
- if a set is updated and then destroyed, that set will be in the delete cache
31-
- if the only operations on a set are adding and removing the same member, the set may still be in the dirty cache, but the member will be untracked
13+
dirtyCacheInterface will maintain the dirty cache.
14+
It may maintain membersToAdd and membersToDelete.
15+
Members are either IPs, CIDRs, IP-Port pairs, or prefixed set names if the parent is a list.
16+
17+
Assumptions:
18+
- if the set becomes dirty via update or destroy, then the set WAS in the kernel before
19+
- if the set becomes dirty via create, then the set was NOT in the kernel before
20+
21+
Usage:
22+
- create, addMember, deleteMember, and destroy are idempotent
23+
- create should not be called if the set becomes dirty via add/delete or the set is removed from the deleteCache via add/update
24+
- deleteMember should not be called if the set is in the deleteCache
25+
- deleteMember is safe to call on members in the kernel and members added via addMember
26+
- deleteMember is also safe to call on members not in the kernel if the set isn't in the kernel yet (became dirty via create)
27+
28+
Examples of Expected Behavior:
29+
- if a set is created and then destroyed, that set will not be in the dirty cache anymore
30+
- if a set is updated and then destroyed, that set will be in the delete cache
31+
- if the only operations on a set are adding and removing the same member, the set may still be in the dirty cache, but the member will be untracked
3232
*/
3333
type dirtyCacheInterface interface {
3434
// reset empties dirty cache
@@ -96,7 +96,7 @@ func (dc *dirtyCache) create(set *IPSet) {
9696
if _, ok := dc.toUpdateCache[set.Name]; ok {
9797
msg := fmt.Sprintf("create should not be called for set %s since it's in the toUpdateCache", set.Name)
9898
klog.Warning(msg)
99-
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
99+
metrics.SendErrorLogAndMetric(util.IpsmID, "%s", msg)
100100
return
101101
}
102102

@@ -136,7 +136,7 @@ func (dc *dirtyCache) deleteMember(set *IPSet, member string) {
136136
if dc.isSetToDelete(set.Name) {
137137
msg := fmt.Sprintf("attempting to delete member %s for set %s in the toDestroyCache", member, set.Name)
138138
klog.Warning(msg)
139-
metrics.SendErrorLogAndMetric(util.IpsmID, msg)
139+
metrics.SendErrorLogAndMetric(util.IpsmID, "%s", msg)
140140
return
141141
}
142142
if diff, ok := dc.toCreateCache[set.Name]; ok {

0 commit comments

Comments
 (0)