onprem

package
v0.1.111 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStoragePool  = "default"
	DefaultDataDiskSize = uint64(100 * 1024 * 1024 * 1024)

	APIVersion      = "hpse.ibm.com/v1"
	KindVSI         = "HyperProtectContainerRuntimeOnPrem"
	KindDataDisk    = "HyperProtectContainerRuntimeOnPremDataDisk"
	KindDataDiskRef = "HyperProtectContainerRuntimeOnPremDataDiskRef"
	KindNetworkRef  = "HyperProtectContainerRuntimeOnPremNetworkRef"

	ResourceNameDataDisks    = "onprem-datadisks"
	ResourceNameDataDiskRefs = "onprem-datadiskrefs"
	ResourceNameNetworkRefs  = "onprem-networkrefs"
	ResourceNameVSIs         = "onprem-hpcrs"

	NeedResults = int32(1)
)
View Source
const (
	// KeyOnPremConfig is the key into the environment to read the name of the ssh config
	KeyOnPremConfig = "ONPREM_CONFIG"
	// KeyStoragePool is the key into the environment to read the name of the target storage pool
	KeyStoragePool = "STORAGE_POOL"
)
View Source
const (

	// Environment variable names
	KeyHostname   = "HOSTNAME"
	KeyPrivateKey = "KEY"
	KeyPort       = "PORT"
	KeyKnownHosts = "KNOWN_HOSTS"
	KeyUser       = "USER"
)
View Source
const (
	// default name for the network to attach to
	DefaultNetwork = "default"
)

Variables

View Source
var (
	// full identifier of the disk config entry
	KeyDiskConfig = fmt.Sprintf("%s.%s", KindDataDisk, APIVersion)
	// full identifier of the disk ref config entry
	KeyDiskRefConfig = fmt.Sprintf("%s.%s", KindDataDiskRef, APIVersion)
)
View Source
var DataDiskCustomResourcesToAttachedDataDisks = A.Map(dataDiskCustomResourceToAttachedDataDisk)

DataDiskCustomResourcesToAttachedDataDisks converts from an array of DataDiskCustomResource to an array of attached disks

View Source
var DataDiskRefCustomResourcesToAttachedDataDisks = A.Map(dataDiskRefCustomResourceToAttachedDataDisk)

DataDiskRefCustomResourcesToAttachedDataDisks converts from an array of DataDiskCustomResource to an array of attached disks

View Source
var (
	// full identifier of the disk ref config entry
	KeyNetworkRefConfig = fmt.Sprintf("%s.%s", KindNetworkRef, APIVersion)
)
View Source
var NetworkRefCustomResourceToNetworks = A.Map(networkRefCustomResourceToNetworks)

NetworkRefCustomResourceToNetworks converts from an array of NetworkRefCustomResource to an array of attached disks

Functions

func BoxDataDiskSize

func BoxDataDiskSize(size uint64) uint64

func BoxNetworkName added in v0.0.22

func BoxNetworkName(name string) string

func BoxStoragePool

func BoxStoragePool(pool string) string

func CloneBootDisk

func CloneBootDisk(client *LivirtClient) func(storagePool string, existingVolumeXML *libvirtxml.StorageVolume, newName string) (*libvirtxml.StorageVolume, error)

CloneBootDisk will clone an existing (boot) disk, so the clone may safely be modified

func CreateBootDiskXML

func CreateBootDiskXML(client *LivirtClient) func(key string) (*libvirtxml.DomainDisk, error)

CreateBootDiskXML creates the XML for the boot disk

func CreateCloudInit

func CreateCloudInit(userData, metaData []byte) ([]byte, error)

CreateCloudInit produces a cloud init ISO file as a data blob with a userdata and a metadata section

func CreateCloudInitDisk

func CreateCloudInitDisk(client *LivirtClient) func(key string) (*libvirtxml.DomainDisk, error)

CreateCloudInitDisk creates the XML for the cloud init disk

func CreateCustomResource

func CreateCustomResource(opt *OnPremCustomResourceOptions) E.Either[error, *OnPremCustomResource]

CreateCustomResource creates a custom resource from a contract

func CreateCustomResourceFromEnv

func CreateCustomResourceFromEnv(envMap env.Environment) func(opt *OnPremCustomResourceEnvOptions) E.Either[error, *OnPremCustomResource]

CreateCustomResourceFromEnv creates a custom resource from some environment

func CreateDataDisk

func CreateDataDisk(client *LivirtClient) func(storagePool, name string, size uint64) (*libvirt.StorageVol, error)

CreateDataDisk creates a data disk or resizes an existing one if required

func CreateDataDiskSync

func CreateDataDiskSync(client *LivirtClient) func(opt *DataDiskOptions) (*libvirt.StorageVol, error)

CreateDataDiskSync creates a data disk or resizes an existing one if required

func CreateDataDiskXML

func CreateDataDiskXML(client *LivirtClient) func(storagePool, name string, index int) (*libvirtxml.DomainDisk, error)

CreateDataDiskXML creates the XML for the data disk

func CreateInstanceHash

func CreateInstanceHash(opt *InstanceOptions) string

createInstanceHash computes a hash value for the instance options

func CreateInstanceSync

func CreateInstanceSync(client *LivirtClient) func(opt *InstanceOptions) (*libvirtxml.Domain, error)

CreateInstanceSync (synchronously) creates an instance

func CreateLoggingVolume

func CreateLoggingVolume(client *LivirtClient) func(storagePool, name string) (*libvirtxml.StorageVolume, error)

CreateLoggingVolume creates a logging volume for the console log

func CreateMacAddressFromHash added in v0.1.29

func CreateMacAddressFromHash(data string) string

constructs a hash value for the string and produces a mac address from that

func CreateMacAddressFromMaybeUUID added in v0.1.29

func CreateMacAddressFromMaybeUUID(maybeuuid string) string

CreateMacAddressFromMaybeUUID tries to parse the UUID from a string, then generate a MAC address from it if the string could not be decoded, create a MAC from a hash instead

func CreateMacAddressFromUUID added in v0.1.29

func CreateMacAddressFromUUID(uid uuid.UUID) string

CreateMacAddressFromUUID creates a mac address from the first 6 bytes of the UUID

func CreateMachineIdFromHash added in v0.1.29

func CreateMachineIdFromHash(data string) string

CreateMachineIdFromHash creates a hash of the input and then a machine ID

func CreateMachineIdFromMaybeUUID added in v0.1.29

func CreateMachineIdFromMaybeUUID(maybeuuid string) string

CreateMachineIdFromMaybeUUID tries to parse the UUID from a string, then generate a machine ID from it if the string could not be decoded, create a machine ID from a hash instead

func CreateMachineIdFromUUID added in v0.1.29

func CreateMachineIdFromUUID(uid uuid.UUID) string

CreateMachineIdFromUUID creates a machineID from a UUID

func CreateNetworksXML added in v0.1.0

func CreateNetworksXML(prefix string) func(networkNames []string) ([]libvirtxml.DomainInterface, error)

CreateNetworksXML creates the XML for the networks

func CreateSSHDialer

func CreateSSHDialer(config *SSHConfig) socket.Dialer

CreateSSHDialer produces a dialer that can connect to the given SSH config

func DeleteDataDiskSync

func DeleteDataDiskSync(client *LivirtClient) func(storagePool, name string) error

DeleteDataDiskSync (synchronously) deletes a data disk

func DeleteDomainByName

func DeleteDomainByName(client *LivirtClient) func(name string) error

func DeleteInstanceSync

func DeleteInstanceSync(client *LivirtClient) func(storagePool, name string) error

DeleteInstanceSync (synchronously) deletes an instance

func GetBootVolumeName

func GetBootVolumeName(name string) string

func GetCIDataVolumeName

func GetCIDataVolumeName(name string) string

func GetDCHPLeases added in v0.0.20

func GetDCHPLeases(client *LivirtClient) func(networkName string) ([]libvirt.NetworkDhcpLease, error)

GetDCHPLeases returns the DCHP leases for a given network

func GetDataDiskRef added in v0.0.22

func GetDataDiskRef(client *LivirtClient) func(opt *DataDiskRefOptions) (*libvirtxml.StorageVolume, error)

