-
Notifications
You must be signed in to change notification settings - Fork 85
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
Attach connections to existing transit gateway when its not there #1901
Attach connections to existing transit gateway when its not there #1901
Conversation
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
/cc @Karthik-K-N |
21a2662
to
ba86fed
Compare
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.
few doubts, will take a look again
cloud/scope/powervs_cluster.go
Outdated
@@ -394,6 +394,35 @@ func (s *PowerVSClusterScope) GetServiceInstanceID() string { | |||
return "" | |||
} | |||
|
|||
func (s *PowerVSClusterScope) SetTransitGatewayStatus(id *string, controllerCreated *bool, powerVSConnResource *infrav1beta2.ResourceReference, vpcConnResource *infrav1beta2.ResourceReference) { |
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.
func (s *PowerVSClusterScope) SetTransitGatewayStatus(id *string, controllerCreated *bool, powerVSConnResource *infrav1beta2.ResourceReference, vpcConnResource *infrav1beta2.ResourceReference) { | |
func (s *PowerVSClusterScope) SetTransitGatewayStatus(id *string, controllerCreated *bool, powerVSConnResource , vpcConnResource *infrav1beta2.ResourceReference) { |
|
||
s.IBMPowerVSCluster.Status.TransitGateway = &infrav1beta2.TransitGatewayStatus{ | ||
ID: id, | ||
ControllerCreated: controllerCreated, |
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.
won't it set ControllerCreated to false during second reconcilation?
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.
Second time, we won't call the SetTransitgatewayStatus()
. We would check status of TG and connections with the ID set in status and return.
cloud/scope/powervs_cluster.go
Outdated
func (s *PowerVSClusterScope) checkTransitGatewayConnections(id *string) (bool, error) { | ||
requeue := false | ||
// checkAndUpdateTransitGatewayConnections checks given transit gateway's connections status. | ||
// // if update is set to true, it updates the transit gateway connections too if it is not exist already. |
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.
// // if update is set to true, it updates the transit gateway connections too if it is not exist already. | |
// if update is set to true, it updates the transit gateway connections too if it is not exist already. |
ba86fed
to
984f3e5
Compare
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.
few questions. otherwise overall LGTM,
cloud/scope/powervs_cluster.go
Outdated
if powerVSAttached && vpcAttached { | ||
if s.IBMPowerVSCluster.Status.TransitGateway == nil { | ||
vpcConnResource = &infrav1beta2.ResourceReference{ | ||
ControllerCreated: ptr.To(false), |
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.
We intentionally not storing connections id here is status right? also if we dont set anything the default value for controller created is also false, but I think explicitly setting will enhance readability of code.
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.
Yes Agree, refactored with returning the ID and checking the attached status based on that. Ptal!
54b7576
to
a261261
Compare
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.
Initial comments on the create TG flow, will be taking a closer look
cloud/scope/powervs_cluster.go
Outdated
} | ||
s.V(3).Info("VPC connection successfully attached to transit gateway", "name", *conn.Name) | ||
vpcAttached = true | ||
s.V(3).Info("Transit gateway VPC connection OK", "name", *conn.Name) |
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.
Can we use a better logging statement?
@@ -1627,71 +1651,66 @@ func (s *PowerVSClusterScope) ReconcileTransitGateway() (bool, error) { | |||
if err != nil { | |||
return false, err | |||
} | |||
requeue, err := s.checkTransitGateway(tg.ID) | |||
requeue, _, _, err := s.checkAndUpdateTransitGateway(tg, false) |
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.
In a case where TG pre-exists and no connections exist, if we pass false
here, it won't create any connections right?
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.
Modified the logic to handle the existing resource passed via id in second block and taken care there to update the status. Ptal!
6229226
to
29d57ee
Compare
if err != nil { | ||
return "", false, err | ||
return "", false, nil, nil, err | ||
} | ||
if transitGateway == nil || transitGateway.ID == nil { |
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.
I think I dont remember, Do you know when can transitGateway can be nil, If we try to query a TG with invalid id or name which does not exist, It will throw an error right?
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.
yes, will remove this.
cloud/scope/powervs_cluster.go
Outdated
if err != nil { | ||
return false, err | ||
} | ||
if tgID != "" { | ||
s.V(3).Info("Transit gateway found in IBM Cloud") | ||
s.SetStatus(infrav1beta2.ResourceTypeTransitGateway, infrav1beta2.ResourceReference{ID: &tgID, ControllerCreated: ptr.To(false)}) | ||
s.SetTransitGatewayStatus(&tgID, ptr.To(false), powerVSConn, vpcConn) |
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.
My another query was wont this set controllerCreated to false, In the second loop?
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.
It won't come to this block on second reconciliation since status would have already generated and try to validate the resource's status in 1st block.
29d57ee
to
673438b
Compare
} | ||
return *transitGateway.ID, requeue, nil | ||
} | ||
|
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.
In a case where spec.TG.ID
is nil
and given TG name doesn't exist in cloud, GetTransitGatewayByName
, returns nil
. Without a nil check here, it would fail going further at checkTransitGatewayStatus
where *tg.Status
would be nil right? @dharaneeshvrd, Please correct me if my understanding is not right..
673438b
to
fae53e5
Compare
cloud/scope/powervs_cluster.go
Outdated
s.Info("Skipping transit gateway deletion as resource is not created by controller") | ||
return false, nil | ||
s.Info("Skipping transit gateway deletion as resource is not created by controller, but will check if connections are created by the controller.") | ||
skipTGDeletion = true | ||
} | ||
|
||
if s.IBMPowerVSCluster.Status.TransitGateway.ID == nil { |
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.
@dharaneesh, while testing, came across a scenario where for any reason if TG reconcilation fails and it doesn't set the s.IBMPowerVSCluster.Status.TransitGateway
, it will return a nil pointer error during deletion as ID will be nil. Though the value of s.IBMPowerVSCluster.Status.TransitGateway
is being checked during isResourceCreatedByController(infrav1beta2.ResourceTypeTransitGateway)
, we don't return after it to allow deletion of TG connections separately.
fae53e5
to
1a15e21
Compare
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.
Overall LGTM!
@dharaneeshvrd, hope you have tested all possible scenarios.
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.
/lgtm
When will this PR merge? |
cloud/scope/powervs_cluster.go
Outdated
Name: connName, | ||
}) | ||
|
||
return conn.ID, err |
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.
what happens when there is an error? don't we face a nil pointer dereference
issue because conn is nil when err occurs.
cloud/scope/powervs_cluster.go
Outdated
|
||
// createTransitGatewayConnections creates PowerVS and VPC connections in the transit gateway. | ||
func (s *PowerVSClusterScope) createTransitGatewayConnections(tg *tgapiv1.TransitGateway, pvsServiceInstanceCRN, vpcCRN *string) (*string, *string, error) { | ||
powerVSConnID, err := s.createTransitGatewayConnection(tg.ID, ptr.To(fmt.Sprintf("%s-pvs-con", *tg.Name)), ptr.To(string(powervsNetworkConnectionType)), pvsServiceInstanceCRN) |
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.
this %s-pvs-con
format can be placed somewhere so that we can reuse and easy to handle as well.
cloud/scope/powervs_cluster.go
Outdated
return nil, nil, fmt.Errorf("failed to create PowerVS connection in transit gateway: %w", err) | ||
} | ||
|
||
vpcConnID, err := s.createTransitGatewayConnection(tg.ID, ptr.To(fmt.Sprintf("%s-vpc-con", *tg.Name)), ptr.To(string(vpcNetworkConnectionType)), vpcCRN) |
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.
same as above
cloud/scope/powervs_cluster.go
Outdated
} | ||
if transitGateway == nil || transitGateway.ID == nil { | ||
|
||
if transitGateway == nil || (transitGateway != nil && transitGateway.ID == nil) { |
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.
if transitGateway == nil || (transitGateway != nil && transitGateway.ID == nil) { | |
if transitGateway == nil || transitGateway.ID == nil { |
cloud/scope/powervs_cluster.go
Outdated
// checkTransitGateway checks transit gateway exist in cloud. | ||
func (s *PowerVSClusterScope) isTransitGatewayExists() (string, bool, error) { | ||
// isTransitGatewayExists checks transit gateway exist in cloud and if exist with unattached connections, it attaches the connection too. | ||
func (s *PowerVSClusterScope) isTransitGatewayExists() (string, bool, *infrav1beta2.ResourceReference, *infrav1beta2.ResourceReference, error) { |
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.
function name misleads as you are doing attach operation as well in this function.
soon, wondering if can test these changes with OCP directly pulling from the @dharaneeshvrd 's branch |
1a15e21
to
b24fe96
Compare
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.
/lgtm
[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 |
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 #1887
Special notes for your reviewer:
/area provider/ibmcloud
Release note: