Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/scaffold/manager/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"log"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/apimachinery/pkg/api/meta"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
Expand All @@ -70,12 +71,17 @@ func main() {

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
log.Fatalf("Add apis failed, error: %#v.", err)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
switch err.(type) {
case *meta.NoKindMatchError:
log.Fatalf("No kind %v found, please install CRD in advance.", err.(*meta.NoKindMatchError).GroupKind)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should add more context in the error in the controller-runtime library itself instead of putting the logic in generated code, WDYT ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts:
Generally, lib (controller-tools) emits all errors and client (kubebuilder) decides what behavior to perform. Based on this point, my PR make sense.

But considering our client code is generated, more concise the better. I think to handle this error in controller-tools is also a good idea. Do you have some ideas about which code should I modify?

Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@droot just a ping, any thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't follow this thread.

Actually, our client code is no longer generated. Kubebuilder project uses client pkg from https://github.com/kubernetes-sigs/controller-runtime. May be, we can just wrap the error when returning from client's pkg. Can you pl. investigate.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will check later.
I will ping you if have some problems. Thanks.

default:
log.Fatalf("Add controller failed, error: %#v.", err)
}
}

log.Printf("Starting the Cmd.")
Expand Down
10 changes: 8 additions & 2 deletions test/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"log"

"k8s.io/apimachinery/pkg/api/meta"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -44,12 +45,17 @@ func main() {

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
log.Fatalf("Add apis failed, error: %#v.", err)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
switch err.(type) {
case *meta.NoKindMatchError:
log.Fatalf("No kind %v found, please install CRD in advance.", err.(*meta.NoKindMatchError).GroupKind)
default:
log.Fatalf("Add controller failed, error: %#v.", err)
}
}

log.Printf("Starting the Cmd.")
Expand Down