GetDataDiskRef tests if a data disk has a valid configuration

func GetDomains added in v0.1.22

func GetDomains(client *LivirtClient) func() ([]libvirt.Domain, error)

func GetEnvMapFromSSHConfig

func GetEnvMapFromSSHConfig(config *SSHConfig) env.Environment

GetEnvMapFromSSHConfig serializes an SSH config into a string map

func GetLoggingVolume

func GetLoggingVolume(client *LivirtClient) func(storagePool, name string) (string, error)

GetLoggingVolume retrieves the value of the logging volume the HPCR console log is very small by design, so passing it as a string does make sense

func GetLoggingVolumeName

func GetLoggingVolumeName(name string) string

func GetLoggingVolumeViaCommand added in v0.1.28

func GetLoggingVolumeViaCommand(client *LivirtClient) func(storagePool, name string) (string, error)

GetLoggingVolumeViaSSH retrieves the value of the logging volume by spawning a separate command. The advantage of this approach is that that command can be canceled if it times out the HPCR console log is very small by design, so passing it as a string does make sense

func GetLoggingVolumeViaSSH added in v0.1.28

func GetLoggingVolumeViaSSH(config *SSHConfig) func(path string) (string, error)

GetLoggingVolumeViaSSH retrieves the value of the logging volume via a new and direct SSH connection the HPCR console log is very small by design, so passing it as a string does make sense

func GetNetworkRef added in v0.0.22

func GetNetworkRef(client *LivirtClient) func(opt *NetworkRefOptions) (*libvirtxml.Network, error)

GetNetworkRef tries to return a network ref

func GetNetworks added in v0.1.0

func GetNetworks(opt *InstanceOptions) []string

GetNetwork returns the network attached to the instane

func GetSSHConfigPath

func GetSSHConfigPath() (string, error)

GetSSHConfigPath returns the path to the SSH config file

func GetStorageVolXMLDesc added in v0.0.18

func GetStorageVolXMLDesc(client *LivirtClient) func(vol *libvirt.StorageVol) (*libvirtxml.StorageVolume, error)

func IsDataDiskValid

func IsDataDiskValid(client *LivirtClient) func(opt *DataDiskOptions) (*libvirtxml.StorageVolume, bool)

IsDataDiskValid tests if a data disk has a valid configuration

func IsInstanceValid

func IsInstanceValid(client *LivirtClient) func(opt *InstanceOptions) (*libvirtxml.Domain, bool)

IsInstanceValid tests if an instance has a valid configuration

func IsNetworkDhcpLeaseForHostname added in v0.0.20

func IsNetworkDhcpLeaseForHostname(hostname string) func(libvirt.NetworkDhcpLease) bool

IsNetworkDhcpLeaseForHostname checks if this lease is for the hostname

func LoadSSHConfig

func LoadSSHConfig(configFile string) func(configName string) (*SSHConfig, error)

LoadSSHConfig loads the SSH config file

func PartitionLogs

func PartitionLogs(logs []string) ([]string, []string)

PartitionLogs partitions the original logs into success and error logs

func RemoveCloudInit

func RemoveCloudInit(client *LivirtClient) func(key string) error

RemoveCloudInit removes the cloud init data from the storage pool

func RemoveDataDisk

func RemoveDataDisk(client *LivirtClient) func(key string) error

RemoveDataDisk removes the data disk

func StartDomain

func StartDomain(client *LivirtClient) func(*libvirtxml.Domain) (*libvirtxml.Domain, error)

func UploadBootDisk

func UploadBootDisk(client *LivirtClient) func(storagePool, name, url string) (*libvirtxml.StorageVolume, error)

UploadBootDisk uploads the iso file to the remote storage pool

func UploadCloudInit

func UploadCloudInit(client *LivirtClient) func(storagePool, name string, isoData []byte) (*libvirtxml.StorageVolume, error)

UploadCloudInit uploads the iso file to the remote storage pool

func VSIFailedToStart

func VSIFailedToStart(logs []string) bool

VSIFailedToStart tests if the VSI failed to start

func VSIStartedSuccessfully

func VSIStartedSuccessfully(logs []string) bool

VSIStartedSuccessfully tests if the VSI started successfully

func XMLMarshall

func XMLMarshall(b any) (string, error)

XMLMarshall marshals an object to XML

Types

type AttachedDataDisk

type AttachedDataDisk struct {
	// name of the attached data disk
	Name string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
}

func AttachedDataDisksFromRelated added in v0.1.24

func AttachedDataDisksFromRelated(rel map[string]any) ([]*AttachedDataDisk, error)

AttachedDataDisksFromRelated decodes the data disks and data disk references from the set of custom resources and convers them into an array of AttachedDataDisk objects

type CloudInit

type CloudInit struct {
	UserData string `json:"user_data" yaml:"user_data"`
	MetaData string `json:"meta_data" yaml:"meta_data"`
}

type DataDiskCustomResource

type DataDiskCustomResource struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the pod.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Spec DataDiskCustomResourceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// status of this custom resource
	Status DataDiskStatus `json:"status,omitempty"`
}

func DataDisksFromRelated

func DataDisksFromRelated(data map[string]any) ([]*DataDiskCustomResource, error)

DataDisksFromRelated decodes the set of configured data disks from the related data structure

type DataDiskCustomResourceSpec

type DataDiskCustomResourceSpec struct {
	// size of the data disk, defaults to 100GiB
	Size uint64 `json:"size"`
	// name of the storage pool, must exist and must be large enough
	StoragePool string `json:"storagePool"`
	// specification of the associated config maps
	TargetSelector *metav1.LabelSelector `json:"targetSelector"`
}

type DataDiskOptions

type DataDiskOptions struct {
	// name of the data disk
	Name string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
	// size of the disk
	Size uint64
}

type DataDiskRefCustomResource added in v0.0.22

type DataDiskRefCustomResource struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the pod.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Spec DataDiskRefCustomResourceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// status of this custom resource
	Status DataDiskRefStatus `json:"status,omitempty"`
}

func DataDiskRefsFromRelated added in v0.1.24

func DataDiskRefsFromRelated(data map[string]any) ([]*DataDiskRefCustomResource, error)

DataDiskRefsFromRelated decodes the set of configured data disks from the related data structure

type DataDiskRefCustomResourceSpec added in v0.0.22

type DataDiskRefCustomResourceSpec struct {
	// name of the volume, must exist
	VolumeName string `json:"volumeName"`
	// name of the storage pool, must exist and must be large enough
	StoragePool string `json:"storagePool"`
	// specification of the associated config maps
	TargetSelector *metav1.LabelSelector `json:"targetSelector"`
}

type DataDiskRefOptions added in v0.0.22

type DataDiskRefOptions struct {
	// name of the data disk
	Name string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
}

type DataDiskRefStatus added in v0.0.22

type DataDiskRefStatus struct {
	// description of the data disk status
	Description string `json:"description"`
	// the status flag
	Status int `json:"status"`
}

type DataDiskStatus added in v0.0.18

type DataDiskStatus struct {
	// description of the data disk status
	Description string `json:"description"`
	// the status flag
	Status int `json:"status"`
}

type Domain

type Domain struct {
	Name     string `json:"name" yaml:"name"`
	Pool     string `json:"pool" yaml:"pool"`
	UserData string `json:"user_data" yaml:"user_data"`
}

type InstanceMetadata

type InstanceMetadata struct {
	XMLName xml.Name `xml:"https://github.com/ibm-hyper-protect/k8s-operator-hpcr instance"`
	Hash    string   `xml:"hash"`
}

type InstanceOptions

type InstanceOptions struct {
	// name of the instance, will also be the hostname
	Name string
	// the userdata field
	UserData string
	// URL to the HPCR qcow2
	ImageURL string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
	// attached data disks
	DataDisks []*AttachedDataDisk
	// attached networks
	Networks []string
}

type LivirtClient

type LivirtClient struct {
	io.Closer
	LibVirt   *libvirt.Libvirt
	Hash      string
	SSHConfig *SSHConfig
}

func CreateLivirtClient

func CreateLivirtClient(sshConfig *SSHConfig) (*LivirtClient, error)

