-
Notifications
You must be signed in to change notification settings - Fork 84
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
Refactor ReconcileNetwork #2040
base: main
Are you sure you want to change the base?
Refactor ReconcileNetwork #2040
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dharaneeshvrd The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
✅ Deploy Preview for kubernetes-sigs-cluster-api-ibmcloud ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
e39f7b8
to
bbef168
Compare
cloud/scope/powervs_cluster.go
Outdated
} | ||
return network.NetworkID, nil | ||
|
||
if nw != nil && !nw.DhcpManaged { |
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.
Do you think nw.DhcpManaged is required? We are getting network id from status and we set network id to status only when we create DHCP server.
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.
Ok I can remove this check.
cloud/scope/powervs_cluster.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
if err := s.verifyDHCPServerRespectToNetwork(*networkID); err != 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 this forces the user to set the dhcp network only. so we should update the api spec to mention it.
Also never tried what happens if we pass public network id here, Not relaying on DHCP.
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. I think we should use DHCP server only, during boot, CoreOS expects the ip from a DHCP server. I hope the case is same for vanilla capi cluster as well.
Shall I modify the API spec as part of this PR?
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 use Centos images in normal capi flow as well.
@mkumatag whats your thought. Should we make this restriction or do you foresee any other use cases.
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.
nope, we should allow both dhcp based and regular public networks.
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.
Ok, current code designed to handle only DHCP network. @Karthik-K-N We can create a story for this to handle later I believe. Wdyt?
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.
Yeah, That can be done.
fb3990c
to
fac8446
Compare
cloud/scope/powervs_cluster.go
Outdated
@@ -459,6 +463,14 @@ func (s *PowerVSClusterScope) SetStatus(resourceType infrav1beta2.ResourceType, | |||
} | |||
} | |||
|
|||
// GetNetworkID returns the Networkf id from status of IBMPowerVSCluster object. If it doesn't exist, returns 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.
// GetNetworkID returns the Networkf id from status of IBMPowerVSCluster object. If it doesn't exist, returns nil. | |
// GetNetworkID returns the Network id from status of IBMPowerVSCluster object. If it doesn't exist, returns nil. |
cloud/scope/powervs_cluster.go
Outdated
// if the user has provided the already existing dhcp server name then there might exist network name | ||
// with format DHCPSERVER<DHCPServer.Name>_Private , try fetching that | ||
var networkName string | ||
if s.DHCPServer() != nil && s.DHCPServer().Name != nil { | ||
networkName = fmt.Sprintf("DHCPSERVER%s_Private", *s.DHCPServer().Name) | ||
networkName = dhcpNetworkName(*s.DHCPServer().Name) | ||
} else { | ||
networkName = *s.GetServiceName(infrav1beta2.ResourceTypeNetwork) |
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.
is this required? as we are already checking this condition above
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 you please give me the ref? I think this is the only place where I am checking with cluster 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.
Thanks for clarifying, I understand it is required to preserve the order.
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.
Sure, addressed your other comments. ptal.
cloud/scope/powervs_cluster.go
Outdated
s.V(3).Info("Checking if PowerVS network exists in IBM Cloud with ID", "networkID", *s.IBMPowerVSCluster.Spec.Network.ID) | ||
network, err := s.IBMPowerVSClient.GetNetworkByID(*s.IBMPowerVSCluster.Spec.Network.ID) | ||
// checkNetwork checks if network exists in cloud with given network's ID or name or dhcp server's ID or name mentioned in spec. | ||
// Priority order: Network ID - Network name - DHCP server ID - DHCP server name - Network with cluster 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.
// Priority order: Network ID - Network name - DHCP server ID - DHCP server name - Network with cluster name. | |
// Priority order: Network ID > Network name > DHCP server ID > DHCP server name > Network with cluster name. |
3cc2ab9
to
8d6fe0c
Compare
41a3a74
to
22012f8
Compare
@Karthik-K-N @Amulyam24 I have refactored this PR to handle plain network and DHCP network separately. PTAL. |
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 flow looks neat and good, couple of questions
- Should we update this var name dhcpServerActive since we check for both network and dhcp?
- In a case where only network name or ID is set in spec, we do not check for associated dhcp servers right, is this to accommodate public network type?
cloud/scope/powervs_cluster.go
Outdated
return nil, err | ||
} | ||
s.SetStatus(infrav1beta2.ResourceTypeNetwork, infrav1beta2.ResourceReference{ID: dhcpServer.Network.ID, ControllerCreated: ptr.To(false)}) | ||
} else if *dhcpServer.Network.ID != *s.GetNetworkID() { |
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 there occur a scenario where dhcpServer.Network
is 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 don't think so, but have added a nil check for dhcpServer.Network
anyway, ptal.
22012f8
to
ee79e44
Compare
Agree, We mainly check network's active status, so kept
Yes that has become the goal of this PR, earlier I was assuming that network should belong to a DHCP server. Now it can be a separate entity, if user provides any field on |
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.
one minor suggestion, in UT, can we also verify the ControllerCreated
value wherever applicable?
/cc @Karthik-K-N
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.
ReconcileNetwork is very compilcated logic, Thank you for taking this up.
Few comments otherwise LGTM. Can we also mention in high level as comments over ReconcileNetwork() function what we are doing.
cloud/scope/powervs_cluster.go
Outdated
return false, err | ||
} | ||
if dhcpServerID != nil { | ||
s.V(3).Info("Found DHCP server in IBM Cloud", "DHCP Server ID", dhcpServerID) |
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.
To keep uniform and improve our logging, lets use , dhcpServerID
instead of "DHCP Server ID"
cloud/scope/powervs_cluster.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
return network.NetworkID, nil | ||
if s.GetNetworkID() == nil { | ||
if _, err := s.IBMPowerVSClient.GetNetworkByID(*dhcpServer.Network.ID); err != 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.
Is it safe to say that dhcpServer will be active by this time? If not the network may be nil.
I am just concerned about *dhcpServer.Network.ID
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.
Here we are validating existing DHCP server, new DHCP server creation won't reach this block, but anyway I have handled this via nil check, PTAL.
cloud/scope/powervs_cluster.go
Outdated
} else { | ||
networkName = *s.GetServiceName(infrav1beta2.ResourceTypeNetwork) | ||
networkName = dhcpNetworkName(s.InfraCluster()) | ||
} | ||
|
||
s.V(3).Info("Checking if PowerVS network exists in IBM Cloud with name", "name", networkName) |
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 log line should be updated to state that, we are trying to look for network from DHCPServer's network list
cloud/scope/powervs_cluster.go
Outdated
} | ||
|
||
if s.Network().Name != nil { | ||
s.V(3).Info("Checking if PowerVS network exists in IBM Cloud with 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.
Lets log network name also.
- If only IBMPowerVSCluster.Spec.Network is set, network would be validated and if exists already will get used as cluster’s network or a new network will be created via DHCP service. - If only IBMPowerVSCluster.Spec.DHCPServer is set, DHCP server would be validated and if exists already, will use DHCP server’s network as cluster network. If not a new DHCP service will be created and it’s network will be used. - If both IBMPowerVSCluster.Spec.Network & IBMPowerVSCluster.Spec.DHCPServer is set, network and DHCP server would be validated and if both exists already then network is belongs to given DHCP server or not would be validated.
ee79e44
to
205a6e2
Compare
@Karthik-K-N @Amulyam24 I have tried to address your comments, PTAL. |
@dharaneeshvrd: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
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 lets fix the failing test. Thank you.
@@ -847,18 +859,32 @@ func (s *PowerVSClusterScope) createServiceInstance() (*resourcecontrollerv2.Res | |||
return serviceInstance, nil | |||
} | |||
|
|||
// ReconcileNetwork reconciles network. | |||
// ReconcileNetwork reconciles network | |||
// If only IBMPowerVSCluster.Spec.Network is set, network would be validated and if exists already will get used as cluster’s network or a new network will be created via DHCP service. |
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 you also mention what happens when both network and dhcpserver is not set, Currently that configuration is used the most.
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 #1933
Special notes for your reviewer:
/area provider/ibmcloud
Release note: