provider

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package provider contains the cloud provider specific implementations to manage machines

Package provider contains the cloud provider specific implementations to manage machines

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServerNotFound indicates the server was not found (404)
	ErrServerNotFound = errors.New("server not found")
)

Functions

func NewProvider

NewProvider returns an empty provider object

Types

type AgentRequest

type AgentRequest struct {
	Provisioned *bool `json:"provisioned,omitempty"`
}

AgentRequest represents the STACKIT agent configuration for a server

type BootVolumeRequest

type BootVolumeRequest struct {
	DeleteOnTermination *bool                    `json:"deleteOnTermination,omitempty"`
	PerformanceClass    string                   `json:"performanceClass,omitempty"`
	Size                int                      `json:"size,omitempty"`
	Source              *BootVolumeSourceRequest `json:"source,omitempty"`
}

BootVolumeRequest represents the boot volume configuration for a server

type BootVolumeSourceRequest

type BootVolumeSourceRequest struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

BootVolumeSourceRequest represents the source for creating a boot volume

type CreateServerRequest

type CreateServerRequest struct {
	Name                string                   `json:"name"`
	MachineType         string                   `json:"machineType"`
	ImageID             string                   `json:"imageId,omitempty"`
	Labels              map[string]string        `json:"labels,omitempty"`
	Networking          *ServerNetworkingRequest `json:"networking"` // Required in v2 API, no omitempty
	SecurityGroups      []string                 `json:"securityGroups,omitempty"`
	UserData            string                   `json:"userData,omitempty"`
	BootVolume          *BootVolumeRequest       `json:"bootVolume,omitempty"`
	Volumes             []string                 `json:"volumes,omitempty"`
	KeypairName         string                   `json:"keypairName,omitempty"`
	AvailabilityZone    string                   `json:"availabilityZone,omitempty"`
	AffinityGroup       string                   `json:"affinityGroup,omitempty"`
	ServiceAccountMails []string                 `json:"serviceAccountMails,omitempty"`
	Agent               *AgentRequest            `json:"agent,omitempty"`
	Metadata            map[string]interface{}   `json:"metadata,omitempty"`
}

CreateServerRequest represents the request to create a server

type Provider

type Provider struct {
	SPI spi.SessionProviderInterface
	// contains filtered or unexported fields
}

Provider is the struct that implements the driver interface It is used to implement the basic driver functionalities

Architecture: Single-tenant design - Each provider instance is deployed per Gardener shoot (cluster) - The STACKIT IaaS client is initialized lazily on first request using credentials from the Secret - All subsequent requests reuse the same client (SDK handles token refresh automatically) - Credential rotation requires pod restart (standard Kubernetes pattern)

func (*Provider) CreateMachine

CreateMachine handles a machine creation request by creating a STACKIT server

This method creates a new server in STACKIT infrastructure based on the ProviderSpec configuration in the MachineClass. It assigns MCM-specific labels to the server for tracking and orphan VM detection.

Returns:

  • ProviderID: Unique identifier in format "stackit://<projectId>/<serverId>"
  • NodeName: Name that the VM will register with in Kubernetes (matches Machine name)

Error codes:

  • InvalidArgument: Invalid ProviderSpec or missing required fields
  • Internal: Failed to create server or communicate with STACKIT API

func (*Provider) DeleteMachine

DeleteMachine handles a machine deletion request by deleting the STACKIT server

This method deletes the server identified by the ProviderID from STACKIT infrastructure. It is idempotent - if the server is already deleted (404), it returns success.

Error codes:

  • InvalidArgument: Missing or invalid ProviderID
  • Internal: Failed to delete server or communicate with STACKIT API

func (*Provider) GenerateMachineClassForMigration

GenerateMachineClassForMigration generates a MachineClass for migration purposes

This method is used to migrate from provider-specific MachineClass CRDs (e.g., AWSMachineClass) to the generic MachineClass format.

STACKIT provider does not have a legacy provider-specific MachineClass format, so this method is not needed and returns Unimplemented.

Returns:

  • Unimplemented: No migration required for STACKIT provider

func (*Provider) GetMachineStatus

GetMachineStatus retrieves the current status of a STACKIT server

This method queries STACKIT API to get the current state of the server identified by the Machine's ProviderID. If the ProviderID is empty (machine not created yet) or the server doesn't exist, it returns NotFound error.

Returns:

  • ProviderID: The machine's ProviderID
  • NodeName: Name that the VM registered with in Kubernetes

Error codes:

  • NotFound: Machine has no ProviderID yet, or server not found in STACKIT
  • InvalidArgument: Invalid ProviderID format
  • Internal: Failed to get server status or communicate with STACKIT API

func (*Provider) GetVolumeIDs

GetVolumeIDs extracts volume IDs from PersistentVolume specs

This method is used by MCM to get volume IDs for persistent volumes. Currently unimplemented for STACKIT provider - volumes are managed directly through the ProviderSpec (bootVolume and volumes fields).

Returns:

  • Unimplemented: This functionality is not required for STACKIT provider

func (*Provider) InitializeMachine

InitializeMachine handles VM initialization for STACKIT VM's. Currently, un-implemented.

func (*Provider) ListMachines

ListMachines lists all STACKIT servers that belong to the specified MachineClass

This method retrieves all servers in the STACKIT project and filters them based on the "mcm.gardener.cloud/machineclass" label. This enables the MCM safety controller to detect and clean up orphan VMs that are not backed by Machine CRs.

Returns:

  • MachineList: Map of ProviderID to MachineName for all servers matching the MachineClass

Error codes:

  • Internal: Failed to list servers or communicate with STACKIT API

type SdkStackitClient

type SdkStackitClient struct {
	// contains filtered or unexported fields
}

SdkStackitClient is an SDK implementation of StackitClient Each instance handles a single STACKIT project (single-tenant design) The IaaS client is created once and reused across all requests The SDK automatically handles token refresh and re-authentication

func NewStackitClient

func NewStackitClient(serviceAccountKey string) (*SdkStackitClient, error)

NewStackitClient creates a new SDK STACKIT client wrapper with the IaaS client The serviceAccountKey is used for authentication (ServiceAccount Key Flow) The client is created once and reused for all subsequent requests

func (*SdkStackitClient) CreateServer

func (c *SdkStackitClient) CreateServer(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error)

CreateServer creates a new server via STACKIT SDK

func (*SdkStackitClient) DeleteServer

func (c *SdkStackitClient) DeleteServer(ctx context.Context, projectID, region, serverID string) error

DeleteServer deletes a server by ID via STACKIT SDK

func (*SdkStackitClient) GetServer

func (c *SdkStackitClient) GetServer(ctx context.Context, projectID, region, serverID string) (*Server, error)

GetServer retrieves a server by ID via STACKIT SDK

func (*SdkStackitClient) ListServers

func (c *SdkStackitClient) ListServers(ctx context.Context, projectID, region string) ([]*Server, error)

ListServers lists all servers in a project via STACKIT SDK

type Server

type Server struct {
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	Status string            `json:"status"`
	Labels map[string]string `json:"labels,omitempty"`
}

Server represents a STACKIT server response

type ServerNetworkingRequest

type ServerNetworkingRequest struct {
	NetworkID string   `json:"networkId,omitempty"`
	NICIDs    []string `json:"nicIds,omitempty"`
}

ServerNetworkingRequest represents the networking configuration for a server

Union type - use one of the following (mutually exclusive):

  • NetworkID: Auto-create a NIC in the specified network (takes precedence)
  • NICIDs: Attach pre-existing NICs to the server

If both are specified, NetworkID takes precedence and NICIDs is ignored.

type StackitClient

type StackitClient interface {
	// CreateServer creates a new server in STACKIT
	CreateServer(ctx context.Context, projectID, region string, req *CreateServerRequest) (*Server, error)
	// GetServer retrieves a server by ID from STACKIT
	GetServer(ctx context.Context, projectID, region, serverID string) (*Server, error)
	// DeleteServer deletes a server by ID from STACKIT
	DeleteServer(ctx context.Context, projectID, region, serverID string) error
	// ListServers lists all servers in a project
	ListServers(ctx context.Context, projectID, region string) ([]*Server, error)
}

StackitClient is an interface for interacting with STACKIT IAAS API This allows us to mock the client in unit tests

Architecture: Single-tenant design - Each client instance is bound to one STACKIT project via serviceAccountKey - The serviceAccountKey is provided once during client creation (NewStackitClient) - The SDK automatically handles JWT token generation and refresh

Note: region parameter is required by STACKIT SDK v1.0.0+ It must be extracted from the Secret (e.g., "eu01-1", "eu01-2")

Directories

Path Synopsis
validation
Package validation - validation is used to validate cloud specific ProviderSpec
Package validation - validation is used to validate cloud specific ProviderSpec

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL