-
Notifications
You must be signed in to change notification settings - Fork 342
Set observed gen in gen-reconciler #1261
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ type reconcilerReconcilerGenerator struct { | |
| reconcilerClass string | ||
| hasReconcilerClass bool | ||
| nonNamespaced bool | ||
| genDuckLogic bool | ||
|
|
||
| groupGoName string | ||
| groupVersion clientgentypes.GroupVersion | ||
|
|
@@ -75,6 +76,7 @@ func (g *reconcilerReconcilerGenerator) GenerateType(c *generator.Context, t *ty | |
| "class": g.reconcilerClass, | ||
| "hasClass": g.hasReconcilerClass, | ||
| "nonNamespaced": g.nonNamespaced, | ||
| "genDuckLogic": g.genDuckLogic, | ||
| "controllerImpl": c.Universe.Type(types.Name{ | ||
| Package: "knative.dev/pkg/controller", | ||
| Name: "Impl", | ||
|
|
@@ -106,6 +108,7 @@ func (g *reconcilerReconcilerGenerator) GenerateType(c *generator.Context, t *ty | |
| // Deps | ||
| "clientsetInterface": c.Universe.Type(types.Name{Name: "Interface", Package: g.clientsetPkg}), | ||
| "resourceLister": c.Universe.Type(types.Name{Name: g.listerName, Package: g.listerPkg}), | ||
| "conditionSet": c.Universe.Type(types.Name{Name: "ConditionSet", Package: "knative.dev/pkg/apis"}), | ||
| // K8s types | ||
| "recordEventRecorder": c.Universe.Type(types.Name{Name: "EventRecorder", Package: "k8s.io/client-go/tools/record"}), | ||
| // methods | ||
|
|
@@ -211,6 +214,11 @@ type reconcilerImpl struct { | |
| // Check that our Reconciler implements controller.Reconciler | ||
| var _ controller.Reconciler = (*reconcilerImpl)(nil) | ||
|
|
||
| {{if .genDuckLogic}} | ||
| // Creates the {{.conditionSet|raw}} to manipulate resource status conditions | ||
| var condSet = apis.NewLivingConditionSet() | ||
| {{end}} | ||
|
|
||
| ` | ||
|
|
||
| var reconcilerNewReconciler = ` | ||
|
|
@@ -320,6 +328,24 @@ func (r *reconcilerImpl) Reconcile(ctx {{.contextContext|raw}}, key string) erro | |
| } | ||
| } | ||
|
|
||
| {{if .genDuckLogic}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code will get here for deleted resources as well and it is not allowed to update generation for a deleted object |
||
| // Bump observed generation to denote that we have processed this | ||
| // generation regardless of success or failure. | ||
| resource.Status.ObservedGeneration = resource.Generation | ||
|
|
||
| if resource.Status.ObservedGeneration != original.Status.ObservedGeneration && reconcileEvent != nil { | ||
| originalRc := original.Status.GetCondition(apis.ConditionReady) | ||
| 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but this could be that it went from ready true to ready true if the update was something minor
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only runs if reconcileEvent != nil should we should be in a (potential) error case. |
||
| logger.Warnw("A reconconiler observed a new generation without updating the resource status") | ||
| condSet.Manage(&resource.Status).MarkUnknown( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you should change the ready condition directly. It needs a dependent condition that cases the unreadiness. |
||
| apis.ConditionReady, "", "unsucessfully observed a new generation") | ||
| } | ||
| } | ||
| {{end}} | ||
|
|
||
| // Synchronize the status. | ||
| if equality.Semantic.DeepEqual(original.Status, resource.Status) { | ||
| // If we didn't change anything then don't call updateStatus. | ||
|
|
||
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 only thing is that duck == interface, so
geninterfacelogicdoes not make a ton of sense.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 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)