Unify common code#1130
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amartyasinha The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
6aab9a1 to
1ef05f9
Compare
| } | ||
|
|
||
| // ReconcilerBase provides a common set of clients scheme and loggers for all reconcilers. | ||
| type ReconcilerBase struct { |
There was a problem hiding this comment.
so ReconcilerBase is intened to be the thing that hold the common code
so you shoudl be moving this as well if your going to do this.
the orginal inte was for this to become the common bas for the nova placment and evnetully cyborg contolers.
There was a problem hiding this comment.
Thanks @SeanMooney! Sure, I'll be moving ReconcilerBase soon to common code. I had it in the initial draft, but removed it because it was getting overwhelming for me to self-review. Once I believe the current code I'm moving are well-placed, I'll move ReconcilerBase as well.
There was a problem hiding this comment.
I've tried moving ReconcilerBase and other related func to internal/common. PTAL.
| h.GetClient(), | ||
| &instance.Status.Conditions) | ||
| &instance.Status.Conditions, | ||
| time.Second*10, |
There was a problem hiding this comment.
I think thanks to unifying ReconcilerBase, we can use r.RequeueTimeout
| // networks to attach to | ||
| nadList := []networkv1.NetworkAttachmentDefinition{} | ||
| for _, netAtt := range networkAttachments { | ||
| nad, err := nad.GetNADWithName(ctx, h, netAtt, h.GetBeforeObject().GetNamespace()) |
There was a problem hiding this comment.
maybe nadObject (nad is a name of package already)
| var ( | ||
| // ErrACSecretNotFound indicates that the ApplicationCredential secret was not found. | ||
| ErrACSecretNotFound = errors.New("ApplicationCredential secret not found") | ||
| // ErrACSecretMissingKeys indicates that the ApplicationCredential secret is missing required keys. |
There was a problem hiding this comment.
I think we missed a few errors, like errUnexpectedObjectType or ErrInvalidObjectType (of course, assuming we want to deduplicate all similar errors in the future, e.g., all errors like errExpectedNovaObject)
There was a problem hiding this comment.
moved all remaining errors here.
There was a problem hiding this comment.
Cool thanks, now when we have all errors in one place they can be unified like ErrInvalidObjectType and ErrUnexpectedObjectType probably can be one error in code. Maybe similar thing can be with more specific one eg ErrExpectedNovaAPIObject
fc8d155 to
7d82edc
Compare
mrkisaolamb
left a comment
There was a problem hiding this comment.
Something else we can try: unifying FindObjectsForSrcByField and findObjectsWithAppSelectorLabelInNamespace
There was a problem hiding this comment.
I think this can be fix Log := r.GetLogger(ctx)
There was a problem hiding this comment.
can we fix all this kind of timeouts using r.RequeueTimeout?
| var ( | ||
| // ErrACSecretNotFound indicates that the ApplicationCredential secret was not found. | ||
| ErrACSecretNotFound = errors.New("ApplicationCredential secret not found") | ||
| // ErrACSecretMissingKeys indicates that the ApplicationCredential secret is missing required keys. |
There was a problem hiding this comment.
Cool thanks, now when we have all errors in one place they can be unified like ErrInvalidObjectType and ErrUnexpectedObjectType probably can be one error in code. Maybe similar thing can be with more specific one eg ErrExpectedNovaAPIObject
| return result, nil | ||
| } | ||
|
|
||
| err = r.generateServiceConfigMaps(ctx, h, instance, secret, &configMapVars, db) |
There was a problem hiding this comment.
Do you think we can generalize the existing nova generateConfigsGeneric and use it here?
There was a problem hiding this comment.
Yes, we can do that. Though it won't be a clean move of nova's generateConfigsGeneric to internal/common, and there will be a few changes, thus will required some tests. I'll try to do it tomorrow, or if you want, we can have it in a follow up PR too, whatever you prefer.
There was a problem hiding this comment.
added a new commit for this. PTAL
2444cca to
3a8b6c6
Compare
…et names Move shared Kolla volume and secret name helpers out of internal/nova so nova and placement deployments can reuse them.
Move shared static errors into internal/common/errors.go and update webhook and controller call sites to reference the shared definitions.
Extract ReconcilerBase, Manageable, Reconciler, NewReconcilerBase, SetRequeueTimeout, Reconcilers, Setup, and OverrideRequeueTimeout into internal/common. Wire nova, placement, and main to use the shared base.
Move EnsureSecret, EnsureNetworkAttachments, EnsureTopology, and ConditionUpdater into internal/common. Switch nova and placement controllers to use the shared helpers.
Remove the duplicate allSubConditionIsTrue helper from nova common; logic matches condition.Conditions.AllSubConditionIsTrue() from lib-common.
Add unit tests for internal/common.EnsureSecret and extend placement functional coverage for missing and incomplete input secrets.
Replace duplicated controller watch map functions with generic helpers in internal/common/watch.go.
Share config secret generation between nova and placement controllers. Nova passes service-specific templates via NovaAdditionalTemplates in nova/common.go; placement uses GenerateConfigsWithScripts in generateServiceConfigMaps. Co-authored-by: Cursor <cursoragent@cursor.com>
| // Static errors shared across operator services. | ||
| var ( | ||
| // ErrACSecretNotFound indicates that the ApplicationCredential secret was not found. | ||
| ErrACSecretNotFound = errors.New("ApplicationCredential secret not found") |
There was a problem hiding this comment.
question: wdyt about removing this error and use in placement similar condition+log+nil error like in nova controllers?
| cmLabels, additionalTemplates, commonTemplates, templateDir, true, | ||
| ) | ||
| // NovaAdditionalTemplates are the default extra config templates for nova services. | ||
| var NovaAdditionalTemplates = map[string]string{ |
There was a problem hiding this comment.
I don't think this should be global, as it can be mutated by any caller during execution. It's better to scope this locally inside the functions
|
|
||
| // EnsureNetworkAttachments - checks the requested network attachments exists and | ||
| // returns the annotation to be set on the deployment objects. | ||
| func EnsureNetworkAttachments( |
There was a problem hiding this comment.
can we add some tests for this?
| // EnsureTopology - when a Topology CR is referenced, remove the | ||
| // finalizer from a previous referenced Topology (if any), and retrieve the | ||
| // newly referenced topology object | ||
| func EnsureTopology( |
There was a problem hiding this comment.
pls add some unit tests
Introduce internal/common for shared nova/placement
controller code: reconciler base, ensure helpers,
config generation, watch mappers, Kolla constants,
and static errors. Nova and placement controllers
call these helpers; nova-only logic stays in
internal/controller/nova/common.go.
This is a move-first refactor: logic, comments, and
naming are preserved where possible. Only
unavoidable mechanical changes are included (e.g.
exported names for cross-package use, import
updates, r.Client.Update because Client is a named
field on ReconcilerBase).
Co-authored-by: Cursor cursoragent@cursor.com