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

Use local routing in transit gateway when PowerVS and VPC are from same region #1777

Merged
merged 1 commit into from
May 22, 2024

Conversation

dharaneeshvrd
Copy link
Contributor

@dharaneeshvrd dharaneeshvrd commented May 15, 2024

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 #1763

Special notes for your reviewer:

/area provider/ibmcloud

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

Use local routing in transit gateway when PowerVS and VPC are from same region

@k8s-ci-robot k8s-ci-robot added the area/provider/ibmcloud Issues or PRs related to ibmcloud provider label May 15, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 15, 2024
Copy link

netlify bot commented May 15, 2024

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

Name Link
🔨 Latest commit c0ec9d7
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-ibmcloud/deploys/664d90ff77527a00086578f2
😎 Deploy Preview https://deploy-preview-1777--kubernetes-sigs-cluster-api-ibmcloud.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.

@dharaneeshvrd
Copy link
Contributor Author

/cc @mkumatag @Karthik-K-N

@@ -251,6 +251,9 @@ type TransitGateway struct {
// id of resource.
// +optional
ID *string `json:"id,omitempty"`
// globalRouting indicates whether to set global routing true or not while creating the transit gateway.
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets also mention a liner about global routing and local routing and when to use which.
Also what system will do when the field is omitted like as we mentioned in other api types. Lets keep as descriptive as possible.

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

return nil, fmt.Errorf("failed to use local routing for transit gateway since powervs and vpc region used requires global routing")
}
// setting global routing to true when it is set by user.
if s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting != nil && *s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting && !*globalRouting {
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 here we need not check whats globalRouting, simply use Spec.TransitGateway.GlobalRouting

}
region := endpoints.ConstructRegionFromZone(*zone)
vpcRegion, err := genUtil.VPCRegionForPowerVSRegion(region)

if s.IBMPowerVSCluster.Spec.VPC != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use s.VPC()

// getTransitGatewayLocationAndRouting returns appropriate location and routing suitable for transit gateway.
// routing indicates whether to enable global routing on transit gateway or not.
// returns true when powervs and vpc region are not common otherwise false.
func (s *PowerVSClusterScope) getTransitGatewayLocationAndRouting() (*string, *bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see any advantage of using pointer to bool , I think we can simply use bool instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway I need to make it a pointer in called func, so just made it here and used as it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense.

vpcRegion, err := genUtil.VPCRegionForPowerVSRegion(region)

if s.IBMPowerVSCluster.Spec.VPC != nil {
routing := !genUtil.IsCommonPowerVSAndVPCRegion(region, *s.IBMPowerVSCluster.Spec.VPC.Region)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it confusing, can we simplify, Instead of negating the return value, Can we make this function to return localRouting instead of globalRouting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored the func a bit, I would like to keep the var as globalRouting since we are going to assign it to CreateTransitGatewayOptions.Global field.

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense.

@@ -251,6 +251,11 @@ type TransitGateway struct {
// id of resource.
// +optional
ID *string `json:"id,omitempty"`
// globalRouting indicates whether to set global routing true or not while creating the transit gateway.
// set this flag to true only when PowerVS and VPC are from different regions, if they are same it's suggested to use local routing by setting the flag to false.
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
// set this flag to true only when PowerVS and VPC are from different regions, if they are same it's suggested to use local routing by setting the flag to false.
// set this field to true only when PowerVS and VPC are from different regions, if they are same it's suggested to use local routing by setting the field to false.

@@ -251,6 +251,11 @@ type TransitGateway struct {
// id of resource.
// +optional
ID *string `json:"id,omitempty"`
// globalRouting indicates whether to set global routing true or not while creating the transit gateway.
// set this flag to true only when PowerVS and VPC are from different regions, if they are same it's suggested to use local routing by setting the flag to false.
// if this flag is not set, based on where PowerVS and VPC regions are from would decide whether to enable globalRouting or not.
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
// if this flag is not set, based on where PowerVS and VPC regions are from would decide whether to enable globalRouting or not.
// when the field is omitted, based on PowerVS region (region associated with IBMPowerVSCluster.Spec.Zone) and VPC region(IBMPowerVSCluster.Spec.VPC.Region) system will decide whether to enable globalRouting or not.

Copy link
Contributor

@Karthik-K-N Karthik-K-N left a comment

Choose a reason for hiding this comment

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

One suggestion otherwise LGTM
Thank you.

return nil, fmt.Errorf("failed to get transit gateway location")
}

// throw error when user tries to use local routing where global routing is required.
Copy link
Contributor

Choose a reason for hiding this comment

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

We can have this check in webhook as well, If required we can add a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to have this in another PR, currently util is importing v1beta2 pkg, which is causing circular import issue when accessing the region map from util in Webhook, added a todo handle this later.
Moved the GetTransitGatewayLocationAndRouting() to util to consume from Webhook validation later.

Copy link
Contributor

Choose a reason for hiding this comment

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

nice, Thanks

Comment on lines 1767 to 1770
if s.VPC() != nil {
routing := genUtil.IsGlobalRoutingRequiredForTG(region, *s.IBMPowerVSCluster.Spec.VPC.Region)
return s.IBMPowerVSCluster.Spec.VPC.Region, &routing
}
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
if s.VPC() != nil {
routing := genUtil.IsGlobalRoutingRequiredForTG(region, *s.IBMPowerVSCluster.Spec.VPC.Region)
return s.IBMPowerVSCluster.Spec.VPC.Region, &routing
}
if vpc := s.VPC(); vpc != nil {
routing := genUtil.IsGlobalRoutingRequiredForTG(region, *vpc.Region)
return vpc.Region, &routing
}

@mkumatag mkumatag added this to the v0.8 milestone May 17, 2024
@dharaneeshvrd dharaneeshvrd force-pushed the tg-local-route branch 4 times, most recently from a2e596f to abc6f94 Compare May 20, 2024 04:00
return nil, fmt.Errorf("failed to get transit gateway location")
}

// throw error when user tries to use local routing where global routing is required.
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, Thanks

util/util.go Outdated
}

// returning routing as true since VPC region is not set and used PowerVS region to calculate the transit gateway location.
return &location, ptr.To(true), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious to know for setting true, This case may not occur as we have a webhook check for making sure the vpc region is set, but incase it occurs any how we are getting VPC region associated with PowerVS so can't we use local routing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing it out, its supposed to be local routing!😁

Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

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

minor comment, otherwise LGTM

// throw error when user tries to use local routing where global routing is required.
// TODO: Add a webhook validation for below condition.
if s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting != nil && !*s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting && *globalRouting {
return nil, fmt.Errorf("failed to use local routing for transit gateway since powervs and vpc region used requires global routing")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("failed to use local routing for transit gateway since powervs and vpc region used requires global routing")
return nil, fmt.Errorf("failed to use local routing for transit gateway since powervs and vpc are in different region and requires global routing")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it. PTAL now!

// throw error when user tries to use local routing where global routing is required.
// TODO: Add a webhook validation for below condition.
if s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting != nil && !*s.IBMPowerVSCluster.Spec.TransitGateway.GlobalRouting && *globalRouting {
return nil, fmt.Errorf("ailed to use local routing for transit gateway since powervs and vpc are in different region and requires global routing")
Copy link
Member

Choose a reason for hiding this comment

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

there is a typo!

Suggested change
return nil, fmt.Errorf("ailed to use local routing for transit gateway since powervs and vpc are in different region and requires global routing")
return nil, fmt.Errorf("failed to use local routing for transit gateway since powervs and vpc are in different region and requires global routing")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.

Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

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

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dharaneeshvrd, mkumatag

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 May 22, 2024
@k8s-ci-robot k8s-ci-robot merged commit 4c5b9da into kubernetes-sigs:main May 22, 2024
13 checks passed
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. area/provider/ibmcloud Issues or PRs related to ibmcloud provider 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/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.

Support local routing in transit gateway when PowerVS and VPC are from same region
4 participants