Skip to content

Cleanup NICs when migrate from openstack MCM - #89

Open
dergeberl wants to merge 5 commits into
mainfrom
removeNicsOnDeletion
Open

Cleanup NICs when migrate from openstack MCM#89
dergeberl wants to merge 5 commits into
mainfrom
removeNicsOnDeletion

Conversation

@dergeberl

@dergeberl dergeberl commented Jan 22, 2026

Copy link
Copy Markdown
Member

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:

@ske-prow ske-prow Bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/enhancement Enhancement, improvement, extension do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jan 22, 2026
@ske-prow

ske-prow Bot commented Jan 22, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nschad for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@ske-prow ske-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 22, 2026
@dergeberl
dergeberl force-pushed the removeNicsOnDeletion branch 3 times, most recently from d542196 to cf02b5c Compare January 22, 2026 11:31
@ske-prow ske-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 22, 2026
@stackit-ske

Copy link
Copy Markdown

Our project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:

  • After 15d of inactivity, lifecycle/stale is applied
  • After 15d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 7d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Mark this PR as rotten with /lifecycle rotten
  • Close this PR with /close

/lifecycle stale

@ske-prow ske-prow Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 6, 2026
@stackit-ske

Copy link
Copy Markdown

Our project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:

  • After 15d of inactivity, lifecycle/stale is applied
  • After 15d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 7d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close

/lifecycle rotten

@ske-prow ske-prow Bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 21, 2026
@stackit-ske

Copy link
Copy Markdown

Our project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:

  • After 15d of inactivity, lifecycle/stale is applied
  • After 15d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 7d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten

/close

@ske-prow ske-prow Bot closed this Feb 28, 2026
@ske-prow

ske-prow Bot commented Feb 28, 2026

Copy link
Copy Markdown

@stackit-ske: Closed this PR.

Details

In response to this:

Our project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:

  • After 15d of inactivity, lifecycle/stale is applied
  • After 15d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 7d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten

/close

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.

@dergeberl

Copy link
Copy Markdown
Member Author

/reopen

@ske-prow ske-prow Bot reopened this Mar 2, 2026
@ske-prow

ske-prow Bot commented Mar 2, 2026

Copy link
Copy Markdown

@dergeberl: Reopened this PR.

Details

In response to this:

/reopen

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.

@dergeberl

Copy link
Copy Markdown
Member Author

/remove-lifecycle rotten

@ske-prow ske-prow Bot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Mar 2, 2026
Comment thread pkg/client/sdk.go Outdated

nics := make([]*NIC, 0)
for _, nic := range *res.Items {
nics = append(nics, convertSDKNICtoNIC(&nic))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@stackit-ske

Copy link
Copy Markdown

Our project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:

  • After 15d of inactivity, lifecycle/stale is applied
  • After 15d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 7d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Mark this PR as rotten with /lifecycle rotten
  • Close this PR with /close

/lifecycle stale

@ske-prow ske-prow Bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 17, 2026
@dergeberl

Copy link
Copy Markdown
Member Author

/remove-lifecycle stale

@ske-prow ske-prow Bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 20, 2026
@dergeberl dergeberl added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Mar 20, 2026
@ske-prow ske-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 27, 2026
@ske-prow ske-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 27, 2026
@aniruddha2000 aniruddha2000 changed the title WIP: Cleanup NICs when migrate from openstack MCM Cleanup NICs when migrate from openstack MCM Sep 7, 2026
@ske-prow ske-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 7, 2026
dergeberl and others added 5 commits September 7, 2026 13:52
Comment thread pkg/provider/create.go

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Comment thread pkg/provider/delete.go
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !strings.HasPrefix(providerID, StackitProviderName) {
if !strings.HasPrefix(providerID, StackitProviderName + "://") {

This only checks if the prefix is "stackit"

Comment thread pkg/client/sdk.go

nics := make([]*NIC, 0, len(res.Items))
for i := range res.Items {
nics = append(nics, convertSDKNICtoNIC(&res.Items[i]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can be addressed by index since the sice is known, instead of using append()

Comment thread pkg/client/sdk.go
Comment on lines +397 to +402
func getStringValue(s *string) string {
if s == nil {
return ""
}
return *s
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
func getStringValue(s *string) string {
if s == nil {
return ""
}
return *s
}

Comment thread pkg/client/sdk.go
AllowedAddresses: addresses,
IPv4: nic.GetIpv4(),
IPv6: nic.GetIpv6(),
Name: getStringValue(nic.Name),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Name: getStringValue(nic.Name),
Name: nic.GetName(),

Comment thread pkg/provider/delete.go
return nil, status.Error(codes.Internal, err.Error())
}

migrated, _ := strconv.ParseBool(req.Machine.Annotations[migratedMachineAnnotation])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should add comment here that missing annotation is to be treated as false

Also the error of strconv.ParseBool() is ignored!

Comment thread pkg/provider/delete.go
}

migrated, _ := strconv.ParseBool(req.Machine.Annotations[migratedMachineAnnotation])
projectID, serverIDs, err := p.serverIDsForMachine(ctx, req, projectIDFromSecret, providerSpec.Region, migrated)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this return multiple serverIDs?

Comment thread pkg/provider/delete.go

// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add massive docstring. Explain in detail what this does

Comment thread pkg/provider/delete.go
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why plural? Also you return out of function instantly as soon as you get a 404, what about the other serverIDs?

Comment thread pkg/provider/delete.go
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above.

@nschad

nschad commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@aniruddha2000 Please add A LOT of documentation explaining this PR and the individual functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/enhancement Enhancement, improvement, extension lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants