Skip to content

Conversation

Fedosin
Copy link
Contributor

@Fedosin Fedosin commented Jun 16, 2023

What this PR does / why we need it:

Previously, the check was executed at the end of reconciliation and in multiple instances. By moving it to the beginning, the process is halted when installed and desired versions match, streamlining the reconciliation workflow.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 16, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from fedosin. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 16, 2023
Fedosin added 4 commits June 16, 2023 16:37
now operator supports only v1alpha4 and v1beta1, but it's an artificial
limitation that we can avoid.
Previously, the check was executed at the end of reconciliation and
in multiple instances. By moving it to the beginning, the process is
halted when installed and desired versions match, streamlining the
reconciliation workflow.
@Fedosin Fedosin force-pushed the preflight_checks branch from b461a00 to b17b9c9 Compare June 16, 2023 14:37
@Fedosin
Copy link
Contributor Author

Fedosin commented Jun 17, 2023

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 17, 2023
@Fedosin
Copy link
Contributor Author

Fedosin commented Jun 18, 2023

The issue is addressed in #168, so the only meaningful thing we can take from this PR is to move preflight checks into a separate package.

@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 22, 2023
func (r *GenericProviderReconciler) reconcile(ctx context.Context, provider genericprovider.GenericProvider, genericProviderList genericprovider.GenericProviderList) (ctrl.Result, error) {
reconciler := newPhaseReconciler(*r, provider, genericProviderList)
phases := []reconcilePhaseFn{
reconciler.preflightChecks,
Copy link
Member

@damdo damdo Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we kept the preflightChecks as a phase here, so we can benefit from the centralised condition setting logic, and we defined the halt pattern you came up with, as a pattern for all the phases.

Maybe with a customisable halting message (similar to the one you specified here) that can be logged before returning reconcile()? We could even have halt as a message string (haltMsg?), and when the phase returns a non empty msg then we log and halt?

So here doing something like

res, halt, err = phase(ctx)
...

Comment on lines +256 to +277
// versionChanged try to get installed version from provider status and decide if it has changed.
func versionChanged(provider genericprovider.GenericProvider) (bool, error) {
installedVersion := provider.GetStatus().InstalledVersion
if installedVersion == nil {
return true, nil
}

currentVersion, err := version.ParseSemantic(*installedVersion)
if err != nil {
return false, err
}

res, err := currentVersion.Compare(provider.GetSpec().Version)
if err != nil {
return false, err
}

// we need to delete installed components if versions are different
versionChanged := res != 0

return versionChanged, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just codemotion, but maybe we could make this even more useful and if
currentVersion.Compare != 0 perform a deep.Equal() and return the []string with the diff between the two or else return []string{}, nil.
This way we could log what is the detected difference and provide useful info to the user about it.

@Fedosin Fedosin closed this Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants