Skip to content

Commit eb12fea

Browse files
committed
refractor: swift v2 middleware
1 parent d221d3b commit eb12fea

File tree

9 files changed

+317
-405
lines changed

9 files changed

+317
-405
lines changed

cns/api.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ type HTTPService interface {
5151
AttachSWIFTv2Middleware(middleware SWIFTv2Middleware)
5252
}
5353

54+
type IPConfigsHandlerFunc func(context.Context, IPConfigsRequest) (*IPConfigsResponse, error)
55+
5456
// Middleware interface for testing later on
5557
type SWIFTv2Middleware interface {
56-
ValidateIPConfigsRequest(context.Context, *IPConfigsRequest) (types.ResponseCode, string)
57-
GetIPConfig(context.Context, PodInfo) (PodIpInfo, error)
58-
SetRoutes(*PodIpInfo) error
58+
IPConfigsRequestHandlerWrapper(defaultHandler IPConfigsHandlerFunc, failureHandler IPConfigsHandlerFunc) IPConfigsHandlerFunc
5959
}
6060

61-
type IPConfigsRequestValidator func(context.Context, *IPConfigsRequest) (types.ResponseCode, string)
62-
6361
// This is used for KubernetesCRD orchestrator Type where NC has multiple ips.
6462
// This struct captures the state for SecondaryIPs associated to a given NC
6563
type IPConfigurationStatus struct {

cns/middlewares/mock/mockClient.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func NewClient() *Client {
3030
testPod1.Labels = make(map[string]string)
3131
testPod1.Labels[configuration.LabelPodSwiftV2] = podNetwork
3232

33+
testPod2 := v1.Pod{}
34+
testPod2.Labels = make(map[string]string)
35+
testPod2.Labels[configuration.LabelPodSwiftV2] = podNetwork
36+
3337
testPod3 := v1.Pod{}
3438
testPod3.Labels = make(map[string]string)
3539
testPod3.Labels[configuration.LabelPodSwiftV2] = podNetwork
@@ -38,19 +42,24 @@ func NewClient() *Client {
3842
testPod4.Labels = make(map[string]string)
3943
testPod4.Labels[configuration.LabelPodSwiftV2] = podNetwork
4044

41-
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{}
45+
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{
46+
Status: v1alpha1.MultitenantPodNetworkConfigStatus{
47+
PrimaryIP: "192.168.0.1/32",
48+
MacAddress: "00:00:00:00:00:00",
49+
GatewayIP: "10.0.0.1",
50+
NCID: "testncid",
51+
},
52+
}
4253

43-
testMTPNC1.Status.PrimaryIP = "192.168.0.1/32"
44-
testMTPNC1.Status.MacAddress = "00:00:00:00:00:00"
45-
testMTPNC1.Status.GatewayIP = "10.0.0.1"
46-
testMTPNC1.Status.NCID = "testncid"
54+
testMTPNC2 := v1alpha1.MultitenantPodNetworkConfig{}
4755

4856
testMTPNC4 := v1alpha1.MultitenantPodNetworkConfig{}
4957

5058
return &Client{
5159
mtPodCache: map[string]*v1.Pod{"testpod1namespace/testpod1": &testPod1, "testpod3namespace/testpod3": &testPod3, "testpod4namespace/testpod4": &testPod4},
5260
mtpncCache: map[string]*v1alpha1.MultitenantPodNetworkConfig{
5361
"testpod1namespace/testpod1": &testMTPNC1,
62+
"testpod2namespace/testpod2": &testMTPNC2,
5463
"testpod4namespace/testpod4": &testMTPNC4,
5564
},
5665
}
@@ -74,3 +83,17 @@ func (c *Client) Get(_ context.Context, key client.ObjectKey, obj client.Object,
7483
}
7584
return nil
7685
}
86+
87+
func (c *Client) SetMTPNCReady() {
88+
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{}
89+
testMTPNC1.Status.PrimaryIP = "192.168.0.1/32"
90+
testMTPNC1.Status.MacAddress = "00:00:00:00:00:00"
91+
testMTPNC1.Status.GatewayIP = "10.0.0.1"
92+
testMTPNC1.Status.NCID = "testncid"
93+
c.mtpncCache["testpod1namespace/testpod1"] = &testMTPNC1
94+
}
95+
96+
func (c *Client) SetMTPNCNotReady() {
97+
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{}
98+
c.mtpncCache["testpod1namespace/testpod1"] = &testMTPNC1
99+
}

cns/middlewares/mock/mockSWIFTv2.go

-235
This file was deleted.

0 commit comments

Comments
 (0)