cloud

package
v0.0.0-...-2170ac4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cloud provides cloud provider abstractions for infrastructure drift detection.

Overview

The cloud package defines interfaces and types for interacting with cloud providers to detect and reconcile infrastructure drift. It supports multiple cloud providers through a factory pattern, allowing opencenter to work with OpenStack, VMware, and other cloud platforms.

This package is not the registry for lifecycle deploy providers. Providers used by cluster deploy or destroy flows may live in sibling packages and be wired directly by those commands or services. Kind is the current example: it manages local cluster lifecycle, but it does not implement the CloudProvider drift interface and is therefore not registered in CloudProviderFactory. Baremetal is also outside the drift-provider registry today.

Architecture

The package is organized around three main concepts:

  1. CloudProvider interface - defines operations for drift detection
  2. CloudProviderFactory - creates provider instances based on configuration
  3. Infrastructure state types - represent cloud resources

CloudProvider Interface

The CloudProvider interface defines three core operations:

  • GetCurrentState: Retrieves actual infrastructure state from the cloud provider
  • DetectDrift: Compares desired vs actual state and reports differences
  • ReconcileDrift: Applies changes to fix detected drift

Usage Example

// Create factory and register providers
factory := cloud.NewCloudProviderFactory()
factory.RegisterProvider("openstack", openstack.NewProvider(authOpts, region))
factory.RegisterProvider("vmware", vmware.NewProvider())

// Get provider for cluster
provider, err := factory.GetProvider(cfg.Infrastructure.Provider)
if err != nil {
    return err
}

// Get current state from cloud
currentState, err := provider.GetCurrentState(ctx, cfg)
if err != nil {
    return err
}

// Build desired state from configuration
desiredState := buildDesiredState(cfg)

// Detect drift
report, err := provider.DetectDrift(ctx, desiredState, currentState)
if err != nil {
    return err
}

// Reconcile if needed
if report.Reconcilable && len(report.Drifts) > 0 {
    err = provider.ReconcileDrift(ctx, report)
}

Drift Detection

Drift detection compares the desired infrastructure state (from configuration) with the actual state (from the cloud provider) and identifies differences.

Each drift item includes:

  • Resource type and identifier
  • Field that has drifted
  • Expected vs actual values
  • Severity level (info, warning, critical)
  • Whether it can be automatically reconciled

Drift Severity Levels

  • SeverityInfo: Informational drift (metadata, timestamps)
  • SeverityWarning: Warning-level drift (worker nodes, tags)
  • SeverityCritical: Critical drift (control plane, network config)

Reconciliation

Drift reconciliation applies changes to bring infrastructure back in line with the desired configuration. Only reconcilable drift items are processed.

Non-reconcilable drift (e.g., deleted resources, manual changes) requires manual intervention.

Provider Implementations

Provider implementations are in subpackages:

  • openstack: OpenStack cloud provider
  • vmware: VMware vSphere cloud provider

Each provider implements the CloudProvider interface and handles provider-specific API calls and resource types.

Thread Safety

CloudProviderFactory is safe for concurrent use. Provider implementations should be safe for concurrent read operations but may require synchronization for write operations (reconciliation).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateSummary

func CalculateSummary(report *DriftReport)

CalculateSummary updates summary counters and aggregate flags for a drift report.

Types

type CloudProvider

type CloudProvider interface {
	// GetCurrentState retrieves the current infrastructure state from the cloud provider.
	// It queries the provider's APIs to get the actual state of all resources.
	GetCurrentState(ctx context.Context, cfg v2.Config) (*InfrastructureState, error)

	// DetectDrift compares desired state (from config) with actual state (from provider)
	// and returns a report of all differences found.
	DetectDrift(ctx context.Context, desired, actual *InfrastructureState) (*DriftReport, error)

	// ReconcileDrift applies changes to the infrastructure to bring it back in line
	// with the desired state. Only reconcilable drift items are processed.
	ReconcileDrift(ctx context.Context, drift *DriftReport) error
}

CloudProvider defines the interface for cloud provider operations needed for drift detection. Implementations provide access to infrastructure state and drift reconciliation capabilities.

type CloudProviderFactory

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

CloudProviderFactory creates cloud provider instances for drift-detection workflows. It maintains a registry of providers that implement CloudProvider and are queried by commands such as cluster drift.

Lifecycle deploy providers are intentionally outside this factory. For example, the Kind deploy provider shells out to kind/kubectl and is wired directly into cluster deploy/destroy flows rather than the drift-detection registry.

func NewCloudProviderFactory

func NewCloudProviderFactory() *CloudProviderFactory

NewCloudProviderFactory creates a new cloud provider factory with all available providers registered.

func (*CloudProviderFactory) GetProvider

func (f *CloudProviderFactory) GetProvider(name string) (CloudProvider, error)

GetProvider returns a cloud provider instance for the given provider name. Returns an error if the provider is not supported.

func (*CloudProviderFactory) RegisterProvider

func (f *CloudProviderFactory) RegisterProvider(name string, provider CloudProvider)

RegisterProvider registers a cloud provider with the factory. This allows providers to be registered at initialization time.

type DriftItem

type DriftItem struct {
	// ResourceType is the type of resource (server, network, etc.)
	ResourceType string `json:"resource_type"`

	// ResourceID is the unique identifier of the resource
	ResourceID string `json:"resource_id"`

	// ResourceName is the human-readable name of the resource
	ResourceName string `json:"resource_name"`

	// Field is the specific field that has drifted
	Field string `json:"field"`

	// Expected is the desired value from configuration
	Expected interface{} `json:"expected"`

	// Actual is the current value from the provider
	Actual interface{} `json:"actual"`

	// Severity indicates how critical this drift is
	Severity Severity `json:"severity"`

	// Reconcilable indicates if this drift can be automatically fixed
	Reconcilable bool `json:"reconcilable"`

	// Message provides additional context about the drift
	Message string `json:"message"`
}

DriftItem represents a single drift between desired and actual state.

type DriftReport

type DriftReport struct {
	// ClusterName is the name of the cluster being checked
	ClusterName string `json:"cluster_name"`

	// DetectedAt is when the drift was detected
	DetectedAt string `json:"detected_at"`

	// Drifts is the list of all detected drift items
	Drifts []DriftItem `json:"drifts"`

	// Summary provides aggregate statistics
	Summary DriftSummary `json:"summary"`

	// OverallSeverity is the highest severity level found
	OverallSeverity Severity `json:"overall_severity"`

	// Reconcilable indicates if all drift can be automatically fixed
	Reconcilable bool `json:"reconcilable"`
}

DriftReport represents the result of drift detection between desired and actual state.

func CompareInfrastructureState

func CompareInfrastructureState(desired, actual *InfrastructureState) *DriftReport

CompareInfrastructureState compares desired and actual infrastructure state using a shared severity and reconcilability model across providers.

type DriftSummary

type DriftSummary struct {
	// TotalDrifts is the total number of drift items
	TotalDrifts int `json:"total_drifts"`

	// CriticalCount is the number of critical severity drifts
	CriticalCount int `json:"critical_count"`

	// WarningCount is the number of warning severity drifts
	WarningCount int `json:"warning_count"`

	// InfoCount is the number of info severity drifts
	InfoCount int `json:"info_count"`

	// ReconcilableCount is the number of drifts that can be auto-fixed
	ReconcilableCount int `json:"reconcilable_count"`
}

DriftSummary provides aggregate statistics about detected drift.

type FloatingIP

type FloatingIP struct {
	ID         string `json:"id"`
	Address    string `json:"address"`
	Status     string `json:"status"`
	AttachedTo string `json:"attached_to"`
}

FloatingIP represents a public IP address.

type InfrastructureState

type InfrastructureState struct {
	// Servers are the compute instances (VMs) in the cluster
	Servers []Server `json:"servers"`

	// Networks are the network resources (VPCs, subnets)
	Networks []Network `json:"networks"`

	// SecurityGroups are the firewall rules
	SecurityGroups []SecurityGroup `json:"security_groups"`

	// LoadBalancers are the load balancing resources
	LoadBalancers []LoadBalancer `json:"load_balancers"`

	// Volumes are the block storage volumes
	Volumes []Volume `json:"volumes"`

	// FloatingIPs are the public IP addresses
	FloatingIPs []FloatingIP `json:"floating_ips"`
}

InfrastructureState represents the complete state of infrastructure resources. It captures all resources managed by the cloud provider for a cluster.

type LoadBalancer

type LoadBalancer struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	VIP      string   `json:"vip"`
	Members  []string `json:"members"`
	Protocol string   `json:"protocol"`
	Port     int      `json:"port"`
}

LoadBalancer represents a load balancer resource.

type Network

type Network struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	CIDR    string   `json:"cidr"`
	Subnets []Subnet `json:"subnets"`
}

Network represents a network resource.

type SecurityGroup

type SecurityGroup struct {
	ID    string         `json:"id"`
	Name  string         `json:"name"`
	Rules []SecurityRule `json:"rules"`
}

SecurityGroup represents a security group with its rules.

type SecurityRule

type SecurityRule struct {
	ID          string `json:"id"`
	Direction   string `json:"direction"`
	Protocol    string `json:"protocol"`
	PortRange   string `json:"port_range"`
	RemoteIP    string `json:"remote_ip"`
	Description string `json:"description"`
}

SecurityRule represents a single security group rule.

type Server

type Server struct {
	ID       string            `json:"id"`
	Name     string            `json:"name"`
	Flavor   string            `json:"flavor"`
	Image    string            `json:"image"`
	Status   string            `json:"status"`
	Networks []string          `json:"networks"`
	Tags     map[string]string `json:"tags"`
}

Server represents a compute instance in the infrastructure.

type Severity

type Severity int

Severity represents the severity level of a drift item.

const (
	// SeverityInfo represents informational drift (metadata, timestamps)
	SeverityInfo Severity = iota

	// SeverityWarning represents warning-level drift (worker nodes, tags, labels)
	SeverityWarning

	// SeverityCritical represents critical drift (control plane, network configuration)
	SeverityCritical
)

func (Severity) String

func (s Severity) String() string

String returns the string representation of severity.

type Subnet

type Subnet struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	CIDR string `json:"cidr"`
}

Subnet represents a subnet within a network.

type UnsupportedProviderError

type UnsupportedProviderError struct {
	Provider           string
	SupportedProviders []string
}

UnsupportedProviderError is returned when a requested provider is not available.

func (*UnsupportedProviderError) Error

func (e *UnsupportedProviderError) Error() string

Error implements the error interface.

type Volume

type Volume struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Size       int    `json:"size"`
	Status     string `json:"status"`
	AttachedTo string `json:"attached_to"`
}

Volume represents a block storage volume.

Directories

Path Synopsis
Package openstack provides OpenStack-specific functionality.
Package openstack provides OpenStack-specific functionality.
Package vmware provides VMware vSphere-specific infrastructure drift detection.
Package vmware provides VMware vSphere-specific infrastructure drift detection.

Jump to

Keyboard shortcuts

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