Merge pull request #4369 from irbekrm/improve_owner_not_found_errors

Improve owner not found errors
This commit is contained in:
jetstack-bot 2021-08-18 17:23:29 +01:00 committed by GitHub
commit bea6c20e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -20,6 +20,7 @@ go_library(
"//pkg/logs:go_default_library",
"//pkg/metrics:go_default_library",
"@com_github_go_logr_logr//:go_default_library",
"@io_k8s_apimachinery//pkg/api/errors:go_default_library",
"@io_k8s_apimachinery//pkg/api/resource:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/schema:go_default_library",

View File

@ -22,6 +22,7 @@ import (
"time"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/runtime"
@ -74,13 +75,20 @@ func HandleOwnedResourceNamespacedFunc(log logr.Logger, queue workqueue.RateLimi
}
if refGV.Group == ownerGVK.Group && ref.Kind == ownerGVK.Kind {
// TODO: how to handle namespace of owner references?
order, err := get(metaobj.GetNamespace(), ref.Name)
if err != nil {
log.Error(err, "error getting referenced owning resource")
obj, err := get(metaobj.GetNamespace(), ref.Name)
// This function is always called with a getter
// that gets from informers cache. Because this
// is also called on cache sync it may be that
// the owner is not yet in the cache.
if err != nil && errors.IsNotFound(err) {
log.Info("owning resource not found in cache")
continue
}
objKey, err := KeyFunc(order)
if err != nil {
log.Error(err, "error getting referenced owning resource from cache")
continue
}
objKey, err := KeyFunc(obj)
if err != nil {
log.Error(err, "error computing key for resource")
continue