Skip to content

Conversation

@csfmomo
Copy link
Contributor

@csfmomo csfmomo commented Oct 14, 2020

*Add pending program status for IPs in CNS.
*Add logic structure of how to update program status.

feat:
Add logic structure for CNS udpate NC secondary IP to pending program before available

Reason for Change:
Pending program is a status to track that IP is available in NC but not in NMAgent side yet. IP is available when NMAgent is also ready.

Issue Fixed:
Prevent CNS allocate pending program IP to pod.

Add logic structure of how to update program status.
@matmerr
Copy link
Member

matmerr commented Oct 14, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@csfmomo
Copy link
Contributor Author

csfmomo commented Oct 14, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@codecov
Copy link

codecov bot commented Oct 14, 2020

Codecov Report

Merging #690 into master will decrease coverage by 0.06%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master     #690      +/-   ##
==========================================
- Coverage   38.60%   38.54%   -0.07%     
==========================================
  Files          78       79       +1     
  Lines       10433    10471      +38     
==========================================
+ Hits         4028     4036       +8     
- Misses       5913     5943      +30     
  Partials      492      492              

@csfmomo
Copy link
Contributor Author

csfmomo commented Oct 15, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

ncRequest.NetworkContainerid = nc.ID
ncRequest.NetworkContainerType = cns.Docker
ncRequest.Version = nc.Version
ncRequest.NCVersion = nc.Version
Copy link
Member

Choose a reason for hiding this comment

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

Why is this changed? It should be set to ncRequest.Version only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change it back to ncRequest.Version.
I didn't reuse the Version since the usage of Version is not clear in CNS previously. There are Version, which compared with VMVersion and HostVersion which record NMA version. After double checking code, resusing Version should be fine.

func (service *HTTPRestService) addIPConfigStateUntransacted(ncVersion, ncId string, ipconfigs map[string]cns.SecondaryIPConfig) {

existingNCStatus, _ := service.state.ContainerStatus[ncId]
existingNCVersion, _ := strconv.Atoi(existingNCStatus.CreateNetworkContainerRequest.NCVersion)
Copy link
Member

Choose a reason for hiding this comment

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

This wont return the expected value, NCRequest is already overwritten in the caller API (saveNetworkContainerGoalState, line 120). You need to pass existing Version (not NCVersion) from the called like we are passing existingIpconfigs

Copy link
Contributor Author

@csfmomo csfmomo Oct 15, 2020

Choose a reason for hiding this comment

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

Will update.
I think we should not overwritten existing NC status unless CNS finish all the updating works in this call. Imagine if call crash in the middle, update is not finished but existing NC status got overwritten. Another plus is we don't need to create new object to carry existing NC status temporarily. I can follow the previous style for now but thinking open another PR which do all the works needed before updating existing NC status.


existingNCStatus, _ := service.state.ContainerStatus[ncId]
existingNCVersion, _ := strconv.Atoi(existingNCStatus.CreateNetworkContainerRequest.NCVersion)
nmAgentNCVersion := getNCVersionFromNMAgent(ncId)
Copy link
Member

Choose a reason for hiding this comment

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

I actually recommend to move it to background or make a call in a go routing and wait for it.

Copy link
Member

Choose a reason for hiding this comment

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

Actually we SHOULD not make an outbound call while acquiring a lock to the Service. it must be outside the lock

Copy link
Contributor Author

@csfmomo csfmomo Oct 15, 2020

Choose a reason for hiding this comment

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

Let's keep it as it for this PR since getNCVersionFromNMAgent didn't have any logic now. This PR is a structure and I'll fill in logic in next PR. It can be a background thread or separate go routine.
No matter whether we query NMAgent in background or not, we should compare NMAgent's version every time when NC is updated. I don't think NC update will be too frequent to bug NMAgent.

}
func (service *HTTPRestService) addIPConfigStateUntransacted(ncVersion, ncId string, ipconfigs map[string]cns.SecondaryIPConfig) {

existingNCStatus, _ := service.state.ContainerStatus[ncId]
Copy link
Member

Choose a reason for hiding this comment

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

Again this is already updated in the caller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will update.

}

// To do, complete this logic according to getNetworkContainerStatus
func getNCVersionFromNMAgent(ncid string) int {
Copy link
Member

Choose a reason for hiding this comment

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

Please add the logic to get NMAgent ver in ImdsClientInterface

Copy link
Contributor Author

@csfmomo csfmomo Oct 15, 2020

Choose a reason for hiding this comment

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

getNetworkContainerStatus is using imdsClient.GetNetworkContainerInfoFromHost. I think GetNetworkContainerInfoFromHost covers most of this logic. I can double check. Will update there.

if _, exists := service.PodIPConfigState[ipId]; exists {
continue
}
func (service *HTTPRestService) addIPConfigStateUntransacted(ncVersion, ncId string, ipconfigs map[string]cns.SecondaryIPConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

I think in this function you also need to pass existingIpconfigs so that you can keep those IPs as available and mark the new ones in PendingProgramming State

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, existingSecondaryIPConfigs is needed.

Available = "Available"
Allocated = "Allocated"
PendingRelease = "PendingRelease"
PendingProgram = "PendingProgram"
Copy link
Member

Choose a reason for hiding this comment

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

can we rename it to PendingProgramming

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.


// Add the newIpConfigs, ignore if ip state is already in the map
service.addIPConfigStateUntransacted(req.NetworkContainerid, newIPConfigs)
service.addIPConfigStateUntransacted(req.NCVersion, req.NetworkContainerid, newIPConfigs)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some logs to updateIpConfigsStateUntransacted function, it is missing logs overall. Specially when we are updating the state or if this api is returning error

Copy link
Contributor Author

@csfmomo csfmomo Oct 15, 2020

Choose a reason for hiding this comment

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


existingNCStatus, _ := service.state.ContainerStatus[ncId]
existingNCVersion, _ := strconv.Atoi(existingNCStatus.CreateNetworkContainerRequest.NCVersion)
nmAgentNCVersion := getNCVersionFromNMAgent(ncId)
Copy link
Member

Choose a reason for hiding this comment

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

Actually we SHOULD not make an outbound call while acquiring a lock to the Service. it must be outside the lock

if nmAgentNCVersion >= existingNCVersion {
service.addIPConfigStateUntransacted(cns.Available, cns.PendingProgramming, req.NetworkContainerid, newIPConfigs)
} else {
service.addIPConfigStateUntransacted(cns.PendingProgramming, cns.PendingProgramming, req.NetworkContainerid, newIPConfigs)
Copy link
Member

Choose a reason for hiding this comment

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

Why we need to move existing IPs back to PendingState if they are already available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. We are NOT make an outboud call. getNCVersionFromNMAgent didn't have implementation yet. It could be the function which fetch NMAgent version locally from what background thread got and saved.
  2. We not not moving existing IPs back to Pending State.

Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

Left one minor comment.

// GetNMagentVersion - Mock implementation to return host NMAgent NC version
// Set it as 0 which is the same as default initial NC version for testing purpose
func (imdsClient *ImdsClientTest) GetNMagentVersion() int {
logger.Printf("[Azure CNS] GetNMagentVersionFromNMAgent")
Copy link
Member

Choose a reason for hiding this comment

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

Update the log to get the NC version from NMAgent

GetNetworkContainerInfoFromHost(networkContainerID string, primaryAddress string, authToken string, apiVersion string) (*ContainerVersion, error)
GetPrimaryInterfaceInfoFromHost() (*InterfaceInfo, error)
GetPrimaryInterfaceInfoFromMemory() (*InterfaceInfo, error)
GetNMagentVersion() int
Copy link
Member

Choose a reason for hiding this comment

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

Rename the function name GetNetworkContainerInfoFromHost and pass all the parameters networkContainerID string, primaryAddress string, apiVersion string)

@csfmomo csfmomo merged commit ce35cd2 into Azure:master Oct 22, 2020
@csfmomo csfmomo deleted the programmedIp branch October 23, 2020 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants