Set observed gen in gen-reconciler#1261
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: whaught The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
I like the idea but have 2 suggestions:
|
n3wscott
left a comment
There was a problem hiding this comment.
I wonder if this generated code belongs inside of the api and not the reconciler. If the reconciler can test that the resource under reconciliation implements some PostReconcile method that does the cleanups and testing, then you can use the correct condition sets and/or add a Mark* method to enable the interactions you are looking for.
|
|
||
| // +genclient | ||
| // +genreconciler | ||
| // +genducklogic |
There was a problem hiding this comment.
the only thing is that duck == interface, so geninterfacelogic does not make a ton of sense.
There was a problem hiding this comment.
I won't pretend to be good at naming. I'm not sure I see the interface problem. The idea was "generate duck-type shaped common logic".
Can you suggest an alternative? @antoineco also suggested making it another option on +genreconciler if you have any thoughts on that (although that already has a :classname option)
| } | ||
| } | ||
|
|
||
| {{if .genDuckLogic}} |
There was a problem hiding this comment.
the code will get here for deleted resources as well and it is not allowed to update generation for a deleted object
| rc := resource.Status.GetCondition(apis.ConditionReady) | ||
| // if a new generation is observed and reconciliation reported an error event | ||
| // the reconciler should change the ready state. By default we will set unknown. | ||
| if equality.Semantic.DeepEqual(originalRc, rc) { |
There was a problem hiding this comment.
but this could be that it went from ready true to ready true if the update was something minor
There was a problem hiding this comment.
This only runs if reconcileEvent != nil should we should be in a (potential) error case.
| // the reconciler should change the ready state. By default we will set unknown. | ||
| if equality.Semantic.DeepEqual(originalRc, rc) { | ||
| logger.Warnw("A reconconiler observed a new generation without updating the resource status") | ||
| condSet.Manage(&resource.Status).MarkUnknown( |
There was a problem hiding this comment.
I don't think you should change the ready condition directly. It needs a dependent condition that cases the unreadiness.
The reason this isn't part of every reconciler is because not ever reconciler follows the duck-type code shape. Specifically some eventing resources don't have observed generation and this code fails for those. The reason this is opt-in is partly to allow to allow generating for non-duck resource but also for safety as we switch to it. I want to migrate resources to it one-by one by adding this tag and removing their reconciler's handling of observed gen. This will let me test it safely as I go through that process. Unfortunately +genreconciler:classname is already a thing to allow reconcilers the option of specifying a type to reconciler. Adding more options to that tag might get pretty cluttered (we could comma separate them). |
|
@whaught that's a fair point, I didn't consider not every type implements these. If the tag's elements are |
The tags are not key=value. You can read the parsing here: it currently expects "genreconciler:class". We could change this and then go update existing usages of it, make it key value, and comma separate multiple tags. I'm not sure if this is really a worthy migration in the scope of what this PR is trying to accomplish for the cost of just adding a new tag. |
|
@whaught the current expected format is Besides, there are at most 4 types that currently set this class parameter in the code base. I simply can't see a case for a new tag here, but I'm also happy to be proven wrong. |
|
@antoineco you're right about the existing format. Although a parser would need to be written to allow for other options. The argument is merely that a new tag doesn't cost anything and allows for options of its own. This isn't intended to be the only common generated logic, but a starting point. The existing pattern in k8s which is being invoked is here: pkg/vendor/k8s.io/gengo/types/comments.go Line 36 in 099343d you'll see that k8s doesn't expect implementors to be using comment tags this way. We sort of cheat by looking for the hardcoded tag "+genreconciler:class" In the future I hope to be able to include other common factors like initializing defaults/conversions and common metrics on conditions. Just thought it might get cluttered, and in line with what @n3wscott said, these aren't properties of a reconciler (which makes no resource shape assumptions) but are properties of the API duck resource. I'm happy to go the other way on this if folks are passionate. |
|
/hold I'm working on hacking together a potential alternative to this |
|
/close pulled this logic into #1284 with an interface that makes it more easily testable |
|
@whaught: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@whaught: PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Issue #1226
Automatically bump ObservedGeneration in the generated reconciler and set status to unknown for unhandled errors.
looks for
// +genducklogicto run this part of the code generation. This can serve as a jumping-off point to share other arbitrary logic among duck-type shaped resources.