-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register direct controller in init() #1910
Register direct controller in init() #1910
Conversation
ee939db
to
c97f73d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is no longer needed since the direct controller e2e test will be covered in tests-e2e-fixtures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to turn on the golden checks in tests-e2e-fixtures? That's the big advantage of these tests, they are actually much stricter....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to turn on the golden checks in tests-e2e-fixtures?
I think we should. Do you happen to know why we don't add the golden check in tests-e2e-fixtures previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to turn on the stricter golden check on the generic e2e fixtures (that would be in a separate PR). Right now, I put back the direct e2e path.
c97f73d
to
f3f8760
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a few nits/suggestions
@@ -5,10 +5,10 @@ metadata: | |||
cnrm.cloud.google.com/version: 0.0.0-dev | |||
creationTimestamp: null | |||
labels: | |||
cnrm.cloud.google.com/directcrd: "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: cnrm.cloud.google.com/direct
(it's the controller that's direct, not really the CRD). Or it could just the default if we don't specify tf2crd or dcl2crd ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change this to "cnrm.cloud.google.com/direct". And +1 to make the direct as default eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rethink about this. I think we can be more "direct aggressive" here (and we should be good if we do):
- By default we expect a resource to use direct controller
- if to use TF/DCL controller, the CRD has to have the corresponding label.(current behavior)
func AddKeyReconciler(mgr manager.Manager, config *controller.Config, opts directbase.Deps) error { | ||
gvk := krm.APIKeysKeyGVK | ||
func init() { | ||
directbase.ControllerBuilder.RegisterModel(krm.APIKeysKeyGVK, NewModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
@@ -247,6 +221,14 @@ func registerDefaultController(r *ReconcileRegistration, config *controller.Conf | |||
} | |||
|
|||
default: | |||
// register controllers for direct CRDs | |||
if val, ok := crd.Labels[k8s.DirectCRDLabel]; ok && val == "true" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be easier to have a directbase.ControllerBuilder.IsDirect
helper, than to require the additional label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a preference. This is just to keep the same code style as below (line 232 and line 241).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so as the function name "Add" vs "AddController"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to turn on the golden checks in tests-e2e-fixtures? That's the big advantage of these tests, they are actually much stricter....
I noticed the vcr test failed due to test timeout on "apikeyskey". Unsure if that's related to this PR, but we can fix it by
|
apis/apikeys/v1alpha1/apikey_type.go
Outdated
@@ -41,7 +41,7 @@ var ( | |||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | |||
// +kubebuilder:resource:categories=gcp,shortName=gcpapikeyskey;gcpapikeyskeys | |||
// +kubebuilder:subresource:status | |||
// +kubebuilder:metadata:labels="cnrm.cloud.google.com/tf2crd=true";"cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/stability-level=alpha";"cnrm.cloud.google.com/system=true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, can we still have resources in transition? For instance, for ApiKey AFAICT, we didn't actually make the switch to a direct CRD but I could be wrong.
What I like about the current state of the world is that we can turn on TF/ DCL based resources to use the DirectController via the feature flag (KCC_USE_DIRECT_RECONCILERS
) and have developers iterate between the behavior of a TF/ DCL based controller and a direct one. Can we preserve that somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, can we still have resources in transition?
Yes, we can. The KCC_USE_DIRECT_RECONCILERS should still work as it is.
.github/workflows/presubmit.yaml
Outdated
go-version-file: 'go.mod' | ||
- name: "run tests-e2e-direct" | ||
run: | | ||
./scripts/github-actions/tests-e2e-direct.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the end state we don't have direct
tests specifically but I think these can be useful for folks, especially as they iterate on a resource conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The KCC_USE_DIRECT_RECONCILERS flag shall still work (which gives developers the testing approach during the resource conversion). For release, we can purely rely on the CRD annotations to tell whether a direct or TF controller shall manage a resource kind (and eventually direct will be the default so it does not need a annotation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I'm not sure (as @justinsb pointed out) is that if we can turn on golden checks for all e2e-fixture tests. Maybe we can try the strict rules and see how big the fix need to be. But anyways, I plan to keep the tests-e2e-dierct.sh for now until the generic e2e has the golden check.
df62dc3
to
0483854
Compare
@@ -196,44 +192,17 @@ func registerDefaultController(r *ReconcileRegistration, config *controller.Conf | |||
JitterGen: r.jitterGenerator, | |||
Defaulters: r.defaulters, | |||
} | |||
|
|||
var schemaUpdater k8s.SchemaReferenceUpdater | |||
if kccfeatureflags.UseDirectReconciler(gvk.GroupKind()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note for reviewers: The previous code only turn on LLM in direct controller, all other resources that already have direct controller and API are only turning on via the KCC_USE_DIRECT_RECONCILERS
flag.
When those resources are ready for direct controller, we can simply remove their "cnrm.cloud.google.com/tf2crd=true"
label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
6b2a985
to
5794e45
Compare
5794e45
to
9a749a4
Compare
@@ -196,44 +192,17 @@ func registerDefaultController(r *ReconcileRegistration, config *controller.Conf | |||
JitterGen: r.jitterGenerator, | |||
Defaulters: r.defaulters, | |||
} | |||
|
|||
var schemaUpdater k8s.SchemaReferenceUpdater | |||
if kccfeatureflags.UseDirectReconciler(gvk.GroupKind()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
|
||
return directbase.NewReconciler(r.mgr, immediateReconcileRequests, resourceWatcherRoutines, loggingapis.LoggingLogMetricGVK, m, jg) | ||
if directbase.ControllerBuilder.IsDirectByCRD(crd) { | ||
return directbase.ControllerBuilder.NewReconciler(r.mgr, &kcccontroller.Config{HTTPClient: r.httpClient}, immediateReconcileRequests, resourceWatcherRoutines, crd.GroupVersionKind(), jg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: IIRC crd.GroupVersionKind() is problematic, ideally ControllerBuilder would record the GVK
Thanks @yuwenma /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ea7ee5c
into
GoogleCloudPlatform:master
Change description
Currently, developers need to register each direct controller in multiple places, and needs to list their dedicated GVK values.
This PR proposes two changes:
init
. This should simplify the code and increase the readability as: developing a direct controller starts from register aModel
--> theModel
implements aAdapter
--> theAdapter
implementscrud
+export
.Introduce a new CRD labeldevelopers do not need to list the new resource GVK in both CC registry and the e2e test base workflow.cnrm.cloud.google.com/directcrd=true
, soThis label approach is the same as the TF and DCL based CRDs.Direct controller will be the default controller to use. If using TF/DCL controller, developers need to use the corresponding CRD labels.KCC_USE_DIRECT_RECONCILERS
flag will override the TF/DCL label to force using the direct controller.How to use
pkg/controller/direct/register/register.go
Model
todirectbase.ControllerBuilder