@@ -15,12 +15,14 @@ import (
1515 apierrors "k8s.io/apimachinery/pkg/api/errors"
1616 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1717 "k8s.io/apimachinery/pkg/types"
18+ "sigs.k8s.io/controller-runtime/pkg/client"
1819 "sigs.k8s.io/controller-runtime/pkg/reconcile"
1920)
2021
2122var _ = Describe ("multiTenantCrdReconciler" , func () {
2223 var kubeClient * mockclients.MockClient
2324 var cnsRestService * mockclients.MockcnsRESTservice
25+ var statusWriter * mockclients.MockSubResourceWriter
2426 var mockCtl * gomock.Controller
2527 var reconciler * multiTenantCrdReconciler
2628 const uuidValue = "uuid"
@@ -39,6 +41,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
3941 mockCtl = gomock .NewController (GinkgoT ())
4042 kubeClient = mockclients .NewMockClient (mockCtl )
4143 cnsRestService = mockclients .NewMockcnsRESTservice (mockCtl )
44+ statusWriter = mockclients .NewMockSubResourceWriter (mockCtl )
4245 reconciler = & multiTenantCrdReconciler {
4346 KubeClient : kubeClient ,
4447 NodeName : mockNodeName ,
@@ -103,6 +106,67 @@ var _ = Describe("multiTenantCrdReconciler", func() {
103106 Expect (err ).To (BeNil ())
104107 })
105108
109+ It ("Should succeed when the NC is in Initialized state and it has not yet been persisted in CNS" , func () {
110+ uuid := uuidValue
111+ var nc ncapi.MultiTenantNetworkContainer = ncapi.MultiTenantNetworkContainer {
112+ ObjectMeta : metav1.ObjectMeta {
113+ Name : namespacedName .Name ,
114+ Namespace : namespacedName .Namespace ,
115+ },
116+ Spec : ncapi.MultiTenantNetworkContainerSpec {
117+ UUID : uuid ,
118+ },
119+ Status : ncapi.MultiTenantNetworkContainerStatus {
120+ State : "Initialized" ,
121+ MultiTenantInfo : ncapi.MultiTenantInfo {
122+ EncapType : "Vlan" ,
123+ ID : 1 ,
124+ },
125+ IPSubnet : "10.0.0.0/8" ,
126+ IP : "10.1.0.0" ,
127+ },
128+ }
129+
130+ orchestratorContext , err := json .Marshal (podInfo )
131+ Expect (err ).To (BeNil ())
132+
133+ kubeClient .EXPECT ().Get (gomock .Any (), namespacedName , gomock .Any ()).SetArg (2 , nc )
134+ cnsRestService .EXPECT ().GetNetworkContainerInternal (cns.GetNetworkContainerRequest {
135+ NetworkContainerid : uuid ,
136+ OrchestratorContext : orchestratorContext ,
137+ }).Return (cns.GetNetworkContainerResponse {}, cnstypes .UnknownContainerID )
138+
139+ cnsRestService .EXPECT ().CreateOrUpdateNetworkContainerInternal (& cns.CreateNetworkContainerRequest {
140+ NetworkContainerid : nc .Spec .UUID ,
141+ OrchestratorContext : orchestratorContext ,
142+ NetworkContainerType : cns .Kubernetes ,
143+ Version : "0" ,
144+ IPConfiguration : cns.IPConfiguration {
145+ IPSubnet : cns.IPSubnet {
146+ IPAddress : nc .Status .IP ,
147+ PrefixLength : 8 ,
148+ },
149+ GatewayIPAddress : nc .Status .Gateway ,
150+ },
151+ PrimaryInterfaceIdentifier : nc .Status .PrimaryInterfaceIdentifier ,
152+ MultiTenancyInfo : cns.MultiTenancyInfo {
153+ EncapType : nc .Status .MultiTenantInfo .EncapType ,
154+ ID : int (nc .Status .MultiTenantInfo .ID ),
155+ },
156+ }).Return (cnstypes .Success )
157+
158+ kubeClient .EXPECT ().Status ().DoAndReturn (func () client.SubResourceWriter {
159+ nc .Status .State = NCStateSucceeded
160+ statusWriter .EXPECT ().Update (gomock .Any (), gomock .Any ()).SetArg (1 , nc )
161+ return statusWriter
162+ })
163+
164+ _ , err = reconciler .Reconcile (context .TODO (), reconcile.Request {
165+ NamespacedName : namespacedName ,
166+ })
167+ Expect (err ).To (BeNil ())
168+ })
169+
106170 It ("Should succeed when the NC is in Initialized state and it has already been persisted in CNS" , func () {
107171 uuid := uuidValue
108172 var nc ncapi.MultiTenantNetworkContainer = ncapi.MultiTenantNetworkContainer {
@@ -168,7 +232,7 @@ var _ = Describe("multiTenantCrdReconciler", func() {
168232 NamespacedName : namespacedName ,
169233 })
170234 Expect (err ).NotTo (BeNil ())
171- Expect (err .Error ()).To (ContainSubstring ("UnknownContainerID " ))
235+ Expect (err .Error ()).To (ContainSubstring ("invalid CIDR address " ))
172236 })
173237
174238 It ("Should succeed when the NC subnet is in correct format" , func () {
0 commit comments