onprem

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 38 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"

	ResourceNameDataDisks = "onprem-datadisks"
	ResourceNameVSIs      = "onprem-hpcrs"
)
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"
)

Variables

View Source
var DataDiskCustomResourcesToAttachedDataDisks = A.Map(dataDiskCustomResourceToAttachedDataDisk)

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

View Source
var (
	// full identifier of the disk config entry
	KeyDiskConfig = fmt.Sprintf("%s.%s", KindDataDisk, APIVersion)
)

Functions

func BoxDataDiskSize

func BoxDataDiskSize(size uint64) uint64

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 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 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 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 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
}

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 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
}

type LivirtClient

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

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 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"`
}

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