forked from liquidmetal-dev/microvm-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All this bit will be refactored into a lib which both this operator and capmvm can use.
- Loading branch information
1 parent
251edca
commit a0553d5
Showing
2 changed files
with
241 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
Copyright 2022 Weaveworks. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
// TODO refactor out into shared lib | ||
type VMSpec struct { | ||
// VCPU specifies how many vcpu's the microvm will be allocated. | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:Minimum:=1 | ||
VCPU int64 `json:"vcpu"` | ||
|
||
// MemoryMb is the amount of memory in megabytes that the microvm will be allocated. | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:Minimum:=1024 | ||
MemoryMb int64 `json:"memoryMb"` | ||
|
||
// RootVolume specifies the volume to use for the root of the microvm. | ||
// +kubebuilder:validation:Required | ||
RootVolume Volume `json:"rootVolume"` | ||
|
||
// AdditionalVolumes specifies additional non-root volumes to attach to the microvm. | ||
// +optional | ||
AdditionalVolumes []Volume `json:"volumes,omitempty"` | ||
|
||
// Kernel specifies the kernel and its arguments to use. | ||
// +kubebuilder:validation:Required | ||
Kernel ContainerFileSource `json:"kernel"` | ||
|
||
// KernelCmdLine are the additional args to use for the kernel cmdline. | ||
// Each MicroVM provider has its own recommended list, they will be used | ||
// automatically. This field is for additional values. | ||
KernelCmdLine map[string]string `json:"kernelCmdline,omitempty"` | ||
|
||
// Initrd is an optional initial ramdisk to use. | ||
// +optional | ||
Initrd *ContainerFileSource `json:"initrd,omitempty"` | ||
|
||
// NetworkInterfaces specifies the network interfaces attached to the microvm. | ||
// +kubebuilder:validation:Required | ||
// +kubebuilder:validation:MinItems:=1 | ||
NetworkInterfaces []NetworkInterface `json:"networkInterfaces"` | ||
} | ||
|
||
// ContainerFileSource represents a file coming from a container image. | ||
type ContainerFileSource struct { | ||
// Image is the container image to use. | ||
// +kubebuilder:validation:Required | ||
Image string `json:"image"` | ||
// Filename is the name of the file in the container to use. | ||
// +optional | ||
Filename string `json:"filename,omitempty"` | ||
} | ||
|
||
// Volume represents a volume to be attached to a microvm. | ||
type Volume struct { | ||
// ID is a unique identifier for this volume. | ||
// +kubebuilder:validation:Required | ||
ID string `json:"id"` | ||
// Image is the container image to use for the volume. | ||
// +kubebuilder:validation:Required | ||
Image string `json:"image"` | ||
// ReadOnly specifies that the volume is to be mounted readonly. | ||
// +kubebuilder:default:=false | ||
// +optional | ||
ReadOnly bool `json:"readOnly,omitempty"` | ||
} | ||
|
||
// IfaceType is a type representing the network interface types. | ||
type IfaceType string | ||
|
||
const ( | ||
// IfaceTypeTap is a TAP network interface. | ||
IfaceTypeTap = "tap" | ||
// IfaceTypeMacvtap is a MACVTAP network interface. | ||
IfaceTypeMacvtap = "macvtap" | ||
) | ||
|
||
// NetworkInterface represents a network interface for the microvm. | ||
type NetworkInterface struct { | ||
// GuestDeviceName is the name of the network interface to create in the microvm. | ||
// +kubebuilder:validation:Required | ||
GuestDeviceName string `json:"guestDeviceName"` | ||
// GuestMAC allows the specifying of a specific MAC address to use for the interface. If | ||
// not supplied a autogenerated MAC address will be used. | ||
// +optional | ||
GuestMAC string `json:"guestMac,omitempty"` | ||
// Type is the type of host network interface type to create to use by the guest. | ||
// +kubebuilder:validation:Enum=macvtap;tap | ||
Type IfaceType `json:"type"` | ||
// Address is an optional IP address to assign to this interface. If not supplied then DHCP will be used. | ||
// +optional | ||
Address string `json:"address,omitempty"` | ||
} | ||
|
||
// VMState is a type that represents the state of a microvm. | ||
type VMState string | ||
|
||
var ( | ||
// VMStatePending indicates the microvm hasn't been started. | ||
VMStatePending = VMState("pending") | ||
// VMStateRunning indicates the microvm is running. | ||
VMStateRunning = VMState("running") | ||
// VMStateFailed indicates the microvm has failed. | ||
VMStateFailed = VMState("failed") | ||
// VMStateDeleted indicates the microvm has been deleted. | ||
VMStateDeleted = VMState("deleted") | ||
// VMStateUnknown indicates the microvm is in an state that is unknown/supported by CAPMVM. | ||
VMStateUnknown = VMState("unknown") | ||
) | ||
|
||
type Host struct { | ||
// Name is an optional name for the host. | ||
// +optional | ||
Name string `json:"name,omitempty"` | ||
// Endpoint is the API endpoint for the microvm service (i.e. flintloc) | ||
// including the port. | ||
// +kubebuilder:validation:Required | ||
Endpoint string `json:"endpoint"` | ||
} | ||
|
||
// TLSConfig represents config for connecting to TLS enabled hosts. | ||
type TLSConfig struct { | ||
Cert []byte `json:"cert"` | ||
Key []byte `json:"key"` | ||
CACert []byte `json:"caCert"` | ||
} | ||
|
||
type SSHPublicKey struct { | ||
// User is the name of the user to add keys for (eg root, ubuntu). | ||
// +kubebuilder:validation:Required | ||
User string `json:"user,omitempty"` | ||
// AuthorizedKeys is a list of public keys to add to the user | ||
// +kubebuilder:validation:Required | ||
AuthorizedKeys []string `json:"authorizedKeys,omitempty"` | ||
} |