Skip to content

Commit

Permalink
NO-ISSUE: fix 'object has been modified' error in kube-api subsystem (#…
Browse files Browse the repository at this point in the history
…6880)

Similar to #6850,
fixed timing issue in kube-api test on BMH update.
Also, removed BMH finalizers on cleanup.
  • Loading branch information
danielerez authored Oct 14, 2024
1 parent b420506 commit 3b752de
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions subsystem/kubeapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,15 @@ func deployBMHCRD(ctx context.Context, client k8sclient.Client, id string, spec
err := client.Create(ctx, &bmh)
Expect(err).To(BeNil())

bmh.Status.Provisioning.State = metal3_v1alpha1.StateReady
Expect(client.Status().Update(ctx, &bmh)).To(BeNil())
bmhKey := types.NamespacedName{
Namespace: bmh.ObjectMeta.Namespace,
Name: bmh.ObjectMeta.Name,
}
Eventually(func() error {
bmh = *getBmhCRD(ctx, client, bmhKey)
bmh.Status.Provisioning.State = metal3_v1alpha1.StateReady
return client.Status().Update(ctx, &bmh)
}, "30s", "10s").Should(BeNil())
}

func deployPPICRD(ctx context.Context, client k8sclient.Client, name string, spec *metal3_v1alpha1.PreprovisioningImageSpec) {
Expand Down Expand Up @@ -980,11 +987,24 @@ func cleanUpCRs(ctx context.Context, client k8sclient.Client) {
Eventually(func() error {
return client.DeleteAllOf(ctx, &v1beta1.Agent{}, k8sclient.InNamespace(Options.Namespace))
}, "1m", "2s").Should(BeNil())
Eventually(func() error {
return client.DeleteAllOf(ctx, &metal3_v1alpha1.PreprovisioningImage{}, k8sclient.InNamespace(Options.Namespace))
}, "1m", "2s").Should(BeNil())
Eventually(func() error {
return client.DeleteAllOf(ctx, &metal3_v1alpha1.BareMetalHost{}, k8sclient.InNamespace(Options.Namespace))
}, "1m", "2s").Should(BeNil())
Eventually(func() error {
return client.DeleteAllOf(ctx, &metal3_v1alpha1.PreprovisioningImage{}, k8sclient.InNamespace(Options.Namespace))
var err error
bareMetalHostList := &metal3_v1alpha1.BareMetalHostList{}
err = client.List(ctx, bareMetalHostList, k8sclient.InNamespace(Options.Namespace))
Expect(err).To(BeNil())
// Remove finalizers to avoid stuck BMHs
funk.ForEach(bareMetalHostList.Items, func(bmh metal3_v1alpha1.BareMetalHost) {
patch := k8sclient.MergeFrom(bmh.DeepCopy())
bmh.ObjectMeta.Finalizers = nil
err = client.Patch(ctx, &bmh, patch)
})
return err
}, "1m", "2s").Should(BeNil())

// Check if tests pull secret exists and needs to be deleted
Expand Down

0 comments on commit 3b752de

Please sign in to comment.