Skip to content

✨ AccessSubnetUUID: we can specify source subnet for access IP address #756

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

Merged
merged 4 commits into from
Feb 26, 2021

Conversation

jsen-
Copy link
Contributor

@jsen- jsen- commented Feb 24, 2021

What this PR does / why we need it:
Currently, when we want to use multiple networks, the IP address is assigned basically randomly, this PR adds the ability to specify from which subnet the IP address will be obtained.

Which issue(s) this PR fixes:
none

Special notes for your reviewer:
This is the minimal amount of changes I found to achieve the goal of getting IP address from the correct CIDR.

Release note:

Added the ability to specify source subnet of compute instance access IP address

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 24, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @jsen-. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 24, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsen-, sbueringer

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 24, 2021
@sbueringer
Copy link
Member

/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 Feb 24, 2021
@sbueringer
Copy link
Member

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

@jsen- jsen- changed the title AccessSubnetUUID: we can specify source subnet for access IP address ✨ AccessSubnetUUID: we can specify source subnet for access IP address Feb 24, 2021
@fejta-bot
Copy link

Unknown CLA label state. Rechecking for CLA labels.

Send feedback to sig-contributor-experience at kubernetes/community.
/check-cla

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 24, 2021
@@ -57,6 +57,10 @@ type OpenStackMachineSpec struct {
// A networks object. Required parameter when there are multiple networks defined for the tenant.
// When you do not specify the networks parameter, the server attaches to the only network created for the current tenant.
Networks []NetworkParam `json:"networks,omitempty"`

// IP address of a port from this subnet will be marked as AccessIPv4 on the created compute instance
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what happens if networks and subnet which is not part of networks are given.
If we do not accept the case comment it here. Or add the check logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess below discussion covered this? maybe need some comments update?

if AccessSubnet is set we will get a hit here and have a value for accessIPv4
otherwise accessIPv4 and we have no change to before this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, got it.

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 added f5ff1bf.
The instance creation will fail if no ports with fixed IP are found in the specified subnet. This also covers the case when this subnet does not exist or is not in .Networks.
I didn't notice the ...

Ok, got it.

... until now, so please let me know if you'd like to keep this change. I can drop this commit if not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsen- Thanks for adding checking logic which is better to be added. Keep the commit, please.

@@ -57,6 +57,10 @@ type OpenStackMachineSpec struct {
// A networks object. Required parameter when there are multiple networks defined for the tenant.
// When you do not specify the networks parameter, the server attaches to the only network created for the current tenant.
Networks []NetworkParam `json:"networks,omitempty"`

// IP address of a port from this subnet will be marked as AccessIPv4 on the created compute instance
AccessSubnetUUID string `json:"accessSubnetUuid,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Other variables does not start with Access. Subnet is easy to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed AccessSubnetUUID to Subnet

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsen- Thanks updating.

@@ -132,6 +132,7 @@ type Instance struct {
FailureDomain string `json:"failureDomain,omitempty"`
SecurityGroups *[]string `json:"securigyGroups,omitempty"`
Networks *[]Network `json:"networks,omitempty"`
AccessSubnet string `json:"accessSubnet,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

hm does it make sense to call the property in instance differently than the one in the spec?

Copy link
Member

Choose a reason for hiding this comment

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

Hm maybe I missed something / or read it incorrectly. Could it be that this adds the Subnet property to the OpenStackMachine and the AccessSubnet to the Instance struct which seems to be only used for the status of the Bastion host?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instance struct seems to be used as a status of bastion and as a holder of state of a created VM, but at the same time, it is used as an input for createInstance. I don't know why this is so, but I wanted to minimize the impact of this PR.
There are basically two possibilities how to forward the subnet UUID into the createInstance function:

  • add this property to this Instance struct (what I did)
  • add another (optional) parameter to createInstance function
    The second option seemed inappropriate, taking into consideration the current signature:
func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infrav1.Instance, error)

Adding accessSubnetUUID string does not feel right, but now that I'm thinking about it, the advantage would be that it would not change the public contract in bastion host status.

Just let me know, I can add another commit and forward the subnet UUID in an additional argument.

It also might make sense to keep it as it is and add the same possibility to specify subnet UUID for bastion host as well (adding similar Subnet property to Bastion struct

type Bastion struct {
//+optional
Enabled bool `json:"enabled"`
//+optional
Flavor string `json:"flavor,omitempty"`
//+optional
Image string `json:"image,omitempty"`
//+optional
SSHKeyName string `json:"sshKeyName,omitempty"`
//+optional
Networks []NetworkParam `json:"networks,omitempty"`
//+optional
FloatingIP string `json:"floatingIP,omitempty"`
//+optional
SecurityGroups []SecurityGroupParam `json:"securityGroups,omitempty"`
}
)
Then having this property in Bastion status starts making sense.

@@ -132,6 +132,7 @@ type Instance struct {
FailureDomain string `json:"failureDomain,omitempty"`
SecurityGroups *[]string `json:"securigyGroups,omitempty"`
Networks *[]Network `json:"networks,omitempty"`
AccessSubnet string `json:"accessSubnet,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

AccessSubnet is also better to be renamed to Subnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -221,6 +229,10 @@ func createInstance(is *Service, clusterName string, i *infrav1.Instance) (*infr
}
}
}
if i.AccessSubnet != "" && accessIPv4 == "" {
return nil, fmt.Errorf("no ports with fixed IPs found on AccessSubnet \"%s\"", i.AccessSubnet)
Copy link
Contributor

Choose a reason for hiding this comment

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

If AccessSubnet is renamed to Subnet, This comment would be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@hidekazuna
Copy link
Contributor

Looks good to me now.

@jichenjc
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 26, 2021
@k8s-ci-robot k8s-ci-robot merged commit 7b62250 into kubernetes-sigs:master Feb 26, 2021
@sbueringer
Copy link
Member

@jichenjc @hidekazuna I would have preferred to be able to at least take a quick look at the final implementation before merge.
It's not a big problem in this case, but what do you think about defaulting to /hold on PRs to avoid instant merge on-lgtm? #758

@sbueringer sbueringer mentioned this pull request Mar 25, 2021
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants