Skip to content

Cleanup NICs when migrate from openstack MCM - #89

Open
dergeberl wants to merge 18 commits into
mainfrom
removeNicsOnDeletion
Open

dergeberl wants to merge 18 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 involves migration of machines from OpenStack to STACKIT provider. There are mainly two controller involved in the change:

Creation
The newly created machine is created with STACKIT provider ID (stackit://project-id/server-id), and for the migrated machines with stackit.cloud/migrated-machine: true annotaion the creation will not work, to be sure not to mess with half created machines.

Delete
While deleting machine it needs to list and delete all ports if a machine with the stackit.cloud/migrated-machine annotation gets deleted.

NOTE: There is a fallback to get the server by name in case there is no providerID during deletion. Normally this is done with a label containing the machine name and a label selector. In case of a migrated machine with the stackit.cloud/migrated-machine annotation the deletion needs to get all servers and filters internally.

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
@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
Comment thread pkg/provider/create.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/client/sdk.go Outdated
Comment thread pkg/client/sdk.go Outdated
Comment thread pkg/client/sdk.go Outdated
Comment thread pkg/provider/delete.go
Comment thread pkg/provider/delete.go
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go
@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

Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
@nschad
nschad requested review from stackit-ske-bot and removed request for stackit-ske-bot September 14, 2026 12:13

@stackit-ske-bot stackit-ske-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SKE Code Review

Architectural Feedback

  • Server Deletion Synchronization & NIC Attachment Race:
    In pkg/provider/delete.go#L170-L183, WaitUntilServerDeleted is retained but is no longer invoked anywhere in the codebase (previously called after DeleteServer). As a consequence, p.client.DeleteServer initiates asynchronous VM termination, but deleteMachineNICs is called immediately afterwards. In STACKIT IaaS, deleting a NIC while its server is still shutting down / terminating will fail because the network interface remains bound to the active instance. Re-evaluating whether WaitUntilServerDeleted should be awaited prior to NIC cleanup prevents race conditions with STACKIT infrastructure during migrated machine teardown.
  • Simplification of Deletion Control Flow & Dead Code Elimination:
    In pkg/provider/delete.go#L53-L75, both deleteServers and deleteMachineNICs return (bool, error). However, both functions return (true, nil) whenever allErrors == nil. Because the boolean is always true on success, the conditional returns if serverAlreadyDeleted && !migrated and if nicAlreadyDeleted ensure that lines 72–74 (pkg/provider/delete.go#L72-L74) are completely unreachable. Refactoring deleteServers and deleteMachineNICs to return solely error simplifies the control flow, eliminates misleading variable naming (*AlreadyDeleted vs successful deletion), and allows completion logging to execute as intended.
  • Defensive Guard on providerSpec.Networking:
    In pkg/provider/delete.go#L64, providerSpec.Networking.NetworkID is dereferenced directly. In DeleteMachine, req.Secret is not validated through ValidateProviderSpecNSecret. If providerSpec.Networking is nil or specifies NICIDs instead of NetworkID, this causes a nil pointer dereference or an invalid STACKIT API call with an empty path parameter. Guarding this invocation with if migrated && providerSpec.Networking != nil && providerSpec.Networking.NetworkID != "" ensures safe teardown.

Findings & Feedback

  • All findings and concrete recommendations have been provided as inline code suggestions above.

Verdict

Comments with suggestions and architectural feedback.

Comment thread pkg/client/sdk.go Outdated
Comment thread pkg/provider/create.go Outdated
Comment thread pkg/provider/create.go Outdated
Comment thread pkg/provider/create.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
@ske-prow ske-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 16, 2026

@stackit-ske-bot stackit-ske-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SKE Code Review

Findings & Feedback

All findings and concrete recommendations have been provided as inline code suggestions above.

Verdict

Comments provided with inline suggestions for nil-pointer protection, dead code cleanup, error status code wrapping, and robust network ID handling.

Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
Comment thread pkg/provider/delete.go Outdated
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants