Skip to content

Commit

Permalink
refractor: swift v2 middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
nddq committed Nov 15, 2023
1 parent d221d3b commit eb12fea
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 405 deletions.
8 changes: 3 additions & 5 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ type HTTPService interface {
AttachSWIFTv2Middleware(middleware SWIFTv2Middleware)
}

type IPConfigsHandlerFunc func(context.Context, IPConfigsRequest) (*IPConfigsResponse, error)

// 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
IPConfigsRequestHandlerWrapper(defaultHandler IPConfigsHandlerFunc, failureHandler IPConfigsHandlerFunc) IPConfigsHandlerFunc
}

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

// 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
33 changes: 28 additions & 5 deletions cns/middlewares/mock/mockClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func NewClient() *Client {
testPod1.Labels = make(map[string]string)
testPod1.Labels[configuration.LabelPodSwiftV2] = podNetwork

testPod2 := v1.Pod{}
testPod2.Labels = make(map[string]string)
testPod2.Labels[configuration.LabelPodSwiftV2] = podNetwork

testPod3 := v1.Pod{}
testPod3.Labels = make(map[string]string)
testPod3.Labels[configuration.LabelPodSwiftV2] = podNetwork
Expand All @@ -38,19 +42,24 @@ func NewClient() *Client {
testPod4.Labels = make(map[string]string)
testPod4.Labels[configuration.LabelPodSwiftV2] = podNetwork

testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{}
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{
Status: v1alpha1.MultitenantPodNetworkConfigStatus{
PrimaryIP: "192.168.0.1/32",
MacAddress: "00:00:00:00:00:00",
GatewayIP: "10.0.0.1",
NCID: "testncid",
},
}

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"
testMTPNC2 := v1alpha1.MultitenantPodNetworkConfig{}

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,
"testpod2namespace/testpod2": &testMTPNC2,
"testpod4namespace/testpod4": &testMTPNC4,
},
}
Expand All @@ -74,3 +83,17 @@ func (c *Client) Get(_ context.Context, key client.ObjectKey, obj client.Object,
}
return nil
}

func (c *Client) SetMTPNCReady() {
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"
c.mtpncCache["testpod1namespace/testpod1"] = &testMTPNC1
}

func (c *Client) SetMTPNCNotReady() {
testMTPNC1 := v1alpha1.MultitenantPodNetworkConfig{}
c.mtpncCache["testpod1namespace/testpod1"] = &testMTPNC1
}
235 changes: 0 additions & 235 deletions cns/middlewares/mock/mockSWIFTv2.go

This file was deleted.

Loading

0 comments on commit eb12fea

Please sign in to comment.