-
Notifications
You must be signed in to change notification settings - Fork 77
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1334,16 +1334,26 @@ func (s *PowerVSClusterScope) createTransitGateway() (*string, error) { | |
return nil, fmt.Errorf("error getting resource group id for resource group %v, id is empty", s.ResourceGroup()) | ||
} | ||
|
||
vpcRegion := s.getVPCRegion() | ||
if vpcRegion == nil { | ||
return nil, fmt.Errorf("failed to get vpc region") | ||
location, globalRouting, err := genUtil.GetTransitGatewayLocationAndRouting(s.Zone(), s.VPC().Region) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get transit gateway location and routing: %w", err) | ||
} | ||
|
||
// throw error when user tries to use local routing where global routing is required. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, Thanks |
||
// 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 are in different region and 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 = ptr.To(true) | ||
} | ||
|
||
tgName := s.GetServiceName(infrav1beta2.ResourceTypeTransitGateway) | ||
tg, _, err := s.TransitGatewayClient.CreateTransitGateway(&tgapiv1.CreateTransitGatewayOptions{ | ||
Location: vpcRegion, | ||
Location: location, | ||
Name: tgName, | ||
Global: ptr.To(true), | ||
Global: globalRouting, | ||
ResourceGroup: &tgapiv1.ResourceGroupIdentity{ID: ptr.To(resourceGroupID)}, | ||
}) | ||
if err != nil { | ||
|
@@ -1744,26 +1754,6 @@ func (s *PowerVSClusterScope) fetchResourceGroupID() (string, error) { | |
return "", err | ||
} | ||
|
||
// getVPCRegion returns region associated with VPC zone. | ||
func (s *PowerVSClusterScope) getVPCRegion() *string { | ||
if s.IBMPowerVSCluster.Spec.VPC != nil { | ||
return s.IBMPowerVSCluster.Spec.VPC.Region | ||
} | ||
// if vpc region is not set try to fetch corresponding region from power vs zone | ||
zone := s.Zone() | ||
if zone == nil { | ||
s.Info("powervs zone is not set") | ||
return nil | ||
} | ||
region := endpoints.ConstructRegionFromZone(*zone) | ||
vpcRegion, err := genUtil.VPCRegionForPowerVSRegion(region) | ||
if err != nil { | ||
s.Error(err, fmt.Sprintf("failed to fetch vpc region associated with powervs region %s", region)) | ||
return nil | ||
} | ||
return &vpcRegion | ||
} | ||
|
||
// fetchVPCCRN returns VPC CRN. | ||
func (s *PowerVSClusterScope) fetchVPCCRN() (*string, error) { | ||
vpcID := s.GetVPCID() | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done