Skip to content

Commit

Permalink
Merge pull request #704 from Nordix/lentzi90/revert-ownerref-removal
Browse files Browse the repository at this point in the history
🌱 Don't remove ownerRef from IPClaim when deleting
  • Loading branch information
metal3-io-bot authored Sep 5, 2022
2 parents 0f32822 + 20e1796 commit d013b94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
14 changes: 0 additions & 14 deletions baremetal/metal3data_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,20 +537,6 @@ func (m *DataManager) releaseAddressFromM3Pool(ctx context.Context, poolRef core

// Remove finalizer from Metal3IPClaim since we no longer need it
ipClaim.Finalizers = Filter(ipClaim.Finalizers, infrav1.DataFinalizer)
// Remove Metal3Data ownerRef
newOwnerRefs := []metav1.OwnerReference{}
for _, ownerRef := range ipClaim.OwnerReferences {
oGV, err := schema.ParseGroupVersion(ownerRef.APIVersion)
if err != nil {
return err
}
if ownerRef.Kind == "Metal3Data" && oGV.Group == infrav1.GroupVersion.Group {
continue
} else {
newOwnerRefs = append(newOwnerRefs, ownerRef)
}
}
ipClaim.OwnerReferences = newOwnerRefs
err = updateObject(ctx, m.client, ipClaim)
if err != nil {
return err
Expand Down
15 changes: 6 additions & 9 deletions baremetal/metal3data_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,8 @@ var _ = Describe("Metal3Data manager", func() {
if tc.injectDeleteErr {
// There was an error deleting the claim, so we expect it to still be there
Expect(err).To(BeNil())
// We expect the ownerRef to be gone
Expect(capm3IPClaim.OwnerReferences).To(BeEmpty())
// We expect the finalizer to be gone
Expect(capm3IPClaim.Finalizers).To(BeEmpty())
} else {
Expect(err).To(HaveOccurred())
Expect(apierrors.IsNotFound(err)).To(BeTrue())
Expand All @@ -1356,7 +1356,7 @@ var _ = Describe("Metal3Data manager", func() {
},
poolRef: corev1.TypedLocalObjectReference{Name: "abc"},
}),
Entry("Deletion error and ownerRef removal", testCaseReleaseAddressFromPool{
Entry("Deletion error and finalizer removal", testCaseReleaseAddressFromPool{
m3d: &infrav1.Metal3Data{
ObjectMeta: testObjectMeta(metal3DataName, namespaceName, ""),
TypeMeta: metav1.TypeMeta{
Expand All @@ -1367,12 +1367,9 @@ var _ = Describe("Metal3Data manager", func() {
poolRef: corev1.TypedLocalObjectReference{Name: testPoolName},
ipClaim: &ipamv1.IPClaim{
ObjectMeta: metav1.ObjectMeta{
Name: metal3DataName + "-" + testPoolName,
Namespace: namespaceName,
OwnerReferences: []metav1.OwnerReference{{
Kind: "Metal3Data",
APIVersion: infrav1.GroupVersion.Group + "/" + infrav1.GroupVersion.Version,
}},
Name: metal3DataName + "-" + testPoolName,
Namespace: namespaceName,
Finalizers: []string{infrav1.DataFinalizer},
},
},
injectDeleteErr: true,
Expand Down

0 comments on commit d013b94

Please sign in to comment.