Skip to content

Conversation

@eshulman2
Copy link
Contributor

@eshulman2 eshulman2 commented Nov 16, 2025

Summary

This PR implements full KeyPair controller support and integrates it with the Server resource, enabling SSH key management and server access control through Kubernetes resources.

Changes

Commit 1: Add KeyPair controller implementation

Implements complete KeyPair resource controller with the following features:

API & Types:

  • KeyPair CRD with spec for both importing existing keys and uploading
  • KeyPairImport for importing public keys from secrets
  • KeyPairSpec for OpenStack resource creation with public key
  • Validation for immutability (keypairs cannot be updated in OpenStack)

Controller Implementation:

  • Client-side name filtering for import/adoption (OpenStack API only supports userID filtering)
  • Deletion guard support through dependency system
  • Status reporting with resource details (fingerprint, type, public key)

Commit 2: Add keypair integration to Server resource

Enables servers to be created with SSH keypairs for access:

API Changes:

  • Added optional keypairRef field to ServerResourceSpec
  • Marked as immutable (matches OpenStack behavior - can't change after creation)

Controller Changes:

  • Added keypair dependency watch (triggers reconciliation when keypair becomes Available)
  • No deletion guard since keypairs are only injected during server boot

Actuator Changes:

  • Fetch and validate referenced KeyPair exists and is Available before server creation
  • Use gophercloud's keypairs.CreateOptsExt extension pattern to inject key_name
  • Get actual OpenStack keypair name from keypair.Status.Resource.Name

Notes

  • KeyPairs are immutable in OpenStack Nova API, so spec changes after creation will be rejected
  • The keypair name in OpenStack may differ from the CR name if spec.resource.name is set
  • No deletion guard on server->keypair reference since keypairs are only injected at boot time

Fixes: #136

Assisted-by: claude

@eshulman2 eshulman2 marked this pull request as draft November 16, 2025 14:36
@github-actions github-actions bot added the semver:major Breaking change label Nov 16, 2025
@eshulman2 eshulman2 changed the title Add KeyPair controller implementation Add KeyPair controller with Server integration Nov 17, 2025
@mandre
Copy link
Collaborator

mandre commented Nov 18, 2025

Hey Ella, if you could split your work in multiple commits that would help with the review.

I have found it very helpful, when working on controllers after we created the scaffolding tool, to have at least 2 separate commits:

  • the first one that just runs the scaffolding tool and commits all the generated files. We should write the exact command we ran in the commit message for reproducibility.
  • a second commit that fills the blank and effectively implements the specific parts of the controller, including the API changes and the tests.
  • more commits as necessary, such as adding keypair support to servers like you did.

I'll try to have a first pass at your work today.

@eshulman2
Copy link
Contributor Author

eshulman2 commented Nov 18, 2025

Hi @mandre I'll work on splitting it tomorrow just 1 missing thing that I already know is missing as I haven't got to is is kuttl testing for the integration with the existing server controller so I'll try to get that into the patch tomorrow as well.

@eshulman2 eshulman2 force-pushed the keypair branch 3 times, most recently from 9052675 to 86592b4 Compare November 19, 2025 15:30
@winiciusallan
Copy link
Contributor

Hi, @eshulman2. Thanks for the work! Before reviewing, I want to confirm one thing.

Do we want to support compute API microversions before 2.92? I ask because the generation of key pairs has been removed from the Nova API.[1][2]

[1] https://specs.openstack.org/openstack/nova-specs/specs/zed/implemented/keypair-generation-removal.html
[2] https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion-2-92

@mandre
Copy link
Collaborator

mandre commented Nov 21, 2025

@winiciusallan raised a good point. I believe we should remove the ability to generate keypairs as it's gone from nova.

BTW, I'm getting a different result than the one you have in the first commit when running the command from the commit message. I assume you passed arguments interactively. May I suggest you add the -interactive=false flag to your command line? It also seems like you've marked Project as a required dependency at creation, which seems odd.

@eshulman2 eshulman2 force-pushed the keypair branch 2 times, most recently from f509d42 to c53a3ca Compare November 23, 2025 13:12
@eshulman2
Copy link
Contributor Author

eshulman2 commented Nov 23, 2025

Hi @winiciusallan , @mandre I believe those issues should be fixed. I encountered another issue with the KeyPairImport. keypairs uses names as their UUID and doesn't have an ID that matches the existing ID validation (kubebuilder:validation:Format:=uuid). This is currently a problem for the keypairimport as it is generated expecting to work with a UUID. I added a flag to the templates to allow having a non kubebuilder:validation:Format:=uuid validation for the name based id.

@winiciusallan
Copy link
Contributor

Hi @winiciusallan , @mandre I believe those issues should be fixed. I encountered another issue with the KeyPairImport. keypairs uses names as their UUID and doesn't have an ID that matches the existing ID validation (kubebuilder:validation:Format:=uuid). This is currently a problem for the keypairimport as it is generated expecting to work with a UUID. I added a flag to the templates to allow having a non kubebuilder:validation:Format:=uuid validation for the name based id.

That's ok for me. There are still cases which we currently don't handle yet, so adding a new spec for it seems good.

Btw, I'll try to take a look at your code today or at the latest tomorrow.

@eshulman2 eshulman2 force-pushed the keypair branch 8 times, most recently from 470b043 to a02dcda Compare November 26, 2025 13:39
@github-actions github-actions bot removed the semver:major Breaking change label Nov 26, 2025
@github-actions
Copy link

Failed to assess the semver bump. See logs for details.

Keypairs in openstack uses names instead of ID to enable proper
generation of Imports and other add a template option to allow it
command:
go run ./cmd/scaffold-controller \
-kind KeyPair \
-gophercloud-client "NewComputeV2" \
-gophercloud-module "github.com/gophercloud/gophercloud/v2/openstack/compute/v2/keypairs" \
-gophercloud-type "KeyPair" \
-openstack-json-object "keypair"
This commit adds complete KeyPair controller support including:
- API types with validation for public key import and creation
- Controller implementation with client-side name filtering for import/adoption
- Unit tests for filtering logic with mock client
- KUTTL integration tests for create, import, and error scenarios
- CRD, RBAC, and sample manifests

KeyPairs are immutable resources where the name serves as the unique identifier.
The OpenStack KeyPairs API only supports server-side userID filtering, so
client-side filtering is implemented for name-based import and adoption.

issue: k-orc#136

Assisted-by: Claude
Enables servers to be created with SSH keypairs by adding optional
keypairRef field to ServerResourceSpec. Uses gophercloud's
keypairs.CreateOptsExt to inject key_name into server creation.

The keypair dependency is watched but has no deletion guard since
keypairs are only injected during server boot.

Assisted-by: claude
Copy link
Collaborator

@mandre mandre left a comment

Choose a reason for hiding this comment

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

Awesome work! Ready to merge.

@mandre mandre added this pull request to the merge queue Nov 26, 2025
Merged via the queue into k-orc:main with commit cfc670f Nov 26, 2025
9 checks passed
@mandre mandre added this to the Release 2.4 milestone Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:major Breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keypair support

3 participants