@@ -78,8 +78,8 @@ var _ = Describe("NetworkInterfaceEphemeralVirtualIP", func() {
7878 })),
7979 ))
8080 })
81- It ("should verify ownerRef is set for ephemeral virtual IPs based on ReclaimPolicy " , func (ctx SpecContext ) {
82- By ("creating a network interface with an ephemeral virtual IP" )
81+ It ("should verify ownerRef is updated based on ReclaimPolicyType for ephemeral virtualIP " , func (ctx SpecContext ) {
82+ By ("creating a network interface with an ephemeral virtual IP having ReclaimPolicyType Retain " )
8383 vipSrc := networkingv1alpha1.VirtualIPSource {
8484 Ephemeral : & networkingv1alpha1.EphemeralVirtualIPSource {
8585 VirtualIPTemplate : & networkingv1alpha1.VirtualIPTemplateSpec {
@@ -110,28 +110,103 @@ var _ = Describe("NetworkInterfaceEphemeralVirtualIP", func() {
110110 }
111111 Expect (k8sClient .Create (ctx , nic )).To (Succeed ())
112112
113- By ("waiting for the virtual IP to exist" )
113+ By ("waiting for the virtual IP to exist with empty OwnerRef " )
114114 vip := & networkingv1alpha1.VirtualIP {
115115 ObjectMeta : metav1.ObjectMeta {
116116 Namespace : ns .Name ,
117117 Name : networkingv1alpha1 .NetworkInterfaceVirtualIPName (nic .Name , vipSrc ),
118118 },
119119 }
120- Eventually (Get (vip )).Should (Succeed ())
121- By ("Verifying OwnerRef is not set for ephemeral virtualIP when reclaim policy is retain" )
122- Eventually (Object (vip )).Should (HaveField ("ObjectMeta.OwnerReferences" , BeEmpty ()))
120+ Eventually (Object (vip )).Should (SatisfyAll (
121+ HaveField ("ObjectMeta.OwnerReferences" , BeEmpty ()),
122+ HaveField ("Spec" , networkingv1alpha1.VirtualIPSpec {
123+ Type : networkingv1alpha1 .VirtualIPTypePublic ,
124+ IPFamily : corev1 .IPv4Protocol ,
125+ TargetRef : & commonv1alpha1.LocalUIDReference {
126+ Name : nic .Name ,
127+ UID : nic .UID ,
128+ },
129+ }),
130+ ))
123131
124- By ("Updating reclaim policy to delete " )
132+ By ("Updating reclaim policy to Delete " )
125133 baseNic := nic .DeepCopy ()
126134 nic .Spec .VirtualIP .Ephemeral .VirtualIPTemplate .Spec .ReclaimPolicy = networkingv1alpha1 .ReclaimPolicyTypeDelete
127135 Expect (k8sClient .Patch (ctx , nic , client .MergeFrom (baseNic ))).To (Succeed ())
128- By ("Verifying OwnerRef is updated for ephemeral virtualIP" )
136+
137+ By ("Verifying ephemeral virtualIP is updated with OwnerRef after updating the ReclaimPolicyTypeDelete" )
129138 Eventually (Object (vip )).Should (HaveField ("ObjectMeta.OwnerReferences" , ConsistOf (MatchFields (IgnoreExtras , Fields {
130139 "APIVersion" : Equal (networkingv1alpha1 .SchemeGroupVersion .String ()),
131140 "Kind" : Equal ("NetworkInterface" ),
132141 "Name" : Equal (nic .Name ),
133142 })),
134143 ))
144+
145+ })
146+
147+ It ("should verify ephemeral virutalIP is not deleted having ReclaimPolicyType Retain with nic deletion" , func (ctx SpecContext ) {
148+ By ("creating a network interface with an ephemeral virtual IP" )
149+ vipSrc := networkingv1alpha1.VirtualIPSource {
150+ Ephemeral : & networkingv1alpha1.EphemeralVirtualIPSource {
151+ VirtualIPTemplate : & networkingv1alpha1.VirtualIPTemplateSpec {
152+ Spec : networkingv1alpha1.EphemeralVirtualIPSpec {
153+ ReclaimPolicy : networkingv1alpha1 .ReclaimPolicyTypeRetain ,
154+ VirtualIPSpec : networkingv1alpha1.VirtualIPSpec {
155+ Type : networkingv1alpha1 .VirtualIPTypePublic ,
156+ IPFamily : corev1 .IPv4Protocol ,
157+ },
158+ },
159+ },
160+ },
161+ }
162+ nic := & networkingv1alpha1.NetworkInterface {
163+ ObjectMeta : metav1.ObjectMeta {
164+ Namespace : ns .Name ,
165+ GenerateName : "nic-" ,
166+ },
167+ Spec : networkingv1alpha1.NetworkInterfaceSpec {
168+ NetworkRef : corev1.LocalObjectReference {Name : "my-network" },
169+ IPs : []networkingv1alpha1.IPSource {
170+ {
171+ Value : commonv1alpha1 .MustParseNewIP ("10.0.0.1" ),
172+ },
173+ },
174+ VirtualIP : & vipSrc ,
175+ },
176+ }
177+ Expect (k8sClient .Create (ctx , nic )).To (Succeed ())
178+
179+ By ("waiting for the virtual IP to exist" )
180+ vip := & networkingv1alpha1.VirtualIP {
181+ ObjectMeta : metav1.ObjectMeta {
182+ Namespace : ns .Name ,
183+ Name : networkingv1alpha1 .NetworkInterfaceVirtualIPName (nic .Name , vipSrc ),
184+ },
185+ }
186+ Eventually (Object (vip )).Should (SatisfyAll (
187+ HaveField ("ObjectMeta.OwnerReferences" , BeEmpty ()),
188+ HaveField ("Spec" , networkingv1alpha1.VirtualIPSpec {
189+ Type : networkingv1alpha1 .VirtualIPTypePublic ,
190+ IPFamily : corev1 .IPv4Protocol ,
191+ TargetRef : & commonv1alpha1.LocalUIDReference {
192+ Name : nic .Name ,
193+ UID : nic .UID ,
194+ },
195+ }),
196+ ))
197+
198+ By ("deleting nic" )
199+ Expect (k8sClient .Delete (ctx , nic )).To (Succeed ())
200+
201+ By ("ensuring the nic is deleted" )
202+ nicKey := client.ObjectKey {Namespace : ns .Name , Name : nic .Name }
203+ err := k8sClient .Get (ctx , nicKey , nic )
204+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
205+
206+ By ("ensuring the virtualIP still exists after the nic is deleted" )
207+ vipKey := client.ObjectKey {Namespace : ns .Name , Name : vip .Name }
208+ Expect (k8sClient .Get (ctx , vipKey , vip )).To (Succeed ())
209+
135210 })
136211
137212 It ("should delete undesired virtual IPs for a network interface" , func (ctx SpecContext ) {
0 commit comments