CreateLivirtClient creates a libvirt connection based on an SSH config

func CreateLivirtClientFromEnvMap

func CreateLivirtClientFromEnvMap(envMap env.Environment) (*LivirtClient, error)

CreateLivirtClientFromEnvMap constructs the libvirt client from an env map

func (*LivirtClient) Close

func (client *LivirtClient) Close() error

type NetworkRefCustomResource added in v0.0.22

type NetworkRefCustomResource struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the pod.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Spec NetworkRefCustomResourceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// status of this custom resource
	Status NetworkRefStatus `json:"status,omitempty"`
}

func NetworkRefsFromRelated added in v0.1.0

func NetworkRefsFromRelated(data map[string]any) ([]*NetworkRefCustomResource, error)

NetworkRefsFromRelated decodes the set of configured networks from the related data structure

type NetworkRefCustomResourceSpec added in v0.0.22

type NetworkRefCustomResourceSpec struct {
	// name of the network, must exist
	NetworkName string `json:"networkName"`
	// specification of the associated config maps
	TargetSelector *metav1.LabelSelector `json:"targetSelector"`
}

type NetworkRefOptions added in v0.0.22

type NetworkRefOptions struct {
	// name of the network
	Name string
}

type NetworkRefStatus added in v0.0.22

type NetworkRefStatus struct {
	// description of the data disk status
	Description string `json:"description"`
	// the status flag
	Status int `json:"status"`
}

type OnPremCustomResource

type OnPremCustomResource struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Specification of the desired behavior of the pod.
	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
	// +optional
	Spec OnPremCustomResourceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}

type OnPremCustomResourceEnvOptions

type OnPremCustomResourceEnvOptions struct {
	// name of the instance, will also be the hostname
	Name string
	// labels
	Labels map[string]string
	// references to the configs (for SSH)
	TargetLabels map[string]string
	// URL to the HPCR qcow2
	ImageURL string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
	// encryption Certificate
	EncryptionCert []byte
	// folder containing the compose file
	ComposeFolder string
}

type OnPremCustomResourceOptions

type OnPremCustomResourceOptions struct {
	// name of the instance, will also be the hostname
	Name string
	// labels
	Labels map[string]string
	// references to the configs (for SSH)
	TargetLabels map[string]string
	// URL to the HPCR qcow2
	ImageURL string
	// name of the libvirt storage pool, the pool must exist
	StoragePool string
	// encryption Certificate
	EncryptionCert []byte
	// clear text contract
	Contract C.RawMap
}

type OnPremCustomResourceSpec

type OnPremCustomResourceSpec struct {
	// the encrypted contract document
	Contract string `json:"contract"`
	// URL to the service that serves the base qcow2 image
	ImageURL string `json:"imageURL"`
	// name of the storage pool, must exist and must be large enough
	StoragePool string `json:"storagePool"`
	// specification of the associated config maps
	TargetSelector *metav1.LabelSelector `json:"targetSelector"`
	// specification of the associated data disks
	DiskSelector *metav1.LabelSelector `json:"diskSelector"`
	// specification of the associated networks
	NetworkSelector *metav1.LabelSelector `json:"networkSelector"`
}

type SSHConfig

type SSHConfig struct {
	Hostname   string   `json:"hostname,omitempty" yaml:"hostname,omitempty"`
	Port       int      `json:"port,omitempty" yaml:"port,omitempty"`
	User       string   `json:"user,omitempty" yaml:"user,omitempty"`
	KnownHosts []string `json:"knownHosts,omitempty" yaml:"knownHosts,omitempty"`
	Key        string   `json:"key,omitempty" yaml:"key,omitempty"`
}

func GetSSHConfigFromConfigMap

func GetSSHConfigFromConfigMap(configMap *v1.ConfigMap) *SSHConfig

GetSSHConfigFromConfigMap deserializes an SSH config from a config map object

func GetSSHConfigFromEnvMap

func GetSSHConfigFromEnvMap(envMap env.Environment) *SSHConfig

GetSSHConfigFromEnvMap deserializes an SSH config from a set of (env) parameters

Jump to

Keyboard shortcuts

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