Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3426829
cns ipam
matmerr Jun 17, 2020
0f5dc91
cnsclient requestipaddress in cni
matmerr Jun 18, 2020
69a5c34
cnsclient release
matmerr Jun 18, 2020
f90fea2
state update, tbd
matmerr Jun 19, 2020
3b3649b
add windows specific vendor
matmerr Jun 19, 2020
e8d0ce3
update windows e2e's
matmerr Jun 20, 2020
b8f10f6
further refactoring
matmerr Jun 24, 2020
638c4ac
cnsclient integration tests
matmerr Jun 25, 2020
20c51fd
cns release integration test
matmerr Jun 25, 2020
c982f4c
fix nested lock
matmerr Jun 25, 2020
a475c7c
Merge remote-tracking branch 'upstream/master' into cnsipamcni
matmerr Jun 25, 2020
c0c47ba
Simply issue template
Jun 10, 2020
c766a57
Use issue template builder
Jun 17, 2020
069c596
Small improvements
Jun 17, 2020
931abab
template revision
matmerr Jun 25, 2020
da39b2a
Merge pull request #13 from matmerr/githubtemplates
matmerr Jun 25, 2020
0c7f746
move cnsclient to ipamdelegate calls
matmerr Jun 29, 2020
33ef3f8
remove cni changes
matmerr Jun 29, 2020
1a10ffa
addressed feedback
matmerr Jul 1, 2020
0b46c1f
add pending release state
matmerr Jul 1, 2020
21b2ae0
address feedback
matmerr Jul 8, 2020
35bda47
fix tests
matmerr Jul 9, 2020
4ec459c
update comments
matmerr Jul 9, 2020
125485f
ipam refactor with clearer locking
matmerr Jul 9, 2020
1b42027
fix nits
matmerr Jul 10, 2020
c8bd6c4
Merge branch 'master' into cnsipamcni
matmerr Jul 10, 2020
0f3863e
Merge remote-tracking branch 'upstream/master' into cnsipamcni
matmerr Jul 10, 2020
af41c5a
Merge branch 'master' into cnsipamcni
matmerr Jul 10, 2020
dbcb17c
add separate structs for new apis
matmerr Jul 10, 2020
e2622e8
update tests based on feedback
matmerr Jul 13, 2020
69ad3aa
remove nested lock on fail and address comments
matmerr Jul 13, 2020
61fa082
address feedback and add validation
matmerr Jul 13, 2020
1fd805c
update test
matmerr Jul 13, 2020
e965d7d
rename api's for allocation, nits, readlock for get api's
matmerr Jul 13, 2020
fe791f8
make release idempotent, and add tests
matmerr Jul 13, 2020
0556409
update getNetworkContainerResponse to take RLock
matmerr Jul 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: 'Feature Request'

about: Suggest an idea for this project.

---
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,13 @@ test-all:
./cnm/network/ \
./cni/ipam/ \
./cns/ipamclient/ \
./cns/cnsclient/ \
./cns/requestcontroller/kubecontroller/ \
./cnms/service/ \
./npm/iptm/ \
./npm/ipsm/

#until the restserver tests are fixed...
go test -timeout 30s \
./cns/restserver -run ^TestIPAM*

10 changes: 5 additions & 5 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,11 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
Gateway: gateway,
},
},
BridgeName: nwCfg.Bridge,
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
DNS: nwDNSInfo,
Policies: policies,
NetNs: args.Netns,
BridgeName: nwCfg.Bridge,
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
DNS: nwDNSInfo,
Policies: policies,
NetNs: args.Netns,
DisableHairpinOnHostInterface: nwCfg.DisableHairpinOnHostInterface,
IPV6Mode: nwCfg.IPV6Mode,
ServiceCidrs: nwCfg.ServiceCidrs,
Expand Down
37 changes: 37 additions & 0 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
GetNetworkContainerByOrchestratorContext = "/network/getnetworkcontainerbyorchestratorcontext"
AttachContainerToNetwork = "/network/attachcontainertonetwork"
DetachContainerFromNetwork = "/network/detachcontainerfromnetwork"
RequestIPConfig = "/network/requestipconfig"
ReleaseIPConfig = "/network/releaseipconfig"
)

// NetworkContainer Prefixes
Expand Down Expand Up @@ -50,6 +52,13 @@ const (
Vxlan = "Vxlan"
)

// IPConfig States for CNS IPAM
const (
Available = "Available"
Allocated = "Allocated"
PendingRelease = "PendingRelease"
)

// CreateNetworkContainerRequest specifies request to create a network container or network isolation boundary.
type CreateNetworkContainerRequest struct {
Version string
Expand Down Expand Up @@ -87,6 +96,11 @@ type KubernetesPodInfo struct {
PodNamespace string
}

// GetOrchestratorContext will return the orchestratorcontext as a string
func (podinfo *KubernetesPodInfo) GetOrchestratorContextKey() string {
return podinfo.PodName + ":" + podinfo.PodNamespace
}

// MultiTenancyInfo contains encap type and id.
type MultiTenancyInfo struct {
EncapType string
Expand All @@ -100,6 +114,19 @@ type IPConfiguration struct {
GatewayIPAddress string
}

type SecondaryIPConfig struct {
UUID string
IPConfig IPSubnet
}

type ContainerIPConfigState struct {
IPConfig IPSubnet
ID string //uuid
NCID string
State string
OrchestratorContext json.RawMessage
}

// IPSubnet contains ip subnet.
type IPSubnet struct {
IPAddress string
Expand Down Expand Up @@ -158,6 +185,16 @@ type GetNetworkContainerResponse struct {
AllowNCToHostCommunication bool
}

type GetIPConfigRequest struct {
DesiredIPConfig IPSubnet
OrchestratorContext json.RawMessage
}

type GetIPConfigResponse struct {
IPConfiguration IPConfiguration
Response Response
}

// DeleteNetworkContainerRequest specifies the details about the request to delete a specifc network container.
type DeleteNetworkContainerRequest struct {
NetworkContainerid string
Expand Down
121 changes: 115 additions & 6 deletions cns/cnsclient/cnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type CNSClient struct {
}

const (
defaultCnsURL = "http://localhost:10090"
defaultCnsURL = "http://localhost:10090"
contentTypeJSON = "application/json"
)

var (
Expand Down Expand Up @@ -67,7 +68,7 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte)
return nil, err
}

res, err := httpc.Post(url, "application/json", &body)
res, err := httpc.Post(url, contentTypeJSON, &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return nil, err
Expand Down Expand Up @@ -98,8 +99,7 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte)
}

// CreateHostNCApipaEndpoint creates an endpoint in APIPA network for host container connectivity.
func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(
networkContainerID string) (string, error) {
func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(networkContainerID string) (string, error) {
var (
err error
body bytes.Buffer
Expand All @@ -118,7 +118,7 @@ func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(
return "", err
}

res, err := httpc.Post(url, "application/json", &body)
res, err := httpc.Post(url, contentTypeJSON, &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return "", err
Expand Down Expand Up @@ -167,7 +167,7 @@ func (cnsClient *CNSClient) DeleteHostNCApipaEndpoint(networkContainerID string)
return err
}

res, err := httpc.Post(url, "application/json", &body)
res, err := httpc.Post(url, contentTypeJSON, &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return err
Expand Down Expand Up @@ -198,3 +198,112 @@ func (cnsClient *CNSClient) DeleteHostNCApipaEndpoint(networkContainerID string)

return nil
}

// RequestIPAddress calls the requestIPAddress in CNS
func (cnsClient *CNSClient) RequestIPAddress(orchestratorContext []byte) (*cns.GetIPConfigResponse, error) {
var (
err error
res *http.Response
response *cns.GetIPConfigResponse
)

defer func() {
if err != nil {
cnsClient.ReleaseIPAddress(orchestratorContext)
}
}()

var body bytes.Buffer

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.RequestIPConfig

payload := &cns.GetNetworkContainerRequest{
OrchestratorContext: orchestratorContext,
}

err = json.NewEncoder(&body).Encode(payload)
if err != nil {
log.Errorf("encoding json failed with %v", err)
return response, err
}

res, err = httpc.Post(url, contentTypeJSON, &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return response, err
}

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] RequestIPAddress invalid http status code: %v", res.StatusCode)
log.Errorf(errMsg)
return response, fmt.Errorf(errMsg)
}

err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
log.Errorf("[Azure CNSClient] Error received while parsing RequestIPAddress response resp:%v err:%v", res.Body, err.Error())
return response, err
}

if response.Response.ReturnCode != 0 {
log.Errorf("[Azure CNSClient] RequestIPAddress received error response :%v", response.Response.Message)
return response, fmt.Errorf(response.Response.Message)
}

return response, err
}

// ReleaseIPAddress calls releaseIPAddress on CNS
func (cnsClient *CNSClient) ReleaseIPAddress(orchestratorContext []byte) error {
var (
err error
res *http.Response
body bytes.Buffer
)

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.ReleaseIPConfig
log.Printf("ReleaseIPAddress url %v", url)

payload := &cns.GetNetworkContainerRequest{
OrchestratorContext: orchestratorContext,
}

err = json.NewEncoder(&body).Encode(payload)
if err != nil {
log.Errorf("encoding json failed with %v", err)
return err
}

res, err = httpc.Post(url, contentTypeJSON, &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return err
}

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] ReleaseIPAddress invalid http status code: %v", res.StatusCode)
log.Errorf(errMsg)
return fmt.Errorf(errMsg)
}

var resp cns.Response

err = json.NewDecoder(res.Body).Decode(&resp)
if err != nil {
log.Errorf("[Azure CNSClient] Error received while parsing ReleaseIPAddress response resp:%v err:%v", res.Body, err.Error())
return err
}

if resp.ReturnCode != 0 {
log.Errorf("[Azure CNSClient] ReleaseIPAddress received error response :%v", resp.Message)
return fmt.Errorf(resp.Message)
}

return err
}
Loading