Skip to content

Commit d0c4f46

Browse files
fix linting errors
1 parent 0d9d4c1 commit d0c4f46

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

cns/restserver/internalapi.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMo
172172
service.Lock()
173173
defer service.Unlock()
174174
start := time.Now()
175-
176175
programmedNCCount, err := service.syncHostNCVersion(ctx, channelMode)
177176
// even if we get an error, we want to write the CNI conflist if we have any NC programmed to any version
178177
if programmedNCCount > 0 {
@@ -208,7 +207,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
208207
logger.Errorf("Received err when change nc version %s in containerstatus to int, err msg %v", service.state.ContainerStatus[idx].CreateNetworkContainerRequest.Version, err)
209208
continue
210209
}
211-
logger.Printf("NC %s: local NC version %d, DNC NC version %d", service.state.ContainerStatus[idx].ID, localNCVersion, dncNCVersion)
210+
212211
// host NC version is the NC version from NMAgent, if it's smaller than NC version from DNC, then append it to indicate it needs update.
213212
if localNCVersion < dncNCVersion {
214213
outdatedNCs[service.state.ContainerStatus[idx].ID] = struct{}{}
@@ -223,7 +222,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
223222
if len(outdatedNCs) == 0 {
224223
return len(programmedNCs), nil
225224
}
226-
logger.Printf("outdatedNCs: %v", outdatedNCs)
225+
227226
ncVersionListResp, err := service.nma.GetNCVersionList(ctx)
228227
if err != nil {
229228
return len(programmedNCs), errors.Wrap(err, "failed to get nc version list from nmagent")
@@ -232,7 +231,6 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
232231
// Get IMDS NC versions for delegated NIC scenarios
233232
imdsNCVersions, err := service.GetIMDSNCVersions(ctx)
234233
if err != nil {
235-
logger.Printf("Failed to get NC versions from IMDS: %v", err)
236234
// If any of the NMA API check calls, imds calls fails assume that nma build doesn't have the latest changes and create empty map
237235
imdsNCVersions = make(map[string]string)
238236
}
@@ -674,50 +672,35 @@ func (service *HTTPRestService) checkNMAgentAPISupport(ctx context.Context) (swi
674672
return false, fmt.Errorf("failed to get supported APIs from NMAgent client: %w", err)
675673
}
676674

677-
logger.Printf("[checkNMAgentAPISupport] Found %d APIs from NMAgent client", len(apis))
678-
for i, api := range apis {
679-
logger.Printf("[checkNMAgentAPISupport] API %d: %s", i+1, api)
680-
675+
for _, api := range apis {
681676
if strings.Contains(api, nmAgentSwiftV2API) { // change
682677
swiftV2Support = true
683678
}
684679
}
685680

686-
logger.Printf("[checkNMAgentAPISupport] Support check - SwiftV2: %t", swiftV2Support)
687681
return swiftV2Support, nil
688682
}
689683

690684
// GetIMDSNCVersions gets NC versions from IMDS and returns them as a map
691685
func (service *HTTPRestService) GetIMDSNCVersions(ctx context.Context) (map[string]string, error) {
692-
logger.Printf("[GetIMDSNCVersions] Getting NC versions from IMDS")
693-
694686
// Check NMAgent API support for SwiftV2, if it fails return empty map assuming support might not be available in that nma build
695687
swiftV2Support, err := service.checkNMAgentAPISupport(ctx)
696-
if err != nil {
697-
logger.Printf("[GetIMDSNCVersions] Failed to check NMAgent API support, returning empty map: %v", err)
688+
if err != nil || !swiftV2Support {
698689
return make(map[string]string), nil
699690
}
700691

701-
if !swiftV2Support {
702-
return make(map[string]string), nil
703-
}
704-
705-
logger.Printf("[GetIMDSNCVersions] SwiftV2 support API exists (%t), proceeding to get NC versions from IMDS", swiftV2Support)
706-
707692
imdsClient := service.imdsClient
708693

709694
// Get all NC versions from IMDS
710695
networkInterfaces, err := imdsClient.GetNCVersions(ctx)
711696
if err != nil {
712-
logger.Printf("[GetIMDSNCVersions] Failed to get NC versions from IMDS: %v", err)
713697
return make(map[string]string), nil
714698
}
715699

716700
// Build ncVersions map from the network interfaces
717701
ncVersions := make(map[string]string)
718702
for _, iface := range networkInterfaces {
719-
// IMDS only returns compartment fields (interfaceCompartmentId, interfaceCompartmentVersion)
720-
// We map these to NC ID and NC version concepts
703+
// IMDS returns interfaceCompartmentId, interfaceCompartmentVersion fields, as nc id guid has different context on nma. We map these to NC ID and NC version
721704
ncId := iface.InterfaceCompartmentId
722705
ncVersion := iface.InterfaceCompartmentVersion
723706

@@ -726,6 +709,5 @@ func (service *HTTPRestService) GetIMDSNCVersions(ctx context.Context) (map[stri
726709
}
727710
}
728711

729-
logger.Printf("[GetIMDSNCVersions] Successfully got %d NC versions from IMDS", len(ncVersions))
730712
return ncVersions, nil
731713
}

cns/restserver/internalapi_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ func TestSyncHostNCVersion(t *testing.T) {
272272

273273
// Create a custom IMDS mock that returns the second NC
274274
mockIMDS := &struct {
275-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
275+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
276276
}{
277-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
277+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
278278
return []imds.NetworkInterface{
279279
{
280280
InterfaceCompartmentId: imdsNCID,
@@ -372,9 +372,9 @@ func TestSyncHostNCVersionErrorMissingNC(t *testing.T) {
372372

373373
// Create IMDS mock that returns 1 NC but with different ID (not matching the outdated NC)
374374
mockIMDS := &struct {
375-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
375+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
376376
}{
377-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
377+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
378378
return []imds.NetworkInterface{
379379
{
380380
InterfaceCompartmentId: "different-nc-id",
@@ -434,9 +434,9 @@ func TestSyncHostNCVersionLocalVersionHigher(t *testing.T) {
434434

435435
// Create IMDS mock that returns lower version(2) than local host version(3)
436436
mockIMDS := &struct {
437-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
437+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
438438
}{
439-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
439+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
440440
return []imds.NetworkInterface{
441441
{
442442
InterfaceCompartmentId: req.NetworkContainerid,
@@ -492,9 +492,9 @@ func TestSyncHostNCVersionLocalHigherThanDNC(t *testing.T) {
492492
svc.Unlock()
493493

494494
mockIMDS := &struct {
495-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
495+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
496496
}{
497-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
497+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
498498
return []imds.NetworkInterface{}, nil
499499
},
500500
}
@@ -550,9 +550,9 @@ func TestSyncHostNCVersionNMAgentAPICallFailed(t *testing.T) {
550550

551551
// Create IMDS mock that returns empty, as nma api call failed
552552
mockIMDS := &struct {
553-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
553+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
554554
}{
555-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
555+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
556556
return []imds.NetworkInterface{}, nil
557557
},
558558
}
@@ -605,9 +605,9 @@ func TestSyncHostNCVersionSwiftV2APINotSupported(t *testing.T) {
605605

606606
// Create IMDS mock - this should not be called since SwiftV2 is not supported
607607
mockIMDS := &struct {
608-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
608+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
609609
}{
610-
ncVersions: func(ctx context.Context) ([]imds.NetworkInterface, error) {
610+
ncVersions: func(_ context.Context) ([]imds.NetworkInterface, error) {
611611
t.Errorf("IMDS should not be called when SwiftV2 API is not supported")
612612
return []imds.NetworkInterface{}, nil
613613
},
@@ -1780,7 +1780,7 @@ func TestMustEnsureNoStaleNCs_PanicsWhenIPsFromStaleNCAreAssigned(t *testing.T)
17801780
// mockIMDSAdapter adapts the anonymous struct to implement the imdsClient interface
17811781
type mockIMDSAdapter struct {
17821782
mock *struct {
1783-
ncVersions func(ctx context.Context) ([]imds.NetworkInterface, error)
1783+
ncVersions func(_ context.Context) ([]imds.NetworkInterface, error)
17841784
}
17851785
}
17861786

cns/service/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ func InitializeMultiTenantController(ctx context.Context, httpRestService cns.HT
12821282
}
12831283

12841284
// TODO: do we need this to be running?
1285+
logger.Printf("Starting SyncHostNCVersion")
12851286
go func() {
12861287
// Periodically poll vfp programmed NC version from NMAgent
12871288
tickerChannel := time.Tick(time.Duration(cnsconfig.SyncHostNCVersionIntervalMs) * time.Millisecond)
@@ -1641,6 +1642,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
16411642
}
16421643

16431644
go func() {
1645+
logger.Printf("Starting SyncHostNCVersion loop.")
16441646
// Periodically poll vfp programmed NC version from NMAgent
16451647
tickerChannel := time.Tick(time.Duration(cnsconfig.SyncHostNCVersionIntervalMs) * time.Millisecond)
16461648
for {

0 commit comments

Comments
 (0)