-
Notifications
You must be signed in to change notification settings - Fork 260
feat: CNS RequestIPAddress branching for MT/V2 #2114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
ace96ff
fix overlay IPAM not reporting version
nddq f0b4f19
Merge branch 'master' into master
nddq f1b5dcb
revert file and var naming, add correct path to makefile
nddq eebfbc8
Merge branch 'Azure:master' into master
nddq 84abe01
Merge branch 'Azure:master' into master
nddq 994dc04
Merge branch 'Azure:master' into master
nddq 8475126
Merge branch 'Azure:master' into master
nddq 29c8206
Merge branch 'Azure:master' into master
nddq 62e6df8
Merge branch 'Azure:master' into master
nddq 20988bd
proposal design for multitenant IPAM flow
nddq 2e6842f
change podipinfo + linter issue
nddq 227fd89
pointer issues for printf
nddq d5b00db
update IPAM branching
nddq e53f1e7
remove comments
nddq f99525c
pod client placeholder
nddq c7f1bca
address lint issue for httpservicefake
nddq f2359ac
getting pod info in validator
nddq fa2cac5
linter issue
nddq 79aef2e
Merge branch 'master' into swift2-cns-ipam-branching
nddq fd2803f
Merge branch 'master' into swift2-cns-ipam-branching
nddq dc08bfe
Merge branch 'master' into swift2-cns-ipam-branching
nddq 7792ac4
Merge branch 'master' into swift2-cns-ipam-branching
nddq dfd8764
Merge branch 'master' into swift2-cns-ipam-branching
nddq a60f9e1
Merge branch 'master' into swift2-cns-ipam-branching
nddq c58fef7
Merge branch 'master' into swift2-cns-ipam-branching
nddq 50deef4
Merge branch 'master' into swift2-cns-ipam-branching
nddq cc91071
update network container contract
nddq 0674e06
renaming
nddq fd03f7c
mtpnc changes
nddq baeb65b
Merge branch 'Azure:master' into master
nddq 1e7c99d
rebase
nddq 6e71052
revert file and var naming, add correct path to makefile
nddq 9225521
resolved merge conflicts
nddq ad1bf07
add default route
nddq 78bc86f
Merge branch 'master' into swift2-cns-ipam-branching
nddq 31ebd90
Merge branch 'master' into swift2-cns-ipam-branching
nddq e26f7c3
add unit tests
nddq 9f97340
Merge branch 'master' into swift2-cns-ipam-branching
nddq 1d4a4bf
Merge branch 'master' into swift2-cns-ipam-branching
nddq 0860321
update unit tests for ipam
nddq 1286167
Merge branch 'master' into swift2-cns-ipam-branching
nddq 5a89c51
go get to fix linter
nddq e193b82
go mod tidy
nddq d1db1ab
update routes
nddq c3e470a
update routes
nddq 7458cf1
Merge branch 'master' into swift2-cns-ipam-branching
nddq c091ec3
Merge branch 'master' into swift2-cns-ipam-branching
nddq dd45bed
remove stale comments + remove redundant method
nddq 745f2cf
Merge branch 'master' into swift2-cns-ipam-branching
nddq bf483aa
add contexts + change address type
nddq 47ce73f
Merge branch 'master' into swift2-cns-ipam-branching
nddq 01310d2
Merge branch 'master' into swift2-cns-ipam-branching
nddq 16e7c50
Merge branch 'master' into swift2-cns-ipam-branching
nddq 99d1e8d
Merge branch 'master' into swift2-cns-ipam-branching
nddq fcdaae0
Merge branch 'master' into swift2-cns-ipam-branching
nddq 843a64e
addressed review
nddq 04ee54c
embedded client to mock + enum for address type
nddq 08b4a78
fix error
nddq da54a6e
Merge branch 'master' into swift2-cns-ipam-branching
nddq 01cc008
Merge branch 'master' into swift2-cns-ipam-branching
nddq 6bb2b7d
change addressType to NICType
nddq 4ee5937
change isDefaultRoute to SkipDefaultRoutes
nddq 7c49876
address comments
nddq aa80c2b
Merge branch 'master' into swift2-cns-ipam-branching
nddq c9baa54
Merge branch 'master' into swift2-cns-ipam-branching
nddq cb8481f
Merge branch 'master' into swift2-cns-ipam-branching
nddq d36f4e7
Merge branch 'master' into swift2-cns-ipam-branching
nddq 33c25f6
refractor: make changes according to cni/cns contract
nddq 2d5c6bd
Merge branch 'master' into swift2-cns-ipam-branching
nddq c0e2ae7
Merge branch 'master' into swift2-cns-ipam-branching
nddq 0972ce4
refractor: make adding route its own func + move swift v2 ipam branch…
nddq 3fc14bd
refractor: change vars naming
nddq 28ba7b2
refractor: more var naming
nddq b067200
test: add test for podv6cidr
nddq 4ffe8d6
refractor: make the returning podIpInfo init cleaner in swiftv2.go
nddq 975e9b4
Merge branch 'master' into swift2-cns-ipam-branching
nddq 0a25e65
refractor + tests: add contexts to ipconfigs req validators + set rou…
nddq d87e4dc
Merge branch 'master' into swift2-cns-ipam-branching
nddq 7153f9b
refractor: change labels for swift v2 pods
nddq d294df3
fix: fix swift v2 UT
nddq e4c60cf
refractor: add v4/v6 distinction for service cidr
nddq 0437f9b
Merge branch 'Azure:master' into swift2-cns-ipam-branching
nddq 5113094
rebase
nddq aee4f2e
revert file and var naming, add correct path to makefile
nddq 68e65e7
rebase
nddq fdebcf4
revert file and var naming, add correct path to makefile
nddq f4802eb
change podipinfo + linter issue
nddq ece68a6
update IPAM branching
nddq ddf472a
pod client placeholder
nddq 691f733
getting pod info in validator
nddq e11247b
linter issue
nddq b6d6c26
rebase
nddq 48a911d
revert file and var naming, add correct path to makefile
nddq 29b6f67
refractor: fix conflicts
nddq c79a0e6
refractor: revert podwatcher code changes
nddq ff291a2
docs: change comment
nddq 17702e9
refractor: change CIDR to CDIRs
nddq 62080d6
Merge branch 'master' into swift2-cns-ipam-branching
nddq 40964f9
Merge branch 'master' into swift2-cns-ipam-branching
nddq 43d7d40
Merge branch 'master' into swift2-cns-ipam-branching
nddq 0e88376
refractor: parse CIDRs as semicolons separated string from env in Set…
nddq b99f5fa
Merge branch 'master' into swift2-cns-ipam-branching
nddq 308d799
Merge branch 'master' into swift2-cns-ipam-branching
nddq e59220e
docs: add minor comment
nddq edcdb2f
Merge branch 'master' into swift2-cns-ipam-branching
nddq 8f7e3c0
Merge branch 'master' into swift2-cns-ipam-branching
nddq 7e086db
Merge branch 'master' into swift2-cns-ipam-branching
nddq 979c417
Merge branch 'master' into swift2-cns-ipam-branching
nddq 48f3895
Merge branch 'master' into swift2-cns-ipam-branching
nddq 627b1a0
refractor: change separator for parsing CIDRs
nddq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package middlewares | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns/configuration" | ||
| "github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1" | ||
| v1 "k8s.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| var ( | ||
| errPodNotFound = errors.New("pod not found") | ||
| errMTPNCNotFound = errors.New("mtpnc not found") | ||
| ) | ||
|
|
||
| // MockClient implements the client.Client interface for testing. We only care about Get, the rest is nil ops. | ||
| type MockClient struct { | ||
| client.Client | ||
| mtPodCache map[string]*v1.Pod | ||
| mtpncCache map[string]*v1alpha1.MultitenantPodNetworkConfig | ||
| } | ||
|
|
||
| // NewMockClient returns a new MockClient. | ||
| func NewMockClient() *MockClient { | ||
| testPod1 := v1.Pod{} | ||
| testPod1.Labels = make(map[string]string) | ||
| testPod1.Labels[configuration.LabelPodSwiftV2] = "true" | ||
|
|
||
| testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{} | ||
| testMTPNC1.Status.PrimaryIP = "192.168.0.1" | ||
| testMTPNC1.Status.MacAddress = "00:00:00:00:00:00" | ||
| testMTPNC1.Status.GatewayIP = "10.0.0.1" | ||
| testMTPNC1.Status.NCID = "testncid" | ||
|
|
||
| testMTPNC3 := v1alpha1.MultitenantPodNetworkConfig{} | ||
|
|
||
| return &MockClient{ | ||
| mtPodCache: map[string]*v1.Pod{"testpod1namespace/testpod1": &testPod1}, | ||
| mtpncCache: map[string]*v1alpha1.MultitenantPodNetworkConfig{ | ||
| "testpod1namespace/testpod1": &testMTPNC1, | ||
| "testpod3namespace/testpod3": &testMTPNC3, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // Get implements client.Client.Get. | ||
| func (c *MockClient) Get(_ context.Context, key client.ObjectKey, obj client.Object, _ ...client.GetOption) error { | ||
| switch o := obj.(type) { | ||
| case *v1.Pod: | ||
| if pod, ok := c.mtPodCache[key.String()]; ok { | ||
| *o = *pod | ||
| } else { | ||
| return errPodNotFound | ||
| } | ||
| case *v1alpha1.MultitenantPodNetworkConfig: | ||
| if mtpnc, ok := c.mtpncCache[key.String()]; ok { | ||
| *o = *mtpnc | ||
| } else { | ||
| return errMTPNCNotFound | ||
| } | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package middlewares | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/configuration" | ||
| "github.com/Azure/azure-container-networking/cns/types" | ||
| "github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1" | ||
| v1 "k8s.io/api/core/v1" | ||
| k8types "k8s.io/apimachinery/pkg/types" | ||
| ) | ||
|
|
||
| var ( | ||
| errMTPNCNotReady = errors.New("mtpnc is not ready") | ||
| errFailedToGetPod = errors.New("failed to get pod") | ||
| ) | ||
|
|
||
| type MockSWIFTv2Middleware struct { | ||
| mtPodState map[string]*v1.Pod | ||
| mtpncState map[string]*v1alpha1.MultitenantPodNetworkConfig | ||
| } | ||
|
|
||
| func NewMockSWIFTv2Middleware() *MockSWIFTv2Middleware { | ||
| testPod1 := v1.Pod{} | ||
| testPod1.Labels = make(map[string]string) | ||
| testPod1.Labels[configuration.LabelPodSwiftV2] = "true" | ||
|
|
||
| testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{} | ||
| testMTPNC1.Status.PrimaryIP = "192.168.0.1" | ||
| testMTPNC1.Status.MacAddress = "00:00:00:00:00:00" | ||
| testMTPNC1.Status.GatewayIP = "10.0.0.1" | ||
| testMTPNC1.Status.NCID = "testncid" | ||
|
|
||
| return &MockSWIFTv2Middleware{ | ||
| mtPodState: map[string]*v1.Pod{"testpod1namespace/testpod1": &testPod1}, | ||
| mtpncState: map[string]*v1alpha1.MultitenantPodNetworkConfig{"testpod1namespace/testpod1": &testMTPNC1}, | ||
| } | ||
| } | ||
|
|
||
| // validateMultitenantIPConfigsRequest validates if pod is multitenant | ||
| // nolint | ||
| func (m *MockSWIFTv2Middleware) ValidateIPConfigsRequest(_ context.Context, req *cns.IPConfigsRequest) (respCode types.ResponseCode, message string) { | ||
| // Retrieve the pod from the cluster | ||
| podInfo, err := cns.UnmarshalPodInfo(req.OrchestratorContext) | ||
| if err != nil { | ||
| errBuf := fmt.Sprintf("unmarshalling pod info from ipconfigs request %v failed with error %v", req, err) | ||
| return types.UnexpectedError, errBuf | ||
| } | ||
| podNamespacedName := k8types.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()} | ||
| pod, ok := m.mtPodState[podNamespacedName.String()] | ||
| if !ok { | ||
| errBuf := fmt.Sprintf("failed to get pod %v with error %v", podNamespacedName, err) | ||
| return types.UnexpectedError, errBuf | ||
| } | ||
| // check the pod labels for Swift V2, enrich the request with the multitenant flag. | ||
| if _, ok := pod.Labels[configuration.LabelPodSwiftV2]; ok { | ||
| req.SecondaryInterfacesExist = true | ||
| } | ||
| return types.Success, "" | ||
| } | ||
|
|
||
| // GetSWIFTv2IPConfig(podInfo PodInfo) (*PodIpInfo, error) | ||
| // GetMultitenantIPConfig returns the IP config for a multitenant pod from the MTPNC CRD | ||
| func (m *MockSWIFTv2Middleware) GetIPConfig(_ context.Context, podInfo cns.PodInfo) (cns.PodIpInfo, error) { | ||
| // Check if the MTPNC CRD exists for the pod, if not, return error | ||
| mtpncNamespacedName := k8types.NamespacedName{Namespace: podInfo.Namespace(), Name: podInfo.Name()} | ||
| mtpnc, ok := m.mtpncState[mtpncNamespacedName.String()] | ||
| if !ok { | ||
| return cns.PodIpInfo{}, errFailedToGetPod | ||
| } | ||
|
|
||
| // Check if the MTPNC CRD is ready. If one of the fields is empty, return error | ||
| if mtpnc.Status.PrimaryIP == "" || mtpnc.Status.MacAddress == "" || mtpnc.Status.NCID == "" || mtpnc.Status.GatewayIP == "" { | ||
| return cns.PodIpInfo{}, errMTPNCNotReady | ||
| } | ||
| podIPInfo := cns.PodIpInfo{} | ||
| podIPInfo.PodIPConfig = cns.IPSubnet{ | ||
| IPAddress: mtpnc.Status.PrimaryIP, | ||
| } | ||
| podIPInfo.MacAddress = mtpnc.Status.MacAddress | ||
| podIPInfo.NICType = cns.DelegatedVMNIC | ||
| podIPInfo.SkipDefaultRoutes = false | ||
|
|
||
| return podIPInfo, nil | ||
| } | ||
|
|
||
| func (m *MockSWIFTv2Middleware) SetRoutes(_ *cns.PodIpInfo) error { | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.