Skip to content

Commit

Permalink
Add ownerReferences after pkgrev creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kushnaidu committed Aug 16, 2024
1 parent 23d62c2 commit b84923e
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions pkg/meta/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,15 @@ func (c *crdMetadataStore) Create(ctx context.Context, pkgRevMeta PackageRevisio
}
labels[PkgRevisionRepoLabel] = repoName

ownerReferences := append(pkgRevMeta.OwnerReferences, metav1.OwnerReference{
APIVersion: packageRevisionGVK.GroupVersion().String(),
Kind: packageRevisionGVK.Kind,
Name: pkgRevMeta.Name,
UID: pkgRevUID,
})

finalizers := append(pkgRevMeta.Finalizers, PkgRevisionFinalizer)

internalPkgRev := internalapi.PackageRev{
ObjectMeta: metav1.ObjectMeta{
Name: pkgRevMeta.Name,
Namespace: pkgRevMeta.Namespace,
Labels: labels,
Annotations: pkgRevMeta.Annotations,
Finalizers: finalizers,
OwnerReferences: ownerReferences,
Name: pkgRevMeta.Name,
Namespace: pkgRevMeta.Namespace,
Labels: labels,
Annotations: pkgRevMeta.Annotations,
Finalizers: finalizers,
},
}
klog.Infof("Creating packagerev %s/%s", internalPkgRev.Namespace, internalPkgRev.Name)
Expand All @@ -142,6 +134,29 @@ func (c *crdMetadataStore) Create(ctx context.Context, pkgRevMeta PackageRevisio
}
return PackageRevisionMeta{}, err
}

namespacedName := types.NamespacedName{
Name: pkgRevMeta.Name,
Namespace: pkgRevMeta.Namespace,
}
// Add owner references after creation to elimiate the possibility of the garbage-collector
// adding deletionTimestamps to main package revisions after an approve
err := c.coreClient.Get(ctx, namespacedName, &internalPkgRev)
if err != nil {
return PackageRevisionMeta{}, err
}

ownerReferences := append(pkgRevMeta.OwnerReferences, metav1.OwnerReference{
APIVersion: packageRevisionGVK.GroupVersion().String(),
Kind: packageRevisionGVK.Kind,
Name: pkgRevMeta.Name,
UID: pkgRevUID,
})
internalPkgRev.OwnerReferences = ownerReferences
if err := c.coreClient.Update(ctx, &internalPkgRev); err != nil {
return PackageRevisionMeta{}, err
}

return toPackageRevisionMeta(&internalPkgRev), nil
}

Expand Down Expand Up @@ -232,7 +247,6 @@ func toPackageRevisionMeta(internalPkgRev *internalapi.PackageRev) PackageRevisi
finalizers = append(finalizers, f)
}
}

return PackageRevisionMeta{
Name: internalPkgRev.Name,
Namespace: internalPkgRev.Namespace,
Expand Down

0 comments on commit b84923e

Please sign in to comment.