Operator-sdk: Generate custom controller using native k8s resources.

Created on 16 Jan 2019  路  8Comments  路  Source: operator-framework/operator-sdk

Feature Request

Is your feature request related to a problem? Please describe.
I want to create a custom controller using native resource like I want to watch for Event for that is there any way to create controller using operator-sdk. To create one Controller we need to pass api group, api version, resource kind. In my case Event belongs to core/v1 native group. I am not able to pass those arguments using flag.

Describe the solution you'd like
There should be some way to create custom controller using native resources.

kinbug

Most helpful comment

@joelanford if we're going to support adding controllers for kubernetes-provided API we should require a --k8s-api boolean flag be passed to add controller. Additionally an optional --k8s-import-path flag would be nice for API import paths with multiple domains or that are different than k8s.io/api. By default we can assume k8s.io/api since this will be the use case most of the time.

All 8 comments

@LiliC Can I contribute to operator-sdk with this issue. If yes I need your guidance.
Thank You.

@shovanmaity if I understand correctly you want to watch k8s upstream native objects?

Yes @LiliC .

@imazik had the same use case and same failure with v0.7.0. However this looks to be allowed now on master. See #1313

I ran go run $GOPATH/src/github.com/operator-framework/operator-sdk/commands/operator-sdk/main.go add controller --api-version=apps/v1 --kind=Deployment without errors so far

Yes this is fixed on the master and should be in the next release. Thanks for confirming @PhilipGough

@hasbro17 @estroz I tried this out and noticed that the scaffolded controller has an import for an api package that doesn't exist, so an additional change is required in pkg/controller/<kind>/<kind>_controller.go to update the API import from a local, non-existent package to the correct k8s.io/api package.

Is there a good way for us to check if the API is a kubernetes-provided API? And if so, to derive its import path?

Looking at the output of kubectl api-resources, I see four patterns:

  • Empty string maps to k8s.io/core
  • Single domain segment group maps to k8s.io/group
  • Multi-domain segment with .k8s.io suffix maps to k8s.io/<firstSegment>
  • Everything else is provided by an external CRD

Is it reasonable to include this mapping logic in our controller scaffolding?

@joelanford if we're going to support adding controllers for kubernetes-provided API we should require a --k8s-api boolean flag be passed to add controller. Additionally an optional --k8s-import-path flag would be nice for API import paths with multiple domains or that are different than k8s.io/api. By default we can assume k8s.io/api since this will be the use case most of the time.

Created #1343 to track the follow-on updates.

Was this page helpful?
0 / 5 - 0 ratings