-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CNS RequestIPAddress branching for MT/V2 (#2300)
* fix overlay IPAM not reporting version * revert file and var naming, add correct path to makefile * proposal design for multitenant IPAM flow * change podipinfo + linter issue * pointer issues for printf * update IPAM branching * remove comments * pod client placeholder * address lint issue for httpservicefake * getting pod info in validator * linter issue * update network container contract * renaming * mtpnc changes * rebase * revert file and var naming, add correct path to makefile * add default route * add unit tests * update unit tests for ipam * go get to fix linter * go mod tidy * update routes * update routes * remove stale comments + remove redundant method * add contexts + change address type * addressed review * embedded client to mock + enum for address type * fix error * change addressType to NICType * change isDefaultRoute to SkipDefaultRoutes * address comments * refractor: make changes according to cni/cns contract * refractor: make adding route its own func + move swift v2 ipam branching to after normal ipam flow * refractor: change vars naming * refractor: more var naming * test: add test for podv6cidr * refractor: make the returning podIpInfo init cleaner in swiftv2.go * refractor + tests: add contexts to ipconfigs req validators + set route tests * refractor: change labels for swift v2 pods * fix: fix swift v2 UT * refractor: add v4/v6 distinction for service cidr * rebase * revert file and var naming, add correct path to makefile * rebase * revert file and var naming, add correct path to makefile * change podipinfo + linter issue * update IPAM branching * pod client placeholder * getting pod info in validator * linter issue * rebase * revert file and var naming, add correct path to makefile * refractor: fix conflicts * refractor: revert podwatcher code changes * docs: change comment * refractor: change CIDR to CDIRs * refractor: parse CIDRs as semicolons separated string from env in SetRoutes * docs: add minor comment * refractor: change separator for parsing CIDRs * feat: add rbac roles * fix: gofumpt * fix: update clusterrole * fix: add namespace to clusterrolebinding * fix: UT * fix: add labels toswift v2 clusterrole * fix: release default ipconfig early if getting swiftv2 ipconfig failed * test: add more UT * fix: parsing MTPNC as CIDR instead * fix: toggle skipDefaultRoutes for infraNic to true * fix: add route for node cidr in ipv4 podipconfig * feat: add node cidrs route * fix: linter * address comments * fix: minor logs formatting * feat: move cns yaml for swiftv2 scenario to a diff file + more logging for swiftv2middleware * fix: log debugf to printf * fix: add testmain to avoid nil pointer error for loggers * Update azure-cns.yaml Signed-off-by: Quang Nguyen <[email protected]> * fix: move parseCIDRs to a common package, use net/netip instead of net * fix: exhaustive all switch case for nic type * fix: exhaustive all switch case for nic type * refractor: change fmt.Errorf to errors.Wrapf * fix: add mtpnc status check in validator + use netip package * fix: minor * revert: azure-cns.yaml --------- Signed-off-by: Quang Nguyen <[email protected]> Signed-off-by: Quang Nguyen <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,184 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,76 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-container-networking/cns/configuration" | ||
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1" | ||
"github.com/pkg/errors" | ||
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") | ||
) | ||
|
||
// Client implements the client.Client interface for testing. We only care about Get, the rest is nil ops. | ||
type Client struct { | ||
client.Client | ||
mtPodCache map[string]*v1.Pod | ||
mtpncCache map[string]*v1alpha1.MultitenantPodNetworkConfig | ||
} | ||
|
||
// NewClient returns a new MockClient. | ||
func NewClient() *Client { | ||
const podNetwork = "azure" | ||
|
||
testPod1 := v1.Pod{} | ||
testPod1.Labels = make(map[string]string) | ||
testPod1.Labels[configuration.LabelPodSwiftV2] = podNetwork | ||
|
||
testPod3 := v1.Pod{} | ||
testPod3.Labels = make(map[string]string) | ||
testPod3.Labels[configuration.LabelPodSwiftV2] = podNetwork | ||
|
||
testPod4 := v1.Pod{} | ||
testPod4.Labels = make(map[string]string) | ||
testPod4.Labels[configuration.LabelPodSwiftV2] = podNetwork | ||
|
||
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{} | ||
|
||
testMTPNC1.Status.PrimaryIP = "192.168.0.1/32" | ||
testMTPNC1.Status.MacAddress = "00:00:00:00:00:00" | ||
testMTPNC1.Status.GatewayIP = "10.0.0.1" | ||
testMTPNC1.Status.NCID = "testncid" | ||
|
||
testMTPNC4 := v1alpha1.MultitenantPodNetworkConfig{} | ||
|
||
return &Client{ | ||
mtPodCache: map[string]*v1.Pod{"testpod1namespace/testpod1": &testPod1, "testpod3namespace/testpod3": &testPod3, "testpod4namespace/testpod4": &testPod4}, | ||
mtpncCache: map[string]*v1alpha1.MultitenantPodNetworkConfig{ | ||
"testpod1namespace/testpod1": &testMTPNC1, | ||
"testpod4namespace/testpod4": &testMTPNC4, | ||
}, | ||
} | ||
} | ||
|
||
// Get implements client.Client.Get. | ||
func (c *Client) 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 | ||
} |
Oops, something went wrong.