Skip to content

Commit fa9b243

Browse files
authored
Merge pull request #15 from DWSR/handle-custom-controller-kinds
fix: make findOwners handle custom types better
2 parents 623b844 + 4776e71 commit fa9b243

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

components/migrations.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
kerrors "k8s.io/apimachinery/pkg/api/errors"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/labels"
33+
"k8s.io/apimachinery/pkg/runtime"
3334
"k8s.io/apimachinery/pkg/runtime/schema"
3435
"k8s.io/apimachinery/pkg/types"
3536
ctrl "sigs.k8s.io/controller-runtime"
@@ -311,11 +312,19 @@ func (_ *migrationsComponent) findOwners(ctx *cu.Context, obj cu.Object) ([]cu.O
311312
gvk := schema.FromAPIVersionAndKind(ref.APIVersion, ref.Kind)
312313
ownerObj, err := ctx.Scheme.New(gvk)
313314
if err != nil {
315+
// Gracefully handle kinds that we haven't registered. Useful when a Rollout or Deployment is
316+
// owned by someone's in-house operator
317+
if runtime.IsNotRegisteredError(err) {
318+
break
319+
}
314320
return nil, errors.Wrapf(err, "error finding object type for owner reference %v", ref)
315321
}
316322
err = ctx.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: namespace}, ownerObj)
317323
if err != nil {
318-
// TODO IMPORTANT If this is a 403, don't bubble up the error. Probably a custom type we don't have access to, just pretend it's not there.
324+
// Gracefully handle objects we don't have access to
325+
if kerrors.IsForbidden(err) {
326+
break
327+
}
319328
return nil, errors.Wrapf(err, "error finding object type for owner reference %v", ref)
320329
}
321330
obj = ownerObj.(cu.Object)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy