Skip to content

Commit

Permalink
fix for sporadic porch crash during new package revision
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharshabm authored and JamesMcDermott committed Dec 17, 2024
1 parent bff6597 commit a37fa28
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -643,25 +643,21 @@ func (r *PackageVariantReconciler) deletePackageRevision(ctx context.Context, pr

// determine if the downstream PR needs to be updated
func (r *PackageVariantReconciler) isUpToDate(pv *api.PackageVariant, downstream *porchapi.PackageRevision) bool {
if downstream.Status != nil && downstream.Status.UpstreamLock != nil {
upstreamLock := downstream.Status.UpstreamLock
if upstreamLock.Git != nil && upstreamLock.Git.Ref != nil {
lastIndex := strings.LastIndex(upstreamLock.Git.Ref, "/")
if strings.HasPrefix(upstreamLock.Git.Ref, "drafts") {
// The current upstream is a draft, and the target upstream
// will always be a published revision, so we will need to do an update.
return false
}
currentUpstreamRevision := upstreamLock.Git.Ref[lastIndex+1:]
return currentUpstreamRevision == pv.Spec.Upstream.Revision
} else {
klog.Warningf("status.upstreamLock.git or status.upstreamLock.git.ref is nil for PackageRevision %s.", pv.ObjectMeta.Name)
return true
}
} else {
klog.Warningf("status or status.upstreamLock is nil for PackageRevision %s.", pv.ObjectMeta.Name)
if downstream.Status.UpstreamLock == nil {
klog.Warningf("status.upstreamLock is nil for PackageRevision %s.", pv.ObjectMeta.Name)
return true
}
upstreamLock := downstream.Status.UpstreamLock
if upstreamLock.Git == nil || upstreamLock.Git.Ref == "" {
klog.Warningf("status.upstreamLock.git or status.upstreamLock.git.ref is nil for PackageRevision %s.", pv.ObjectMeta.Name)
return true
}
lastIndex := strings.LastIndex(upstreamLock.Git.Ref, "/")
if strings.HasPrefix(upstreamLock.Git.Ref, "drafts") {
// The current upstream is a draft, and the target upstream
// will always be a published revision, so we will need to do an update.
return false
}
}

func (r *PackageVariantReconciler) copyPublished(ctx context.Context,
Expand Down

0 comments on commit a37fa28

Please sign in to comment.