Skip to content

Commit

Permalink
Merge pull request #99 from Nordix/metaData-Store-OwnerRefs
Browse files Browse the repository at this point in the history
#798 - PackageReivsion deletionProposed sometimes deletes the packageRevision
  • Loading branch information
kispaljr authored Sep 5, 2024
2 parents b81a03e + 644f2c8 commit 8a1c5fd
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pkg/cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,24 @@ func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[re
}
}

// Send notification for packages that changed before the creation of PkgRev to avoid race conditions because of ownerReferences.
addSent := 0
modSent := 0
for kname, newPackage := range newPackageRevisionNames {
oldPackage := oldPackageRevisionNames[kname]
metaPackage, found := existingPkgRevCRsMap[newPackage.KubeObjectName()]
if !found {
klog.Warningf("no PackageRev CR found for PackageRevision %s", newPackage.KubeObjectName())
}
if oldPackage == nil {
addSent += r.objectNotifier.NotifyPackageRevisionChange(watch.Added, newPackage, metaPackage)
} else {
if oldPackage.ResourceVersion() != newPackage.ResourceVersion() {
modSent += r.objectNotifier.NotifyPackageRevisionChange(watch.Modified, newPackage, metaPackage)
}
}
}

// We go through all the PackageRevisions and make sure they have
// a corresponding PackageRev CR.
for pkgRevName, pkgRev := range newPackageRevisionNames {
Expand All @@ -490,24 +508,6 @@ func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[re
}
}

// Send notification for packages that changed.
addSent := 0
modSent := 0
for kname, newPackage := range newPackageRevisionNames {
oldPackage := oldPackageRevisionNames[kname]
metaPackage, found := existingPkgRevCRsMap[newPackage.KubeObjectName()]
if !found {
klog.Warningf("no PackageRev CR found for PackageRevision %s", newPackage.KubeObjectName())
}
if oldPackage == nil {
addSent += r.objectNotifier.NotifyPackageRevisionChange(watch.Added, newPackage, metaPackage)
} else {
if oldPackage.ResourceVersion() != newPackage.ResourceVersion() {
modSent += r.objectNotifier.NotifyPackageRevisionChange(watch.Modified, newPackage, metaPackage)
}
}
}

delSent := 0
// Send notifications for packages that was deleted in the SoT
for kname, oldPackage := range oldPackageRevisionNames {
Expand Down

0 comments on commit 8a1c5fd

Please sign in to comment.