/
types.go
190 lines (165 loc) · 6.78 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright 2021 Weaveworks or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MPL-2.0
package v1alpha1
import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
// MicrovmSpec represents the specification for a microvm.
type MicrovmSpec 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"`
}
// MicrovmMachineTemplateResource describes the data needed to create a MicrovmMachine from a template.
type MicrovmMachineTemplateResource struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
// Spec is the specification of the machine.
Spec MicrovmMachineSpec `json:"spec"`
}
// ContainerFileSource represents a file coming from a container.
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")
)
// Placement represents configuration relating to the placement of the microvms. The number of placement
// options will grow and so we need to ensure in the validation webhook that only 1 placement types
// is configured.
type Placement struct {
// StaticPool is used to specify that static pool placement should be used.
StaticPool *StaticPoolPlacement `json:"staticPool,omitempty"`
}
// IsSet returns true if one of the placement options has been configured.
// NOTE: this will need to be expanded as the placement options grow.
func (p *Placement) IsSet() bool {
return p.StaticPool != nil
}
// StaticPoolPlacement represents the configuration for placing microvms across
// a pool of predefined servers.
type StaticPoolPlacement struct {
// Hosts defines the pool of hosts that should be used when creating microvms. The hosts will
// be supplied to CAPI (as fault domains) and it will place machines across them.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems:=1
Hosts []MicrovmHost `json:"hosts"`
// BasicAuthSecret is the name of the secret containing basic auth info for each
// host listed in Hosts.
// The secret should be created in the same namespace as the Cluster.
// The secret should contain a data entry for each host Endpoint without the port:
//
// apiVersion: v1
// kind: Secret
// metadata:
// name: mybasicauthsecret
// namespace: same-as-cluster
// type: Opaque
// data:
// 1.2.4.5: YWRtaW4=
// myhost: MWYyZDFlMmU2N2Rm
BasicAuthSecret string `json:"basicAuthSecret,omitempty"`
}
type MicrovmHost 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. flintlock).
// +kubebuilder:validation:Required
Endpoint string `json:"endpoint"`
// ControlPlaneAllowed marks this host as suitable for running control plane nodes in
// addition to worker nodes.
// +kubebuilder:default=true
ControlPlaneAllowed bool `json:"controlplaneAllowed"`
}
// Proxy represents a proxy server.
type Proxy struct {
// Endpoint is the address of the proxy.
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"`
}