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

⚠️ Store []ResolvedPortSpec in ReferencedMachineResources #1951

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

mdbooth
Copy link
Contributor

@mdbooth mdbooth commented Mar 15, 2024

The purpose of this change is fix an issue where we are storing unresolved references in ReferencedMachineResources. Specifically we are storing a PortOpts, which is a user-intent struct. PortOpts can contain unresolved references to both subnets and security groups, as well fields requiring additional processing which reference external objects: the port name, description, and tags.

We create a new type, ResolvedPortSpec, which can contain only fully resolved data. This can be seen in the new signature of CreatePorts(), which no longer requires any source of data other than the []ResolvedPortSpec from ReferencedMachineResources, and is now greatly simplified.

Fully resolving the port name also allows a simplification in port adoption.

All of the complexity now moves to ConstructPorts(), which is updated to return []ResolvedPortSpec instead of []PortOpts. ConstructPorts() is updated to resolve security groups, port name, description, and all subnets referenced in FixedIPs.

Fixes: #1943

TODO:

/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 Mar 15, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mdbooth

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 15, 2024
Copy link

netlify bot commented Mar 15, 2024

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

Name Link
🔨 Latest commit b6d7748
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65fd5bc413150c00080ada66
😎 Deploy Preview https://deploy-preview-1951--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 Author

mdbooth commented Mar 15, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@mdbooth mdbooth force-pushed the issue1943 branch 2 times, most recently from e8507e0 to 8281e5a Compare March 15, 2024 13:50
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 15, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2024
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 15, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 15, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

1 similar comment
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 16, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 18, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

Copy link
Contributor

@dulek dulek left a comment

Choose a reason for hiding this comment

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

Comments inline, most of them are more of a question thank a remark.

api/v1beta1/types.go Outdated Show resolved Hide resolved
@@ -6626,6 +6430,10 @@ spec:
implementations. What type of vNIC is actually available depends on
deployments. If not specified, the Neutron default value is used.
type: string
required:
- description
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this sucks that description is required, but if it's to change in a later patch I'm okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the resolved port spec in the status, which will always have a description: if it didn't have a description we would have generated one. This is expected.

api/v1beta1/openstackmachine_types.go Outdated Show resolved Hide resolved
}
return normalizedPorts, nil
}

// normalizePortTarget ensures that the port has a network ID.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all below should be double-checked by @MaysaMacedo. It looks right to me from dual stack perspective, but this is the delicate part in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be just code motion with changes for context. I didn't intentionally change the logic here.

test/e2e/suites/e2e/e2e_test.go Show resolved Hide resolved
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 19, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 20, 2024

@dulek Comments addressed.

@mdbooth mdbooth requested a review from dulek March 20, 2024 12:12
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 21, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 21, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 21, 2024

Nothing obvious, could be a flake.
/test pull-cluster-api-provider-openstack-e2e-test

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 21, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 21, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

Error was:

INFO: Applying the cluster template yaml to the cluster
[FAILED] Expected success, but got an error:
    <*errors.fundamental | 0xc002709368>: 
    exit status 1: stderr: 
    {
        msg: "exit status 1: stderr: ",
        stack: [0x1e615ee, 0x1efc805, 0x84ee73, 0x862ecd, 0x47b0c1],
    }
In [It] at: /root/go/pkg/mod/sigs.k8s.io/cluster-api/test@v1.6.0/e2e/clusterctl_upgrade.go:389 @ 03/21/24 13:25:03.601

Referring to https://github.com/kubernetes-sigs/cluster-api/blob/14efefeb46dbe8d0cd0f5b7d1718e00ec58fc079/test/e2e/clusterctl_upgrade.go#L389

That's not very illuminating! Lets see if it was a flake.

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 21, 2024

Same error.

The purpose of this change is fix an issue where we are storing
unresolved references in ReferencedMachineResources. Specifically we are
storing a PortOpts, which is a user-intent struct. PortOpts can contain
unresolved references to both subnets and security groups, as well
fields requiring additional processing which reference external objects:
the port name, description, and tags.

We create a new type, ResolvedPortSpec, which can contain only fully
resolved data. This can be seen in the new signature of CreatePorts(),
which no longer requires any source of data other than the
[]ResolvedPortSpec from ReferencedMachineResources, and is now greatly
simplified.

Fully resolving the port name also allows a simplification in port
adoption.

All of the complexity now moves to ConstructPorts(), which is updated to
return []ResolvedPortSpec instead of []PortOpts. ConstructPorts() is
updated to resolve security groups, port name, description, and all
subnets referenced in FixedIPs.
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 21, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

Copy link
Contributor

@huxcrux huxcrux left a comment

Choose a reason for hiding this comment

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

I looked thru the code and think it looks good. Only one inline comment regarding the function clusterName that actually returns a name used for resources and is not the cluster name.

It can safely be ignored however may cause confusion for someone reading the code. When I see clusterName i almost every time ask myself why cluster.Name is not used since cluster exists almost everywhere already

@@ -36,3 +38,7 @@ func GetFloatingAddressClaimName(openStackMachineName string) string {
func GetOpenStackMachineNameFromClaimName(claimName string) string {
return strings.TrimSuffix(claimName, fmt.Sprintf("-%s", FloatingAddressIPClaimNameSuffix))
}

func ClusterName(cluster *clusterv1.Cluster) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should call this variable something else? I get this is used for a lot of resources however it is not the clusters name.

Maybe clusterResourceName or something could work?

I really like the initiative to move this to a function since the name are present in a lot of places in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, and I agree. Confusion from this was also the cause of a bug in @EmilienM's ports series a few weeks back that took both of us working together over a day to track down. I think it's worth picking a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a separate commit which changes it everywhere. Note that clusterName in the e2e tests actually does mean cluster name, so I haven't changed it there.

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 22, 2024

I'm not going to re-run the full test on this latest push because it just updates function and variable names.

Actually we just broke the upgrade test with a search and replace the other day. Do I learn nothing? 🤦

@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 22, 2024

/test pull-cluster-api-provider-openstack-e2e-full-test

@huxcrux
Copy link
Contributor

huxcrux commented Mar 22, 2024

/lgtm

Lets hope the full e2e test passes 🤞

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 22, 2024
@mdbooth
Copy link
Contributor Author

mdbooth commented Mar 22, 2024

Passed!

/hold cancel

@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 Mar 22, 2024
@k8s-ci-robot k8s-ci-robot merged commit cb99e17 into kubernetes-sigs:main Mar 22, 2024
10 checks passed
@mdbooth mdbooth deleted the issue1943 branch March 22, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

ReferencedResources.Ports contains unresolved security groups
4 participants