@@ -958,6 +958,32 @@ func TestPatchHelper(t *testing.T) {
958
958
959
959
g .Expect (patcher .Patch (ctx , machineSet )).NotTo (Succeed ())
960
960
})
961
+
962
+ t .Run ("Should not error if there are no finalizers and deletion timestamp is not nil" , func (t * testing.T ) {
963
+ g := NewWithT (t )
964
+ cluster := & clusterv1.Cluster {
965
+ ObjectMeta : metav1.ObjectMeta {
966
+ Name : "test-cluster" ,
967
+ Namespace : ns .Name ,
968
+ Finalizers : []string {"block-deletion" },
969
+ },
970
+ Status : clusterv1.ClusterStatus {},
971
+ }
972
+ key := client.ObjectKey {Name : cluster .GetName (), Namespace : cluster .GetNamespace ()}
973
+ g .Expect (env .Create (ctx , cluster )).To (Succeed ())
974
+ g .Expect (env .Delete (ctx , cluster )).To (Succeed ())
975
+
976
+ // Ensure cluster still exists & get Cluster with deletionTimestamp set
977
+ g .Expect (env .Get (ctx , key , cluster )).To (Succeed ())
978
+
979
+ // Patch helper will first remove the finalizer and then it will get a not found error when
980
+ // trying to patch status. This test validates that the not found error is ignored.
981
+ patcher , err := NewHelper (cluster , env )
982
+ g .Expect (err ).ToNot (HaveOccurred ())
983
+ cluster .Finalizers = []string {}
984
+ cluster .Status .Phase = "Running"
985
+ g .Expect (patcher .Patch (ctx , cluster )).To (Succeed ())
986
+ })
961
987
}
962
988
963
989
func TestNewHelperNil (t * testing.T ) {
0 commit comments