diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/injection.go b/controllers/packagevariants/pkg/controllers/packagevariant/injection.go index edad6a32..3fbf859d 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/injection.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/injection.go @@ -1,4 +1,4 @@ -// Copyright 2023 The kpt and Nephio Authors +// Copyright 2023-2024 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go index 95774ae2..8b2dda28 100644 --- a/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go +++ b/controllers/packagevariants/pkg/controllers/packagevariant/packagevariant_controller.go @@ -1,4 +1,4 @@ -// Copyright 2022 The kpt and Nephio Authors +// Copyright 2023-2024 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -596,7 +596,15 @@ 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.UpstreamLock == nil { + klog.Warningf("status.upstreamLock field is empty/missing in downstream 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 field is empty/missing in downstream 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