@@ -23,6 +23,7 @@ import (
2323
2424 "github.com/linode/linodego"
2525 "go.uber.org/mock/gomock"
26+ apierrors "k8s.io/apimachinery/pkg/api/errors"
2627 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728 "sigs.k8s.io/cluster-api/util/patch"
2829 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -135,7 +136,7 @@ var _ = Describe("lifecycle", Ordered, Label("placementgroup", "lifecycle"), fun
135136 res , err := reconciler .reconcile (ctx , mck .Logger (), & pgScope )
136137 Expect (err ).NotTo (HaveOccurred ())
137138 Expect (res .RequeueAfter ).To (Equal (rec .DefaultPGControllerReconcilerDelay ))
138- Expect (mck .Logs ()).To (ContainSubstring ("Failed to fetch Placement Group" ))
139+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to fetch Placement Group from API " ))
139140 })),
140141 Path (Result ("timeout error" , func (ctx context.Context , mck Mock ) {
141142 reconciler .ReconcileTimeout = time .Nanosecond
@@ -160,7 +161,7 @@ var _ = Describe("lifecycle", Ordered, Label("placementgroup", "lifecycle"), fun
160161 res , err := reconciler .reconcile (ctx , mck .Logger (), & pgScope )
161162 Expect (err ).NotTo (HaveOccurred ())
162163 Expect (res .RequeueAfter ).To (Equal (rec .DefaultPGControllerReconcilerDelay ))
163- Expect (mck .Logs ()).To (ContainSubstring ("Failed to delete Placement Group" ))
164+ Expect (mck .Logs ()).To (ContainSubstring ("Failed to delete Placement Group via API " ))
164165 })),
165166 Path (Result ("timeout error" , func (ctx context.Context , mck Mock ) {
166167 reconciler .ReconcileTimeout = time .Nanosecond
@@ -190,14 +191,38 @@ var _ = Describe("lifecycle", Ordered, Label("placementgroup", "lifecycle"), fun
190191 }, nil )
191192 }),
192193 OneOf (
193- Path (Result ("requeues delete" , func (ctx context.Context , mck Mock ) {
194+ Path (Result ("delete requeues " , func (ctx context.Context , mck Mock ) {
194195 res , err := reconciler .reconcile (ctx , mck .Logger (), & pgScope )
195196 Expect (err ).NotTo (HaveOccurred ())
196197 Expect (res .RequeueAfter ).To (Equal (rec .DefaultPGControllerReconcilerDelay ))
197- Expect (mck .Logs ()).To (ContainSubstring ("re-queuing deletion to wait for detachment" ))
198+ Expect (mck .Logs ()).To (ContainSubstring ("Placement Group has node(s) attached, re-queuing deletion to wait for detachment" ))
199+ })),
200+ Path (Result ("timeout error" , func (ctx context.Context , mck Mock ) {
201+ reconciler .ReconcileTimeout = time .Nanosecond
202+ res , err := reconciler .reconcile (ctx , mck .Logger (), & pgScope )
203+ Expect (err ).To (HaveOccurred ())
204+ Expect (res .RequeueAfter ).To (Equal (time .Duration (0 )))
205+ Expect (mck .Events ()).To (ContainSubstring ("Will not delete Placement Group" ))
198206 })),
199207 ),
200208 ),
209+ Path (
210+ Call ("with no nodes attached" , func (ctx context.Context , mck Mock ) {
211+ getPG := mck .LinodeClient .EXPECT ().GetPlacementGroup (ctx , gomock .Any ()).Return (& linodego.PlacementGroup {
212+ ID : 1 ,
213+ Label : "pg1" ,
214+ Region : "us-east" ,
215+ Members : []linodego.PlacementGroupMember {},
216+ }, nil )
217+ mck .LinodeClient .EXPECT ().DeletePlacementGroup (ctx , gomock .Any ()).After (getPG ).Return (nil )
218+ }),
219+ Result ("delete success" , func (ctx context.Context , mck Mock ) {
220+ res , err := reconciler .reconcile (ctx , mck .Logger (), & pgScope )
221+ Expect (err ).NotTo (HaveOccurred ())
222+ Expect (res .RequeueAfter ).To (Equal (time .Duration (0 )))
223+ Expect (apierrors .IsNotFound (k8sClient .Get (ctx , objectKey , & linodePG ))).To (BeTrue ())
224+ }),
225+ ),
201226 ),
202227 )
203228})
0 commit comments