Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
ace96ff
fix overlay IPAM not reporting version
nddq Jul 27, 2023
f0b4f19
Merge branch 'master' into master
nddq Jul 31, 2023
f1b5dcb
revert file and var naming, add correct path to makefile
nddq Jul 31, 2023
eebfbc8
Merge branch 'Azure:master' into master
nddq Aug 7, 2023
84abe01
Merge branch 'Azure:master' into master
nddq Aug 9, 2023
994dc04
Merge branch 'Azure:master' into master
nddq Aug 11, 2023
8475126
Merge branch 'Azure:master' into master
nddq Aug 14, 2023
29c8206
Merge branch 'Azure:master' into master
nddq Aug 16, 2023
62e6df8
Merge branch 'Azure:master' into master
nddq Aug 16, 2023
20988bd
proposal design for multitenant IPAM flow
nddq Aug 9, 2023
2e6842f
change podipinfo + linter issue
nddq Aug 9, 2023
227fd89
pointer issues for printf
nddq Aug 10, 2023
d5b00db
update IPAM branching
nddq Aug 15, 2023
e53f1e7
remove comments
nddq Aug 15, 2023
f99525c
pod client placeholder
nddq Aug 18, 2023
c7f1bca
address lint issue for httpservicefake
nddq Aug 18, 2023
f2359ac
getting pod info in validator
nddq Aug 21, 2023
fa2cac5
linter issue
nddq Aug 21, 2023
79aef2e
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 21, 2023
fd2803f
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 22, 2023
dc08bfe
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 23, 2023
7792ac4
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 23, 2023
dfd8764
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 23, 2023
a60f9e1
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 24, 2023
c58fef7
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 24, 2023
50deef4
Merge branch 'master' into swift2-cns-ipam-branching
nddq Aug 25, 2023
cc91071
update network container contract
nddq Aug 23, 2023
0674e06
renaming
nddq Aug 25, 2023
fd03f7c
mtpnc changes
nddq Aug 29, 2023
baeb65b
Merge branch 'Azure:master' into master
nddq Aug 29, 2023
1e7c99d
rebase
nddq Aug 29, 2023
6e71052
revert file and var naming, add correct path to makefile
nddq Jul 31, 2023
9225521
resolved merge conflicts
nddq Aug 29, 2023
ad1bf07
add default route
nddq Aug 29, 2023
78bc86f
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 3, 2023
31ebd90
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 7, 2023
e26f7c3
add unit tests
nddq Sep 8, 2023
9f97340
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 8, 2023
1d4a4bf
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 8, 2023
0860321
update unit tests for ipam
nddq Sep 11, 2023
1286167
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 11, 2023
5a89c51
go get to fix linter
nddq Sep 11, 2023
e193b82
go mod tidy
nddq Sep 11, 2023
d1db1ab
update routes
nddq Sep 11, 2023
c3e470a
update routes
nddq Sep 11, 2023
7458cf1
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 12, 2023
c091ec3
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 15, 2023
dd45bed
remove stale comments + remove redundant method
nddq Sep 15, 2023
745f2cf
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 18, 2023
bf483aa
add contexts + change address type
nddq Sep 18, 2023
47ce73f
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 20, 2023
01310d2
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 20, 2023
16e7c50
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 20, 2023
99d1e8d
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 21, 2023
fcdaae0
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 22, 2023
843a64e
addressed review
nddq Sep 22, 2023
04ee54c
embedded client to mock + enum for address type
nddq Sep 22, 2023
08b4a78
fix error
nddq Sep 22, 2023
da54a6e
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 22, 2023
01cc008
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 25, 2023
6bb2b7d
change addressType to NICType
nddq Sep 25, 2023
4ee5937
change isDefaultRoute to SkipDefaultRoutes
nddq Sep 25, 2023
7c49876
address comments
nddq Sep 25, 2023
aa80c2b
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 25, 2023
c9baa54
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 26, 2023
cb8481f
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 27, 2023
d36f4e7
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 27, 2023
33c25f6
refractor: make changes according to cni/cns contract
nddq Sep 27, 2023
2d5c6bd
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 28, 2023
c0e2ae7
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 29, 2023
0972ce4
refractor: make adding route its own func + move swift v2 ipam branch…
nddq Sep 29, 2023
3fc14bd
refractor: change vars naming
nddq Sep 29, 2023
28ba7b2
refractor: more var naming
nddq Sep 29, 2023
b067200
test: add test for podv6cidr
nddq Sep 29, 2023
4ffe8d6
refractor: make the returning podIpInfo init cleaner in swiftv2.go
nddq Sep 29, 2023
975e9b4
Merge branch 'master' into swift2-cns-ipam-branching
nddq Sep 30, 2023
0a25e65
refractor + tests: add contexts to ipconfigs req validators + set rou…
nddq Oct 2, 2023
d87e4dc
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 3, 2023
7153f9b
refractor: change labels for swift v2 pods
nddq Oct 3, 2023
d294df3
fix: fix swift v2 UT
nddq Oct 3, 2023
e4c60cf
refractor: add v4/v6 distinction for service cidr
nddq Oct 3, 2023
0437f9b
Merge branch 'Azure:master' into swift2-cns-ipam-branching
nddq Oct 4, 2023
5113094
rebase
nddq Aug 29, 2023
aee4f2e
revert file and var naming, add correct path to makefile
nddq Jul 31, 2023
68e65e7
rebase
nddq Aug 29, 2023
fdebcf4
revert file and var naming, add correct path to makefile
nddq Jul 31, 2023
f4802eb
change podipinfo + linter issue
nddq Aug 9, 2023
ece68a6
update IPAM branching
nddq Aug 15, 2023
ddf472a
pod client placeholder
nddq Aug 18, 2023
691f733
getting pod info in validator
nddq Aug 21, 2023
e11247b
linter issue
nddq Aug 21, 2023
b6d6c26
rebase
nddq Aug 29, 2023
48a911d
revert file and var naming, add correct path to makefile
nddq Jul 31, 2023
29b6f67
refractor: fix conflicts
nddq Oct 4, 2023
c79a0e6
refractor: revert podwatcher code changes
nddq Oct 4, 2023
ff291a2
docs: change comment
nddq Oct 4, 2023
17702e9
refractor: change CIDR to CDIRs
nddq Oct 4, 2023
62080d6
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 4, 2023
40964f9
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 5, 2023
43d7d40
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 5, 2023
0e88376
refractor: parse CIDRs as semicolons separated string from env in Set…
nddq Oct 6, 2023
b99f5fa
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 7, 2023
308d799
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 9, 2023
e59220e
docs: add minor comment
nddq Oct 10, 2023
edcdb2f
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 11, 2023
8f7e3c0
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 13, 2023
7e086db
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 13, 2023
979c417
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 13, 2023
48f3895
Merge branch 'master' into swift2-cns-ipam-branching
nddq Oct 16, 2023
627b1a0
refractor: change separator for parsing CIDRs
nddq Oct 16, 2023
6085da3
feat: add rbac roles
nddq Oct 17, 2023
c96cc66
fix: gofumpt
nddq Oct 17, 2023
f4f2f8e
fix: update clusterrole
nddq Oct 17, 2023
0b55822
fix: add namespace to clusterrolebinding
nddq Oct 17, 2023
4b85934
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 17, 2023
b7639ed
fix: UT
nddq Oct 17, 2023
75a2110
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 18, 2023
768a9de
fix: add labels toswift v2 clusterrole
nddq Oct 18, 2023
610446c
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 20, 2023
65977ed
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 23, 2023
7e00999
fix: release default ipconfig early if getting swiftv2 ipconfig failed
nddq Oct 24, 2023
7d791f3
test: add more UT
nddq Oct 24, 2023
7b3987a
fix: parsing MTPNC as CIDR instead
nddq Oct 24, 2023
28b0bfa
fix: toggle skipDefaultRoutes for infraNic to true
nddq Oct 24, 2023
b307254
fix: add route for node cidr in ipv4 podipconfig
nddq Oct 26, 2023
38fc471
feat: add node cidrs route
nddq Oct 26, 2023
d1522cd
fix: linter
nddq Oct 26, 2023
de1c82d
address comments
nddq Oct 26, 2023
9f8f7d4
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 27, 2023
432a79d
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 27, 2023
5ef9623
fix: minor logs formatting
nddq Oct 27, 2023
adb1813
feat: move cns yaml for swiftv2 scenario to a diff file + more loggin…
nddq Oct 27, 2023
5660542
fix: log debugf to printf
nddq Oct 27, 2023
dc005cd
fix: add testmain to avoid nil pointer error for loggers
nddq Oct 27, 2023
94a8e2d
Update azure-cns.yaml
nddq Oct 27, 2023
382708d
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 27, 2023
ae5d28d
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 28, 2023
2d305e1
fix: move parseCIDRs to a common package, use net/netip instead of net
nddq Oct 27, 2023
54aa8be
fix: exhaustive all switch case for nic type
nddq Oct 28, 2023
86b9e7d
fix: exhaustive all switch case for nic type
nddq Oct 28, 2023
9417618
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 30, 2023
8fed7b9
refractor: change fmt.Errorf to errors.Wrapf
nddq Oct 30, 2023
d57e6b3
fix: add mtpnc status check in validator + use netip package
nddq Oct 30, 2023
04f08fe
fix: minor
nddq Oct 30, 2023
790e787
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 30, 2023
0688baf
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 30, 2023
82016cd
Merge branch 'master' into featSWIFTv2-IPAM-branching
nddq Oct 30, 2023
113021d
revert: azure-cns.yaml
nddq Oct 31, 2023
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
6 changes: 4 additions & 2 deletions cni/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"go.uber.org/zap"
)

var logger = log.CNILogger.With(zap.String("component", "cni-plugin"))
var storeLogger = log.CNILogger.With(zap.String("component", "cni-store"))
var (
logger = log.CNILogger.With(zap.String("component", "cni-plugin"))
storeLogger = log.CNILogger.With(zap.String("component", "cni-store"))
)

var errEmptyContent = errors.New("read content is zero bytes")

Expand Down
25 changes: 17 additions & 8 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ type PodInfo interface {
Equals(PodInfo) bool
// String implements string for logging PodInfos
String() string
// SecondaryInterfacesExist returns true if there exist a secondary interface for this pod
SecondaryInterfacesExist() bool
}

type KubernetesPodInfo struct {
Expand All @@ -199,9 +201,10 @@ var _ PodInfo = (*podInfo)(nil)
// podInfo implements PodInfo for multiple schemas of Key
type podInfo struct {
KubernetesPodInfo
PodInfraContainerID string
PodInterfaceID string
Version podInfoScheme
PodInfraContainerID string
PodInterfaceID string
Version podInfoScheme
SecondaryInterfaceSet bool
}

func (p podInfo) String() string {
Expand Down Expand Up @@ -255,6 +258,10 @@ func (p *podInfo) OrchestratorContext() (json.RawMessage, error) {
return jsonContext, nil
}

func (p *podInfo) SecondaryInterfacesExist() bool {
return p.SecondaryInterfaceSet
}

// NewPodInfo returns an implementation of PodInfo that returns the passed
// configuration for their namesake functions.
func NewPodInfo(infraContainerID, interfaceID, name, namespace string) PodInfo {
Expand Down Expand Up @@ -292,6 +299,7 @@ func NewPodInfoFromIPConfigsRequest(req IPConfigsRequest) (PodInfo, error) {
}
p.(*podInfo).PodInfraContainerID = req.InfraContainerID
p.(*podInfo).PodInterfaceID = req.PodInterfaceID
p.(*podInfo).SecondaryInterfaceSet = req.SecondaryInterfacesExist
return p, nil
}

Expand Down Expand Up @@ -453,11 +461,12 @@ type IPConfigRequest struct {

// Same as IPConfigRequest except that DesiredIPAddresses is passed in as a slice
type IPConfigsRequest struct {
DesiredIPAddresses []string `json:"desiredIPAddresses"`
PodInterfaceID string `json:"podInterfaceID"`
InfraContainerID string `json:"infraContainerID"`
OrchestratorContext json.RawMessage `json:"orchestratorContext"`
Ifname string `json:"ifname"` // Used by delegated IPAM
DesiredIPAddresses []string `json:"desiredIPAddresses"`
PodInterfaceID string `json:"podInterfaceID"`
InfraContainerID string `json:"infraContainerID"`
OrchestratorContext json.RawMessage `json:"orchestratorContext"`
Ifname string `json:"ifname"` // Used by delegated IPAM
SecondaryInterfacesExist bool `json:"secondaryInterfacesExist"` // will be set by SWIFT v2 validator func
}

// IPConfigResponse is used in CNS IPAM mode as a response to CNI ADD
Expand Down
10 changes: 10 additions & 0 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,18 @@ type HTTPService interface {
GetPendingReleaseIPConfigs() []IPConfigurationStatus
GetPodIPConfigState() map[string]IPConfigurationStatus
MarkIPAsPendingRelease(numberToMark int) (map[string]IPConfigurationStatus, error)
AttachSWIFTv2Middleware(middleware SWIFTv2Middleware)
}

// Middleware interface for testing later on
type SWIFTv2Middleware interface {
ValidateIPConfigsRequest(context.Context, *IPConfigsRequest) (types.ResponseCode, string)
GetIPConfig(context.Context, PodInfo) (PodIpInfo, error)
SetRoutes(*PodIpInfo) error
}

type IPConfigsRequestValidator func(context.Context, *IPConfigsRequest) (types.ResponseCode, string)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this func need to return (types.ResponseCode, string)? If it is just a validator, returning err or nil should be plenty?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see from the impl that this is not actually a pure function, as -Validator implies.
It also isn't really middleware/decorator - that would require the input to the middleware func to the next func to call in the chain...this is just a dependent object.
Since it mutates the input *IPConfigsRequest, the field in the "Middleware" object should be renamed to something like SetHasSecondaryInterface. I don't have a good idea for what the interface def should be renamed to, but validator it is not.

Copy link
Member Author

Choose a reason for hiding this comment

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

fyi @miguelgoms, we had a discussion regarding this offline. Currently the way I implement the logic behind SWIFTv2Middleware cherry-picked middleware behaviors, but it is not "true middleware". It is a design review so it is not blocking, we can still go ahead with this since everything is working now, but I can go back to this after we got everything merged to revise the design.


// This is used for KubernetesCRD orchestrator Type where NC has multiple ips.
// This struct captures the state for SecondaryIPs associated to a given NC
type IPConfigurationStatus struct {
Expand Down
2 changes: 1 addition & 1 deletion cns/azure-cns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ data:
"ManageEndpointState": false,
"ProgramSNATIPTables" : false
}
# Toggle ManageEndpointState and ProgramSNATIPTables to true for delegated IPAM use case.
# Toggle ManageEndpointState and ProgramSNATIPTables to true for delegated IPAM use case.
42 changes: 40 additions & 2 deletions cns/configuration/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ const (
EnvNodeName = "NODENAME"
// EnvNodeIP is the IP of the node running this CNS binary
EnvNodeIP = "NODE_IP"
// LabelSwiftV2 is the Node label for Swift V2
LabelSwiftV2 = "kubernetes.azure.com/podnetwork-multi-tenancy"
// LabelNodeSwiftV2 is the Node label for Swift V2
LabelNodeSwiftV2 = "kubernetes.azure.com/podnetwork-multi-tenancy-enabled"
// LabelPodSwiftV2 is the Pod label for Swift V2
LabelPodSwiftV2 = "kubernetes.azure.com/pod-network"
EnvPodCIDRs = "POD_CIDRs"
EnvServiceCIDRs = "SERVICE_CIDRs"
EnvNodeCIDRs = "NODE_CIDRs"
Copy link
Member

Choose a reason for hiding this comment

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

This will change to infraVnet CIDR in future PR

)

// ErrNodeNameUnset indicates the the $EnvNodeName variable is unset in the environment.
var ErrNodeNameUnset = errors.Errorf("must declare %s environment variable", EnvNodeName)

// ErrPodCIDRsUnset indicates the the $EnvPodCIDRs variable is unset in the environment.
var ErrPodCIDRsUnset = errors.Errorf("must declare %s environment variable", EnvPodCIDRs)

// ErrServiceCIDRsUnset indicates the the $EnvServiceCIDRs variable is unset in the environment.
var ErrServiceCIDRsUnset = errors.Errorf("must declare %s environment variable", EnvServiceCIDRs)

// ErrNodeCIDRsUnset indicates the the $EnvNodeCIDRs variable is unset in the environment.
var ErrNodeCIDRsUnset = errors.Errorf("must declare %s environment variable", EnvNodeCIDRs)

// NodeName checks the environment variables for the NODENAME and returns it or an error if unset.
func NodeName() (string, error) {
nodeName := os.Getenv(EnvNodeName)
Expand All @@ -31,3 +45,27 @@ func NodeName() (string, error) {
func NodeIP() string {
return os.Getenv(EnvNodeIP)
}

func PodCIDRs() (string, error) {
podCIDRs := os.Getenv(EnvPodCIDRs)
if podCIDRs == "" {
return "", ErrPodCIDRsUnset
}
return podCIDRs, nil
}

func ServiceCIDRs() (string, error) {
serviceCIDRs := os.Getenv(EnvServiceCIDRs)
if serviceCIDRs == "" {
return "", ErrServiceCIDRsUnset
}
return serviceCIDRs, nil
}

func NodeCIDRs() (string, error) {
nodeCIDRs := os.Getenv(EnvNodeCIDRs)
if nodeCIDRs == "" {
return "", ErrNodeCIDRsUnset
}
return nodeCIDRs, nil
}
20 changes: 20 additions & 0 deletions cns/configuration/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ func TestNodeName(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "test", name)
}

func TestPodCIDRs(t *testing.T) {
_, err := PodCIDRs()
require.Error(t, err)
require.ErrorIs(t, err, ErrPodCIDRsUnset)
os.Setenv(EnvPodCIDRs, "test")
cidr, err := PodCIDRs()
assert.NoError(t, err)
assert.Equal(t, "test", cidr)
}

func TestServiceCIDRs(t *testing.T) {
_, err := ServiceCIDRs()
require.Error(t, err)
require.ErrorIs(t, err, ErrServiceCIDRsUnset)
os.Setenv(EnvServiceCIDRs, "test")
cidr, err := ServiceCIDRs()
assert.NoError(t, err)
assert.Equal(t, "test", cidr)
}
2 changes: 2 additions & 0 deletions cns/fakes/cnsfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,5 @@ func (fake *HTTPServiceFake) Init(*common.ServiceConfig) error {
}

func (fake *HTTPServiceFake) Stop() {}

func (fake *HTTPServiceFake) AttachSWIFTv2Middleware(cns.SWIFTv2Middleware) {}
76 changes: 76 additions & 0 deletions cns/middlewares/mock/mockClient.go
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
}
Loading