Cleanup NICs when migrate from openstack MCM - #89
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
d542196 to
cf02b5c
Compare
|
Our project currently lacks enough active contributors to adequately respond to all PRs.
You can:
/lifecycle stale |
|
Our project currently lacks enough active contributors to adequately respond to all PRs.
You can:
/lifecycle rotten |
|
Our project currently lacks enough active contributors to adequately respond to all PRs.
You can:
/close |
|
@stackit-ske: Closed this PR. DetailsIn response to this:
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. |
|
/reopen |
|
@dergeberl: Reopened this PR. DetailsIn response to this:
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. |
|
/remove-lifecycle rotten |
|
|
||
| nics := make([]*NIC, 0) | ||
| for _, nic := range *res.Items { | ||
| nics = append(nics, convertSDKNICtoNIC(&nic)) |
There was a problem hiding this comment.
Is there a reason we use these convertSDKNICtoNIC? I know we did this also for servers but IMO there is really no reason, we could just use the SDK Type.
|
Our project currently lacks enough active contributors to adequately respond to all PRs.
You can:
/lifecycle stale |
|
/remove-lifecycle stale |
cf02b5c to
d47b553
Compare
55364f4 to
1e553c4
Compare
5b85955 to
17def4f
Compare
|
|
||
| if len(servers) > 1 { | ||
| klog.Errorf("Multiple servers already exists for this machine %q: %v", req.Machine.Name, err) | ||
| return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("failed to fetch server: %v", err)) |
There was a problem hiding this comment.
| return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("failed to fetch server: %v", err)) | |
| return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("multiple servers found: %v", err)) |
Also err is most likely nil here. Refactor this. We should print here all the ids or so
| func (p *Provider) serverIDsForMachine(ctx context.Context, req *driver.DeleteMachineRequest, secretProjectID, region string, migrated bool) (projectID string, serverIDs []string, err error) { | ||
| projectID, serverIDs = "", nil | ||
| if providerID := req.Machine.Spec.ProviderID; providerID != "" { | ||
| if !strings.HasPrefix(providerID, StackitProviderName) { |
There was a problem hiding this comment.
| if !strings.HasPrefix(providerID, StackitProviderName) { | |
| if !strings.HasPrefix(providerID, StackitProviderName + "://") { |
This only checks if the prefix is "stackit"
|
|
||
| nics := make([]*NIC, 0, len(res.Items)) | ||
| for i := range res.Items { | ||
| nics = append(nics, convertSDKNICtoNIC(&res.Items[i])) |
There was a problem hiding this comment.
can be addressed by index since the sice is known, instead of using append()
| func getStringValue(s *string) string { | ||
| if s == nil { | ||
| return "" | ||
| } | ||
| return *s | ||
| } |
There was a problem hiding this comment.
| func getStringValue(s *string) string { | |
| if s == nil { | |
| return "" | |
| } | |
| return *s | |
| } |
| AllowedAddresses: addresses, | ||
| IPv4: nic.GetIpv4(), | ||
| IPv6: nic.GetIpv6(), | ||
| Name: getStringValue(nic.Name), |
There was a problem hiding this comment.
| Name: getStringValue(nic.Name), | |
| Name: nic.GetName(), |
| return nil, status.Error(codes.Internal, err.Error()) | ||
| } | ||
|
|
||
| migrated, _ := strconv.ParseBool(req.Machine.Annotations[migratedMachineAnnotation]) |
There was a problem hiding this comment.
Should add comment here that missing annotation is to be treated as false
Also the error of strconv.ParseBool() is ignored!
| } | ||
|
|
||
| migrated, _ := strconv.ParseBool(req.Machine.Annotations[migratedMachineAnnotation]) | ||
| projectID, serverIDs, err := p.serverIDsForMachine(ctx, req, projectIDFromSecret, providerSpec.Region, migrated) |
There was a problem hiding this comment.
Why does this return multiple serverIDs?
|
|
||
| // Parse ProviderID to extract projectID and serverID | ||
| projectID, serverID, err = parseProviderID(req.Machine.Spec.ProviderID) | ||
| func (p *Provider) serverIDsForMachine(ctx context.Context, req *driver.DeleteMachineRequest, secretProjectID, region string, migrated bool) (projectID string, serverIDs []string, err error) { |
There was a problem hiding this comment.
| func (p *Provider) serverIDsForMachine(ctx context.Context, req *driver.DeleteMachineRequest, secretProjectID, region string, migrated bool) (projectID string, serverIDs []string, err error) { | |
| func (p *Provider) serverIDsForMachine(ctx context.Context, req *driver.DeleteMachineRequest, projectIDFromSecret, region string, migrated bool) (projectID string, serverIDs []string, err error) { |
There was a problem hiding this comment.
Add massive docstring. Explain in detail what this does
| if serverID == "" { | ||
| klog.V(2).Infof("Server is already deleted for machine %q", req.Machine.Name) | ||
| return &driver.DeleteMachineResponse{}, nil | ||
| func (p *Provider) deleteServers(ctx context.Context, projectID, region, machineName string, serverIDs []string) (bool, error) { |
There was a problem hiding this comment.
Why plural? Also you return out of function instantly as soon as you get a 404, what about the other serverIDs?
| // Call STACKIT API to delete server | ||
| err = p.client.DeleteServer(ctx, projectID, providerSpec.Region, serverID) | ||
| func (p *Provider) deleteMachineNICs(ctx context.Context, projectID, region, networkID, machineName string) (bool, error) { | ||
| nics, err := p.client.ListNICs(ctx, projectID, region, networkID) |
|
@aniruddha2000 Please add A LOT of documentation explaining this PR and the individual functions |
How to categorize this PR?
/kind enhancement
/hold
wip
What this PR does / why we need it:
This PR clean up NICs associated with servers when deleting machines.
Special notes for your reviewer:
Breaking changes: