Skip to content
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

✨ Introduce version check validation for generate provider command #5933

Conversation

tharun208
Copy link

Signed-off-by: tharun [email protected]

This PR introduces validation for incompatible versions while generating providers using the generate provider command.

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #5864

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 13, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @tharun208!

It looks like this is your first PR to kubernetes-sigs/cluster-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @tharun208. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 13, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign vincepri after the PR has been reviewed.
You can assign the PR to them by writing /assign @vincepri in a comment when ready.

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

@tharun208 tharun208 force-pushed the feat/version_validation_generate_provider branch from fc9c58f to ec48ded Compare January 13, 2022 11:58
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 13, 2022
@tharun208 tharun208 force-pushed the feat/version_validation_generate_provider branch from ec48ded to e6cfe94 Compare January 13, 2022 12:49
@fabriziopandini
Copy link
Member

/ok-to-test
/cc @ykakarap

@k8s-ci-robot k8s-ci-robot requested a review from ykakarap January 14, 2022 15:01
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 14, 2022
@k8s-ci-robot
Copy link
Contributor

@tharun208: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main e6cfe94 link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@ykakarap
Copy link
Contributor

@tharun208 Thank you for getting the PR out. 🙂
I will review this soon.

Copy link
Contributor

@ykakarap ykakarap left a comment

Choose a reason for hiding this comment

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

First pass review:
It mostly looks good, expect for the default version case.

// namespace etc.
// Currently we are not supporting custom yaml processors for the provider
// components. So we revert to using the default SimpleYamlProcessor.
repositoryClientFactory, err := c.repositoryClientFactory(RepositoryClientFactoryInput{Provider: providerConfig})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
repositoryClientFactory, err := c.repositoryClientFactory(RepositoryClientFactoryInput{Provider: providerConfig})
repositoryClient, err := c.repositoryClientFactory(RepositoryClientFactoryInput{Provider: providerConfig})

nit: the factory returns a client not another factory.

Comment on lines +74 to +75
// Currently we are not supporting custom yaml processors for the provider
// components. So we revert to using the default SimpleYamlProcessor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Currently we are not supporting custom yaml processors for the provider
// components. So we revert to using the default SimpleYamlProcessor.

IMHO, I dont think you need these comments here. Also, If the defaulting changes these comments will become false.


providerName, providerVersion, err := parseProviderName(providerName)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return nil, errrors.Wrap(err, "failed to parse provider name")

Wrapping the errors provides more context when something fails.
If you can also wrap other errors below that would be great.

}
releaseSeries := latestMetadata.GetReleaseSeriesForVersion(currentVersion)
if releaseSeries.Contract != clusterv1.GroupVersion.Version {
return nil, errors.Errorf("current version of clusterctl is only compatible with %s providers, detected %s for provider %s", clusterv1.GroupVersion.Version, releaseSeries.Contract, providerVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("current version of clusterctl is only compatible with %s providers, detected %s for provider %s", clusterv1.GroupVersion.Version, releaseSeries.Contract, providerVersion)
return nil, errors.Errorf("current version of clusterctl is only compatible with %s providers, detected %s for provider version %s", clusterv1.GroupVersion.Version, releaseSeries.Contract, providerVersion)

return nil, err
}

latestMetadata, err := repositoryClientFactory.Metadata(providerVersion).Get()
Copy link
Contributor

Choose a reason for hiding this comment

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

This command is also supposed to work when a user does not provider a version in the input (Example: clusterctl generate provider -i aws). In such cases the providerVersion here will be empty and this command will fail. If the user does not provider a version we have to fall back to the default version.

However, I see that the repository client here does not have a DefaultVersion function. I would suggest adding a DefaultVersion function to the repository.Client interface and to the implementation (type repositoryClient struct {...}).
You can have something like this:

func (c *repositoryClient) DefaultVersion() string {
	return c.repository.DefaultVersion()
}

@fabriziopandini Thoughts about adding the DefaultVersion function to repository.Client interface? This interface already has a GetVersions function. I dont think it is unreasonable to add a DefaultVersion function.

Then, once you have access to the DefaultVersion function, after l.63 you can have to check to see if providerVersion is empty and set it to default version. This should fix the broken use case.

@ykakarap
Copy link
Contributor

@tharun208 Will you have bandwidth to continue this?

@tharun208
Copy link
Author

@ykakarap will address the feedbacks this week

@ykakarap
Copy link
Contributor

ykakarap commented May 7, 2022

@tharun208 will you have bandwidth to follow up on this?

@vincepri
Copy link
Member

vincepri commented Jun 7, 2022

Any updates on this PR?

@tharun208
Copy link
Author

@ykakarap can you follow up on this pr?

@ykakarap
Copy link
Contributor

ykakarap commented Jun 7, 2022

@ykakarap can you follow up on this pr?

I am not sure I understand. If you are asking about the next steps to do then the review on the PR still valid. Adding those changes should be a good place to start.
Let me know if you need help with this.

@sbueringer
Copy link
Member

@tharun208 Do you have time to address the findings?

@vincepri
Copy link
Member

vincepri commented Jul 6, 2022

Going to close this for now due to inactivity, please feel free to reopen
/close

@k8s-ci-robot
Copy link
Contributor

@vincepri: Closed this PR.

In response to this:

Going to close this for now due to inactivity, please feel free to reopen
/close

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.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clusterctl generate provider should return early if working with incompatible provider versions
6 participants