Skip to content

Commit cd4ab3c

Browse files
intermainterma
authored and
interma
committed
Prompt to install CRD when Kind no found
1 parent 3db8d34 commit cd4ab3c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/source/source.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"fmt"
2121
"sync"
2222

23+
"github.com/pkg/errors"
24+
25+
"k8s.io/apimachinery/pkg/api/meta"
2326
"k8s.io/apimachinery/pkg/runtime"
2427
"k8s.io/client-go/util/workqueue"
2528
"sigs.k8s.io/controller-runtime/pkg/event"
@@ -62,6 +65,7 @@ type Kind struct {
6265

6366
var _ Source = &Kind{}
6467

68+
6569
// Start is internal and should be called only by the Controller to register an EventHandler with the Informer
6670
// to enqueue reconcile.Requests.
6771
func (ks *Kind) Start(handler handler.EventHandler, queue workqueue.RateLimitingInterface,
@@ -80,7 +84,13 @@ func (ks *Kind) Start(handler handler.EventHandler, queue workqueue.RateLimiting
8084
// Lookup the Informer from the Cache and add an EventHandler which populates the Queue
8185
i, err := ks.cache.GetInformer(ks.Type)
8286
if err != nil {
83-
return err
87+
switch err.(type) {
88+
case *meta.NoKindMatchError:
89+
return errors.Wrapf(err, "if %s is a CRD, should install it before calling Start",
90+
err.(*meta.NoKindMatchError).GroupKind)
91+
default:
92+
return err
93+
}
8494
}
8595
i.AddEventHandler(internal.EventHandler{Queue: queue, EventHandler: handler, Predicates: prct})
8696
return nil

0 commit comments

Comments
 (0)