Documentation
¶
Overview ¶
Package openstack provides OpenStack-specific functionality.
This package contains functions for performing preflight checks and other operations related to OpenStack.
When to use ¶
This package is used internally by opencenter for OpenStack discovery, storage, and bootstrap validation. Its bootstrap preflight helper is not part of the cluster-independent `cluster doctor` command.
Index ¶
- Constants
- func DefaultCloudsYAMLPath() string
- func EnsureApplicationCredential(ctx context.Context, profile Profile, provisioner AppCredentialProvisioner, ...) (AppCredential, Profile, error)
- func PreflightOpenStack(authURL string) []string
- type AccessRule
- type AppCredential
- type AppCredentialProvisioner
- type AppCredentialRequest
- type CatalogItem
- type ContainerRequest
- type CredentialCheckOptions
- type CredentialHealth
- type DiscoveryCatalog
- type DiscoveryClient
- type DiscoveryOptions
- type DiscoverySnapshot
- type EC2CredentialRequest
- type EC2Credentials
- type GophercloudDiscoveryClient
- type GophercloudStorageAdapter
- func (a *GophercloudStorageAdapter) CreateAppCredential(ctx context.Context, req AppCredentialRequest) (AppCredential, error)
- func (a *GophercloudStorageAdapter) CreateEC2Credentials(ctx context.Context, req EC2CredentialRequest) (EC2Credentials, error)
- func (a *GophercloudStorageAdapter) DeleteAppCredential(ctx context.Context, id, userID string) error
- func (a *GophercloudStorageAdapter) DeleteEC2Credentials(ctx context.Context, id, userID string) error
- func (a *GophercloudStorageAdapter) EnsureContainer(ctx context.Context, req ContainerRequest) error
- func (a *GophercloudStorageAdapter) Preflight(ctx context.Context, backend, explicitS3Endpoint string, resolveOwner bool) (StoragePreflight, error)
- type Profile
- type ProfileDiscovery
- type Provider
- func (p *Provider) DetectDrift(ctx context.Context, desired, actual *cloud.InfrastructureState) (*cloud.DriftReport, error)
- func (p *Provider) GetCurrentState(ctx context.Context, cfg v2.Config) (*cloud.InfrastructureState, error)
- func (p *Provider) ReconcileDrift(ctx context.Context, drift *cloud.DriftReport) error
- type Resource
- type StorageAdapter
- type StoragePreflight
- type Subnet
Constants ¶
const DefaultApplicationCredentialName = "opencenter"
DefaultApplicationCredentialName is the credential name used when the caller does not choose one.
Variables ¶
This section is empty.
Functions ¶
func DefaultCloudsYAMLPath ¶
func DefaultCloudsYAMLPath() string
DefaultCloudsYAMLPath returns the standard OpenStack client configuration path, respecting the conventional override used by openstacksdk and OSC.
func EnsureApplicationCredential ¶
func EnsureApplicationCredential(ctx context.Context, profile Profile, provisioner AppCredentialProvisioner, name string) (AppCredential, Profile, error)
EnsureApplicationCredential returns a persistable application credential ID and secret for the profile, minting one when the profile has none.
The three profile credential shapes behave differently:
- ID + secret: already persistable; returned unchanged, nothing created.
- name + secret: cannot be persisted. The cluster config stores an application-credential ID (OpenTofu and the rendered services consume the ID), and a name is only resolvable against the issuing user, so a name-only credential is replaced by a freshly minted ID/secret pair.
- no credential at all (username/password profile): a credential is minted so the cluster never depends on a raw password.
A minted pair is written back into the profile's clouds.yaml before being returned: the secret is only available in the create response, so a failure to persist is fatal rather than a silent loss. The write preserves the rest of the file and is performed atomically with 0600 permissions.
func PreflightOpenStack ¶
PreflightOpenStack performs provider-specific preflight checks for OpenStack. It checks for the presence of the `openstack` CLI tool and verifies that the authentication URL is configured.
This check is deliberately offline: it never contacts Keystone. Deploy time must use ValidateOpenStackCredentials, which authenticates for real.
Inputs:
- authURL: The OpenStack authentication URL.
Outputs:
- []string: A list of warning messages. If the list is empty, all checks passed.
Types ¶
type AccessRule ¶
type AppCredential ¶
type AppCredentialProvisioner ¶
type AppCredentialProvisioner interface {
CreateApplicationCredential(ctx context.Context, profile Profile, name, description string) (AppCredential, error)
}
AppCredentialProvisioner creates an OpenStack application credential for the authenticated profile user. The real implementation talks to Keystone; tests replace it to exercise the persist-and-return flow without a live cloud.
func NewAppCredentialProvisioner ¶
func NewAppCredentialProvisioner() AppCredentialProvisioner
NewAppCredentialProvisioner returns the live Keystone provisioner.
type AppCredentialRequest ¶
type AppCredentialRequest struct {
UserID string
Name string
Description string
AccessRules []AccessRule
}
type CatalogItem ¶
type ContainerRequest ¶
type CredentialCheckOptions ¶
type CredentialCheckOptions struct {
AuthURL string
Region string
ApplicationCredentialID string
ApplicationCredentialSecret string
Domain string
TenantName string
ProjectName string
ProjectDomainName string
UserDomainName string
Insecure bool
Username string
Password string
}
CredentialCheckOptions describes the credentials and expectations that ValidateOpenStackCredentials authenticates and asserts.
type CredentialHealth ¶
type CredentialHealth struct {
// Authenticated reports that Keystone accepted the credentials.
Authenticated bool
// TokenRegion is the region_name reported by the token, when the cloud
// provides one.
TokenRegion string
// CatalogRegions are the distinct regions advertised by the service
// catalog. Many clouds omit token.region_name, so the catalog is the
// authoritative fallback for the region assertion.
CatalogRegions []string
}
CredentialHealth is the outcome of a live Keystone authentication attempt.
func ValidateOpenStackCredentials ¶
func ValidateOpenStackCredentials(ctx context.Context, opts CredentialCheckOptions) (*CredentialHealth, error)
ValidateOpenStackCredentials authenticates against Keystone for real and asserts that the configured region is served by the configured auth_url.
It exists because auth_url is consumed verbatim by everything that runs inside the cluster: the rendered OpenStack cloud-controller-manager cloudConfig and the cinder CSI cloud.conf both embed it. A credential that was issued in a different region than auth_url points at is rejected by Keystone with 404 "Could not find Application Credential". That is invisible at provision time when OpenTofu authenticates through OS_* environment variables which happen to resolve correctly, so deploy reports success while every in-cluster consumer is permanently broken: the CCM never initializes nodes, the cloud-provider-uninitialized taint is never removed, and the cluster is left unschedulable. Catching it here fails deploy at preflight.
The returned error never contains the credential secret.
type DiscoveryCatalog ¶
type DiscoveryCatalog struct {
Images []CatalogItem
Flavors []CatalogItem
Networks []CatalogItem
Subnets []CatalogItem
ExternalNetworks []CatalogItem
AvailabilityZones []CatalogItem
DesignateAvailable bool
}
type DiscoveryClient ¶
type DiscoveryClient interface {
Discover(ctx context.Context, cfg *v2.Config) (*DiscoveryCatalog, error)
}
func NewDiscoveryClient ¶
func NewDiscoveryClient() DiscoveryClient
type DiscoveryOptions ¶
type DiscoveryOptions struct {
SkipInternalNetworkAndSubnet bool
}
DiscoveryOptions controls optional inventory reads.
type DiscoverySnapshot ¶
type DiscoverySnapshot struct {
AuthURL string
Region string
ProjectID string
ProjectName string
UserDomainName string
ProjectDomainName string
DomainName string
Insecure bool
CA string
AvailabilityZonesAvailable bool
Images []Resource
WindowsImages []Resource
Networks []Resource
Subnets []Subnet
ExternalNetworks []Resource
AvailabilityZones []Resource
Flavors []Resource
Warnings []string
}
DiscoverySnapshot is a read-only inventory and profile metadata snapshot.
type EC2CredentialRequest ¶
type EC2Credentials ¶
type GophercloudDiscoveryClient ¶
type GophercloudDiscoveryClient struct{}
func (*GophercloudDiscoveryClient) Discover ¶
func (c *GophercloudDiscoveryClient) Discover(ctx context.Context, cfg *v2.Config) (*DiscoveryCatalog, error)
type GophercloudStorageAdapter ¶
type GophercloudStorageAdapter struct{ Profile Profile }
func NewStorageAdapter ¶
func NewStorageAdapter(profile Profile) *GophercloudStorageAdapter
func (*GophercloudStorageAdapter) CreateAppCredential ¶
func (a *GophercloudStorageAdapter) CreateAppCredential(ctx context.Context, req AppCredentialRequest) (AppCredential, error)
func (*GophercloudStorageAdapter) CreateEC2Credentials ¶
func (a *GophercloudStorageAdapter) CreateEC2Credentials(ctx context.Context, req EC2CredentialRequest) (EC2Credentials, error)
func (*GophercloudStorageAdapter) DeleteAppCredential ¶
func (a *GophercloudStorageAdapter) DeleteAppCredential(ctx context.Context, id, userID string) error
func (*GophercloudStorageAdapter) DeleteEC2Credentials ¶
func (a *GophercloudStorageAdapter) DeleteEC2Credentials(ctx context.Context, id, userID string) error
func (*GophercloudStorageAdapter) EnsureContainer ¶
func (a *GophercloudStorageAdapter) EnsureContainer(ctx context.Context, req ContainerRequest) error
func (*GophercloudStorageAdapter) Preflight ¶
func (a *GophercloudStorageAdapter) Preflight(ctx context.Context, backend, explicitS3Endpoint string, resolveOwner bool) (StoragePreflight, error)
type Profile ¶
type Profile struct {
Name string
AuthURL string
Username string
UserID string
Password string
ProjectID string
ProjectName string
Region string
S3Endpoint string
Interface string
DomainName string
UserDomain string
ProjectDomain string
AppCredID string
AppCredName string
AppCredSecret string
CACert string
Cert string
Key string
Insecure bool
Verify *bool
// SourcePath is the clouds.yaml the profile was loaded from. It is the
// only writable handle the profile carries, used by
// EnsureApplicationCredential to persist a minted credential back to the
// same file the operator selected with --os-cloud.
SourcePath string
}
Profile is the read-only representation of one clouds.yaml profile. Secret fields are retained for authentication but are never included in results.
func LoadProfile ¶
LoadProfile reads a selected profile without authenticating or mutating a remote resource.
func (Profile) AuthOptions ¶
func (p Profile) AuthOptions() gophercloud.AuthOptions
type ProfileDiscovery ¶
type ProfileDiscovery struct{ Profile Profile }
ProfileDiscovery performs only OpenStack reads. Optional compute inventory failures are returned as warnings because provider wiring does not require flavor matching or availability-zone enumeration by default.
func NewProfileDiscovery ¶
func NewProfileDiscovery(profile Profile) *ProfileDiscovery
func (*ProfileDiscovery) Discover ¶
func (d *ProfileDiscovery) Discover(ctx context.Context) (*DiscoverySnapshot, error)
func (*ProfileDiscovery) DiscoverWithOptions ¶
func (d *ProfileDiscovery) DiscoverWithOptions(ctx context.Context, opts DiscoveryOptions) (*DiscoverySnapshot, error)
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the CloudProvider interface for OpenStack.
func NewProvider ¶
func NewProvider(authOpts gophercloud.AuthOptions, region string) *Provider
NewProvider creates a new OpenStack cloud provider.
func (*Provider) DetectDrift ¶
func (p *Provider) DetectDrift(ctx context.Context, desired, actual *cloud.InfrastructureState) (*cloud.DriftReport, error)
DetectDrift compares desired state with actual state and returns a drift report.
func (*Provider) GetCurrentState ¶
func (p *Provider) GetCurrentState(ctx context.Context, cfg v2.Config) (*cloud.InfrastructureState, error)
GetCurrentState retrieves the current infrastructure state from OpenStack.
func (*Provider) ReconcileDrift ¶
ReconcileDrift applies safe mutable changes only.
type StorageAdapter ¶
type StorageAdapter interface {
Preflight(context.Context, string, string, bool) (StoragePreflight, error)
EnsureContainer(context.Context, ContainerRequest) error
CreateAppCredential(context.Context, AppCredentialRequest) (AppCredential, error)
DeleteAppCredential(context.Context, string, string) error
CreateEC2Credentials(context.Context, EC2CredentialRequest) (EC2Credentials, error)
DeleteEC2Credentials(context.Context, string, string) error
}
StorageAdapter is the only OpenStack surface used by the one-service storage flow.
type StoragePreflight ¶
type StoragePreflight struct {
Endpoint string `json:"endpoint" yaml:"endpoint"`
S3Endpoint string `json:"s3_endpoint,omitempty" yaml:"s3_endpoint,omitempty"`
AuthURL string `json:"auth_url" yaml:"auth_url"`
Region string `json:"region" yaml:"region"`
ProjectID string `json:"project_id" yaml:"project_id"`
CredentialOwnerID string `json:"-" yaml:"-"`
}