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

Add e2e test to cover region in providerID clusterv1 machine object #2210

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MatthieuFin
Copy link
Contributor

What this PR does / why we need it:
Add E2E test to cover region in providerID clusterv1 machine object introduced in issue #2183 and PR #2193

Special notes for your reviewer:

I have write 2 test cases:

  1. One cluster object with identityRef.Region field specified in OpenStackCluster providerID-with-region-default and no identityRef specified in OpenStackMachineTemplate
  2. One cluster object without identityRef.Region field specified in OpenstackCluster providerID-with-region-override and identityRef.Region specified in OpenStackMachineTemplate.

I uncounter an error on test case number 1, region name missing from clusterv1.Machine providerID string. That why I add a 2nd commit to fix that usecase and keep behavior of identityRef herited from Cluster Object.

It seems to do the job but it is "semantically" not really fair because I mutate object openStackMachine to append Cluster idenityRef if openStackMachine one's is nil, but this object goal of life is to mirror reality so that's technically a hack should I append a parameter to reconcileMachineState function to pass cluster object or cluster's identityRef object ?

/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 Oct 28, 2024
@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 assign jichenjc for approval. 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 28, 2024
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 28, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @MatthieuFin. 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-sigs/prow repository.

Copy link

netlify bot commented Oct 28, 2024

Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

Name Link
🔨 Latest commit e1edef9
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/6723a9707a7a2e00089b7463
😎 Deploy Preview https://deploy-preview-2210--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mdbooth
Copy link
Contributor

mdbooth commented Oct 28, 2024

/ok-to-test

@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 Oct 28, 2024
@MatthieuFin MatthieuFin force-pushed the fix-providerID branch 2 times, most recently from 8723acf to 902e688 Compare October 29, 2024 08:11
@MatthieuFin
Copy link
Contributor Author

Outch, I thinked that CAPO_REGION env variable will be set by https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/templates/env.rc#L89 but it seems not, personally I run tests by setting my own CAPO_REGION variable with my region name.
How could I retrieve CI region name to feed CAPO_REGION env variable ?

@MatthieuFin MatthieuFin force-pushed the fix-providerID branch 3 times, most recently from 0bf46aa to b5fa8d3 Compare October 29, 2024 16:52
@MatthieuFin
Copy link
Contributor Author

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 29, 2024
@@ -391,6 +391,9 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
Address: instanceStatus.Name(),
})
openStackMachine.Status.Addresses = addresses
if openStackMachine.Spec.IdentityRef == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@MatthieuFin MatthieuFin Oct 29, 2024

Choose a reason for hiding this comment

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

function getOrCreateMachineServer build an openStackServer object, that's not the purpose of this context so I didn't think to use it like that.
Do you think that this way is a better approach ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No it's not a better approach I think.
However moving the code to a separated function and use it in both places seems a good idea. We share the logic in case it has to change one day.

Thanks for trying that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obviously it seems to make sens, I'll take a look on this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IdentityRef lookup logic was also implmented here, so I tried to factorise code to use same implementation at anyplaces with this last commit.

Makefile Outdated Show resolved Hide resolved
@EmilienM
Copy link
Contributor

Really good start, thanks for writing these tests! A few minor comments inline.

break
}
}
return namespace, identityRef
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not trying to be picky but I want to ensure we create code that will be maintainable and debuggable. I don't see error management here. What if the identifyRef wasn't found? Shouldn't we return an error?
Or from the callers, if identityRef is nil, we should return an error?

I think either way we need to stop and send a clean error if we can't find an identityRef. Especially because we use a pointer in one of the cases and I like to see pointer checks before using them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I ask myself about that too.
I took the choose of that the responsibility of caller since objects ...infrav1.IdentityRefProvider could have nil pointer to IdentityRef field, I don't wanna return an error because the value of objects could be nil as a normal behavior.

In my 2 callers functions last parameters are openStackCluster type of infrav1.OpenStackCluster which is not a pointer https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/api/v1beta1/openstackcluster_types.go#L194 so I'm sure that identityRef variable here and here and correctly defined.

But I'm agree maybe tomorrow it could be different, so I could validate function return from caller for more maintainability.

factorize identityRef lookup from multiple object to implement logic of identityRef's inheritage in one place (scope factory)

Signed-off-by: MatthieuFin <[email protected]>
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Inbox
Development

Successfully merging this pull request may close these issues.

4 participants