Skip to content

Conversation

@matmerr
Copy link
Member

@matmerr matmerr commented Jun 17, 2020

What this PR does / why we need it:

Adds two new API's in CNS which will enable it to act as an IPAM.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

Release note:

@codecov
Copy link

codecov bot commented Jun 19, 2020

Codecov Report

Merging #584 into master will decrease coverage by 2.57%.
The diff coverage is 23.61%.

@@            Coverage Diff             @@
##           master     #584      +/-   ##
==========================================
- Coverage   39.88%   37.30%   -2.58%     
==========================================
  Files          42       47       +5     
  Lines        4586     5203     +617     
==========================================
+ Hits         1829     1941     +112     
- Misses       2502     3000     +498     
- Partials      255      262       +7     

@matmerr matmerr added enhancement cni Related to CNI. cns Related to CNS. and removed work-in-progress labels Jun 25, 2020
@matmerr matmerr requested a review from neaggarwMS June 25, 2020 18:16
@matmerr matmerr force-pushed the cnsipamcni branch 2 times, most recently from 260fc97 to 5c56f56 Compare July 9, 2020 16:54
@matmerr matmerr requested a review from tamilmani1989 July 9, 2020 23:09
Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

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

minor comments. One concern is that changed introduced in getnetworkcontainerrequest struct should not regress multitenancy scenario.


// If IPConfig is already allocated for pod, it returns that else it returns one of the available ipconfigs.
func requestIPConfigHelper(service *HTTPRestService, req cns.GetNetworkContainerRequest) (*cns.ContainerIPConfigState, error) {
func requestIPConfigHelper(service *HTTPRestService, req cns.GetIPConfigRequest) (*cns.ContainerIPConfigState, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this method, we check for an existing ipConfig, when would there already exist an ipConfig for the particular pod?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the pod dies and is restarted, or if the node reboots and all pods are restarted

// If IPConfig is already allocated for pod, it returns that else it returns one of the available ipconfigs.
func requestIPConfigHelper(service *HTTPRestService, req cns.GetNetworkContainerRequest) (*cns.ContainerIPConfigState, error) {
func requestIPConfigHelper(service *HTTPRestService, req cns.GetIPConfigRequest) (*cns.ContainerIPConfigState, error) {
var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Later on in this method, it checks that the ipconfig already exists for the pod, and returns the ipstate if err!= nil || isExist. Wouldn't we want to return the ipstate if err == nil && isExist?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, inside the implementation of "GetExistingIPConfig", the "err" var goes unused basically, the only time it is used is to return nil, so maybe switch that last return to return nil like you did inside the if statement and get rid of the err var.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing in "GetExistingIPConfig", the returned error message is "Pod->IPIP exists..." but I think you meant "Pod->IPID exists..."

Copy link
Member Author

Choose a reason for hiding this comment

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

Later on in this method, it checks that the ipconfig already exists for the pod, and returns the ipstate if err!= nil || isExist. Wouldn't we want to return the ipstate if err == nil && isExist?

good catch, fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, inside the implementation of "GetExistingIPConfig", the "err" var goes unused basically, the only time it is used is to return nil, so maybe switch that last return to return nil like you did inside the if statement and get rid of the err var.

true, reused skeleton, fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another thing in "GetExistingIPConfig", the returned error message is "Pod->IPIP exists..." but I think you meant "Pod->IPID exists..."

Updated the comment

Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

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

couple of nits..rest lgtm

plugin.report.ContainerName = k8sPodName + ":" + k8sNamespace

if nwCfg.MultiTenancy {
if nwCfg.MultiTenancy || nwCfg.Ipam.Type == azureCNSIPAM {
Copy link
Member

Choose a reason for hiding this comment

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

we should refactor CNI to implement interfaces and and have specific implementation according to the scenario. Not required to do in this change only, but we should take care of as it will get difficult to parse the code with more scenarios coming in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes CNI work is being done in a separate PR to do just that

return plugin.Errorf(err.Error())
}

result, resultV6, err = cnsClient.RequestIPAddress(orchestratorContext)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldnt this be part of plugin.IpamAdd call?

if ipState, isExist = service.PodIPConfigState[ipID]; isExist {
return ipState, isExist, nil
}
return ipState, isExist, fmt.Errorf("Pod->IPIP exists but IPID to IPConfig doesn't exist")
Copy link
Member

Choose a reason for hiding this comment

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

This means our CNS state is corrupted right? We should log this error into kusto and raise alert to see if we ever reach this state. Can be handled in a separate PR though

@matmerr matmerr requested a review from tamilmani1989 July 13, 2020 22:54
Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

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

lgtm

@matmerr matmerr merged commit 644642b into Azure:master Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cns Related to CNS. enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants