Documentation
¶
Overview ¶
Package instanceinfo provides cloud instance metadata provider interface and implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCloudInitInstanceID ¶
GetCloudInitInstanceID gets the instance ID from cloud-init cache for the given provider.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides access to cloud instance metadata.
func NewWithProvider ¶
NewWithProvider creates a client with an explicit provider.
func (*Client) GetInstanceID ¶
GetInstanceID returns the provider-specific instance ID.
func (*Client) GetTerminationNotice ¶
GetTerminationNotice checks for spot termination notices.
type CloudInitDS ¶
type CloudInitDS struct {
MetaData CloudInitProviderMeta `json:"meta_data"`
}
CloudInitDS contains provider-specific data source metadata.
type CloudInitData ¶
type CloudInitData struct {
V1 CloudInitV1 `json:"v1"`
DS CloudInitDS `json:"ds"`
Metadata map[string]any `json:"meta_data"`
}
CloudInitData represents the cloud-init instance data structure.
func ReadCloudInit ¶
func ReadCloudInit() (*CloudInitData, error)
ReadCloudInit reads and parses the cloud-init instance data file. Returns nil if the file doesn't exist (not running with cloud-init).
type CloudInitProviderMeta ¶
type CloudInitProviderMeta struct {
// AWS fields
InstanceID string `json:"instance-id"`
// Azure fields
Compute *struct {
Name string `json:"name"`
VMId string `json:"vmId"`
ResourceGroupName string `json:"resourceGroupName"`
SubscriptionId string `json:"subscriptionId"`
} `json:"compute"`
// GCP fields
Name string `json:"name"`
Zone string `json:"zone"`
ProjectID string `json:"project-id"`
}
CloudInitProviderMeta contains provider-specific metadata fields.
type CloudInitV1 ¶
type CloudInitV1 struct {
InstanceID string `json:"instance_id"`
Region string `json:"region"`
Zone string `json:"availability_zone"`
}
CloudInitV1 contains standardized instance data.
type Provider ¶
type Provider interface {
// Kind returns the provider kind (aws, azure, gcp).
Kind() string
// GetInstanceID returns the provider-specific instance ID.
// For AWS: instance-id (e.g., i-abc123)
// For Azure: VM name
// For GCP: instance name
GetInstanceID(ctx context.Context) (string, error)
// IsSpot returns true if running on a spot/preemptible instance.
IsSpot(ctx context.Context) (bool, error)
// GetTerminationNotice checks for spot termination notices.
// Returns nil if no termination notice is present.
GetTerminationNotice(ctx context.Context) (*health.TerminationNotice, error)
}
Provider defines the interface for querying cloud instance metadata.
func NewMockProvider ¶
NewMockProvider creates a Provider that returns the given serverID as the instance identity.
type SpotMonitor ¶
type SpotMonitor struct {
// contains filtered or unexported fields
}
SpotMonitor monitors for spot instance termination notices.
func NewSpotMonitor ¶
func NewSpotMonitor(cfg SpotMonitorConfig) (*SpotMonitor, error)
NewSpotMonitor creates a new termination notice monitor. It auto-detects the provider and spot status.
func (*SpotMonitor) GetTerminationNotice ¶
func (m *SpotMonitor) GetTerminationNotice() *health.TerminationNotice
GetTerminationNotice returns the most recent termination notice.
func (*SpotMonitor) Start ¶
func (m *SpotMonitor) Start(ctx context.Context)
Start begins monitoring for termination notices.