-
Notifications
You must be signed in to change notification settings - Fork 319
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
HOSTEDCP-1984: Refactor capi logic out from NodePool controller #4795
HOSTEDCP-1984: Refactor capi logic out from NodePool controller #4795
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: enxebre 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 |
0a9c1c5
to
bc26251
Compare
if err != nil { | ||
return err | ||
} | ||
if result, err := c.CreateOrUpdate(ctx, c.Client, template, func() error { |
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 we are introducing a tight coupling with the Token
struct by using its client, createOrUpdate, nodePool, etc. fields.
should we explicitly pass those options to the Reconcile()
function or add them as fields to CAPI
?
I would imagine the Token
object we pass to CAPI to just be an interface exposing the functions CAPI needs.
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 agree, I'd expect that's exactly the end state (fields in capi + interface) and even consider separate packages so unexported fields are not accessible. I chose coupling for simplicity for now, the fields are accessible within the same package anyways and otherwise you would endup with "duplicated" fields which is also confusing. Any follow up refinement in that direction can be done now with confidence since we have decent coverage.
Added a TODO
} | ||
return fmt.Errorf("error getting MachineHealthCheck: %w", err) | ||
} | ||
if mhc.DeletionTimestamp != nil { |
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.
why do we need to fetch the object and check the DeletionTimestamp first? isn't Delete
a no-op if the object is already deleting?
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 is just the business logic of the original function. I'd prefer to keep the scope of this PR small to reduce risk of regression and let any follow up iteration be test driven now we have decent coverage.
Added a TODO
// TODO(Alberto): drop this an rely on core in-place propagation once CAPI 1.4.0 https://github.com/kubernetes-sigs/cluster-api/releases comes through the payload. | ||
// https://issues.redhat.com/browse/HOSTEDCP-971 | ||
machineList := &capiv1.MachineList{} | ||
if err := c.List(context.TODO(), machineList, client.InNamespace(machineDeployment.Namespace)); err != nil { |
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 we should pass a proper context here instead of context.TODO()
machine.Labels = make(map[string]string) | ||
} | ||
|
||
if result, err := controllerutil.CreateOrPatch(context.TODO(), c.Client, &machine, func() error { |
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 we should pass a proper context here instead of context.TODO()
bc26251
to
ab740d1
Compare
✅ Deploy Preview for hypershift-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
ab740d1
to
0b4cd22
Compare
if nodePool.Spec.Platform.AWS.AMI != "" { | ||
ami = nodePool.Spec.Platform.AWS.AMI | ||
} else { | ||
// TODO: Should the region be included in the NodePool platform information? |
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.
Do we still need this TODO?
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.
Yes, I don't want to couple dropping that with this PR. fwiw this is just moving existing code around, intentionally modifying as less as possible in this PR and increasing coverage to an acceptable bar to enable further changes
// Check if platform machine template needs to be updated. | ||
targetMachineTemplate := template.GetName() | ||
if isUpdatingMachineTemplate(nodePool, targetMachineTemplate) { | ||
// TODO (alberto): deocuple all conditions handling from this file into nodepool_controller.go dedicated function. |
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.
We should tag Jira tickets to TODOs in the code so we don't lose track of items like this.
// Set defaults. These are normally set by the CAPI machinedeployment webhook. | ||
// However, since we don't run the webhook, CAPI updates the machinedeployment | ||
// after it has been created with defaults. | ||
machineDeployment.Spec.MinReadySeconds = k8sutilspointer.Int32(0) |
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.
k8sutilspointer.Int32 is deprecated. These should be updated to use ptr.To[int32]
Kind: gvk.Kind, | ||
APIVersion: gvk.GroupVersion().String(), | ||
Namespace: machineTemplateCR.GetNamespace(), | ||
// keep current tempalte name for later check. |
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.
// keep current tempalte name for later check. | |
// keep current template name for later check. |
targetVersion := c.Version() | ||
targetConfigHash := c.HashWithoutVersion() | ||
targetConfigVersionHash := c.Hash() | ||
if userDataSecret.Name != k8sutilspointer.StringDeref(machineDeployment.Spec.Template.Spec.Bootstrap.DataSecretName, "") { |
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.
StringDeref is also deprecated. Should use ptr.Deref
} | ||
|
||
func deleteMachineSet(ctx context.Context, c client.Client, ms *capiv1.MachineSet) error { | ||
// TODO(alberto): why do we need to fetch the object and check the DeletionTimestamp first? |
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.
TODO should link to a Jira ticket
} | ||
|
||
func deleteMachineHealthCheck(ctx context.Context, c client.Client, mhc *capiv1.MachineHealthCheck) error { | ||
// TODO(alberto): why do we need to fetch the object and check the DeletionTimestamp first? |
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.
TODO should link to a Jira ticket
} | ||
} | ||
|
||
// TODO (alberto) drop this deterministic naming logic and get the name for child MachineDeployment from the status/annotation/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.
TODO should link to a Jira ticket
return filtered, nil | ||
} | ||
|
||
// TODO (alberto): Let the all the deletion logic be a capi func. |
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.
TODO should link to a Jira ticket
} | ||
|
||
func TestMachineTemplateBuildersPreexisting(t *testing.T) { | ||
//RunTestMachineTemplateBuilders(t, 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.
Does this need uncommented?
0b4cd22
to
c056c49
Compare
This moves the CAPI related logic into their own file and add test coverage particularly for the reconcile function. Additional refactor of the business logic itself is left out intentionally for now to contain the scope of the refactor and avoid backward compatibility issues.
c056c49
to
d965bf9
Compare
Fleshing out all the follow ups for these series of refactors is a task on its own not to be done in this PR yet. The TODOs are the placeholders for that task. |
/retest |
/lgtm |
@enxebre: This pull request references HOSTEDCP-1984 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set. In 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 openshift-eng/jira-lifecycle-plugin repository. |
/jira refresh |
@enxebre: This pull request references HOSTEDCP-1984 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set. In 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 openshift-eng/jira-lifecycle-plugin repository. |
@enxebre: all tests passed! Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
This moves the CAPI related logic into their own file and add test coverage particularly for the reconcile function. Additional refactor of the business logic itself is left out intentionally for now to contain the scope of the refactor and avoid backward compatibility issues.
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, use
fixes #<issue_number>(, fixes #<issue_number>, ...)
format, where issue_number might be a GitHub issue, or a Jira story:Fixes #
Checklist