Skip to content

Commit

Permalink
Add more logging when PackageRev CRs are deleted (#3946)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent authored May 9, 2023
1 parent 47a6f8d commit ff6a1dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions porch/pkg/cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func (r *cachedRepository) Close() error {
// There isn't really any correct way to handle finalizers here. We are removing
// the repository, so we have to just delete the PackageRevision regardless of any
// finalizers.
klog.Infof("Deleting packagerev %s/%s because repository is closed", nn.Namespace, nn.Name)
pkgRevMeta, err := r.metadataStore.Delete(context.TODO(), nn, true)
if err != nil {
// There isn't much use in returning an error here, so we just log it
Expand Down Expand Up @@ -442,6 +443,8 @@ func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[re
// PackageRevision. The ones that doesn't is removed.
for _, prm := range existingPkgRevCRs {
if _, found := newPackageRevisionNames[prm.Name]; !found {
klog.Infof("Deleting PackageRev %s/%s because parent PackageRevision was not found",
prm.Namespace, prm.Name)
if _, err := r.metadataStore.Delete(ctx, types.NamespacedName{
Name: prm.Name,
Namespace: prm.Namespace,
Expand Down Expand Up @@ -489,12 +492,15 @@ func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[re
}
}

// Send notifications for packages that was deleted in the SoT
for k, oldPackage := range oldPackageRevisions {
if newPackageRevisionMap[k] == nil {
nn := types.NamespacedName{
Name: oldPackage.KubeObjectName(),
Namespace: oldPackage.KubeObjectNamespace(),
}
klog.Infof("Deleting PackageRev %s/%s because PackageRevision was removed from SoT",
nn.Namespace, nn.Name)
metaPackage, err := r.metadataStore.Delete(ctx, nn, true)
if err != nil {
klog.Warningf("Error deleting PkgRevMeta %s: %v")
Expand Down
4 changes: 4 additions & 0 deletions porch/pkg/meta/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -134,6 +135,7 @@ func (c *crdMetadataStore) Create(ctx context.Context, pkgRevMeta PackageRevisio
OwnerReferences: ownerReferences,
},
}
klog.Infof("Creating packagerev %s/%s", internalPkgRev.Namespace, internalPkgRev.Name)
if err := c.coreClient.Create(ctx, &internalPkgRev); err != nil {
if apierrors.IsAlreadyExists(err) {
return c.Update(ctx, pkgRevMeta)
Expand Down Expand Up @@ -180,6 +182,7 @@ func (c *crdMetadataStore) Update(ctx context.Context, pkgRevMeta PackageRevisio
internalPkgRev.OwnerReferences = ownerReferences
internalPkgRev.Finalizers = append(pkgRevMeta.Finalizers, PkgRevisionFinalizer)

klog.Infof("Updating packagerev %s/%s", internalPkgRev.Namespace, internalPkgRev.Name)
if err := c.coreClient.Update(ctx, &internalPkgRev); err != nil {
return PackageRevisionMeta{}, err
}
Expand All @@ -203,6 +206,7 @@ func (c *crdMetadataStore) Delete(ctx context.Context, namespacedName types.Name
}
}

klog.Infof("Deleting packagerev %s/%s", internalPkgRev.Namespace, internalPkgRev.Name)
if err := c.coreClient.Delete(ctx, &internalPkgRev); err != nil {
return PackageRevisionMeta{}, err
}
Expand Down

0 comments on commit ff6a1dd

Please sign in to comment.