Skip to content

Commit 37ae130

Browse files
authored
ref: Replace components with extracted common pkg (#248)
`github.com/weaveworks-liquidmetal/controller-pkg` contains things used by both CAPMVM and the new microvm-operator. Aside from this switch there are no code changes at all.
1 parent 8d1221d commit 37ae130

27 files changed

+388
-1135
lines changed

api/v1alpha1/defaults.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package v1alpha1
22

33
import (
4+
"github.com/weaveworks-liquidmetal/controller-pkg/types/microvm"
45
"github.com/yitsushi/macpot"
56
)
67

7-
func SetDefaults_NetworkInterface(obj *NetworkInterface) { //nolint: revive,stylecheck // idk it was here
8+
func SetDefaults_NetworkInterface(obj *microvm.NetworkInterface) { //nolint: revive,stylecheck // idk it was here
89
if obj.GuestMAC == "" {
910
mac, _ := macpot.New(macpot.AsLocal(), macpot.AsUnicast())
1011

api/v1alpha1/microvmcluster_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package v1alpha1
55

66
import (
7+
flclient "github.com/weaveworks-liquidmetal/controller-pkg/client"
8+
"github.com/weaveworks-liquidmetal/controller-pkg/types/microvm"
79
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
911
)
@@ -21,13 +23,13 @@ type MicrovmClusterSpec struct {
2123
// If specified these keys will be applied to all machine created unless you
2224
// specify different keys at the machine level.
2325
// +optional
24-
SSHPublicKeys []SSHPublicKey `json:"sshPublicKeys,omitempty"`
26+
SSHPublicKeys []microvm.SSHPublicKey `json:"sshPublicKeys,omitempty"`
2527
// Placement specifies how machines for the cluster should be placed onto hosts (i.e. where the microvms are created).
2628
// +kubebuilder:validation:Required
2729
Placement Placement `json:"placement"`
2830
// MicrovmProxy is the proxy server details to use when calling the microvm service. This is an
2931
// alteranative to using the http proxy environment variables and applied purely to the grpc service.
30-
MicrovmProxy *Proxy `json:"microvmProxy,omitempty"`
32+
MicrovmProxy *flclient.Proxy `json:"microvmProxy,omitempty"`
3133

3234
// mTLS Configuration:
3335
//

api/v1alpha1/microvmmachine_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package v1alpha1
55

66
import (
7+
microvm "github.com/weaveworks-liquidmetal/controller-pkg/types/microvm"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
910
"sigs.k8s.io/cluster-api/errors"
@@ -17,14 +18,14 @@ const (
1718

1819
// MicrovmMachineSpec defines the desired state of MicrovmMachine.
1920
type MicrovmMachineSpec struct {
20-
MicrovmSpec `json:",inline"`
21+
microvm.VMSpec `json:",inline"`
2122

2223
// SSHPublicKeys is list of SSH public keys that will be used with stated users
2324
// on this machine.
2425
// If specified they will take precedence over any SSH keys specified at
2526
// the cluster level.
2627
// +optional
27-
SSHPublicKeys []SSHPublicKey `json:"sshPublicKeys,omitempty"`
28+
SSHPublicKeys []microvm.SSHPublicKey `json:"sshPublicKeys,omitempty"`
2829

2930
// ProviderID is the unique identifier as specified by the cloud provider.
3031
ProviderID *string `json:"providerID,omitempty"`
@@ -38,7 +39,7 @@ type MicrovmMachineStatus struct {
3839
Ready bool `json:"ready"`
3940

4041
// VMState indicates the state of the microvm.
41-
VMState *VMState `json:"vmState,omitempty"`
42+
VMState *microvm.VMState `json:"vmState,omitempty"`
4243

4344
// Addresses contains the microvm associated addresses.
4445
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`

api/v1alpha1/types.go

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,6 @@ import (
77
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
88
)
99

10-
// MicrovmSpec represents the specification for a microvm.
11-
type MicrovmSpec struct {
12-
// VCPU specifies how many vcpu's the microvm will be allocated.
13-
// +kubebuilder:validation:Required
14-
// +kubebuilder:validation:Minimum:=1
15-
VCPU int64 `json:"vcpu"`
16-
17-
// MemoryMb is the amount of memory in megabytes that the microvm will be allocated.
18-
// +kubebuilder:validation:Required
19-
// +kubebuilder:validation:Minimum:=1024
20-
MemoryMb int64 `json:"memoryMb"`
21-
22-
// RootVolume specifies the volume to use for the root of the microvm.
23-
// +kubebuilder:validation:Required
24-
RootVolume Volume `json:"rootVolume"`
25-
26-
// AdditionalVolumes specifies additional non-root volumes to attach to the microvm.
27-
// +optional
28-
AdditionalVolumes []Volume `json:"volumes,omitempty"`
29-
30-
// Kernel specifies the kernel and its arguments to use.
31-
// +kubebuilder:validation:Required
32-
Kernel ContainerFileSource `json:"kernel"`
33-
34-
// KernelCmdLine are the additional args to use for the kernel cmdline.
35-
// Each MicroVM provider has its own recommended list, they will be used
36-
// automatically. This field is for additional values.
37-
KernelCmdLine map[string]string `json:"kernelCmdline,omitempty"`
38-
39-
// Initrd is an optional initial ramdisk to use.
40-
// +optional
41-
Initrd *ContainerFileSource `json:"initrd,omitempty"`
42-
43-
// NetworkInterfaces specifies the network interfaces attached to the microvm.
44-
// +kubebuilder:validation:Required
45-
// +kubebuilder:validation:MinItems:=1
46-
NetworkInterfaces []NetworkInterface `json:"networkInterfaces"`
47-
}
48-
4910
// MicrovmMachineTemplateResource describes the data needed to create a MicrovmMachine from a template.
5011
type MicrovmMachineTemplateResource struct {
5112
// Standard object's metadata.
@@ -57,73 +18,6 @@ type MicrovmMachineTemplateResource struct {
5718
Spec MicrovmMachineSpec `json:"spec"`
5819
}
5920

60-
// ContainerFileSource represents a file coming from a container.
61-
type ContainerFileSource struct {
62-
// Image is the container image to use.
63-
// +kubebuilder:validation:Required
64-
Image string `json:"image"`
65-
// Filename is the name of the file in the container to use.
66-
// +optional
67-
Filename string `json:"filename,omitempty"`
68-
}
69-
70-
// Volume represents a volume to be attached to a microvm.
71-
type Volume struct {
72-
// ID is a unique identifier for this volume.
73-
// +kubebuilder:validation:Required
74-
ID string `json:"id"`
75-
// Image is the container image to use for the volume.
76-
// +kubebuilder:validation:Required
77-
Image string `json:"image"`
78-
// ReadOnly specifies that the volume is to be mounted readonly.
79-
// +kubebuilder:default:=false
80-
// +optional
81-
ReadOnly bool `json:"readOnly,omitempty"`
82-
}
83-
84-
// IfaceType is a type representing the network interface types.
85-
type IfaceType string
86-
87-
const (
88-
// IfaceTypeTap is a TAP network interface.
89-
IfaceTypeTap = "tap"
90-
// IfaceTypeMacvtap is a MACVTAP network interface.
91-
IfaceTypeMacvtap = "macvtap"
92-
)
93-
94-
// NetworkInterface represents a network interface for the microvm.
95-
type NetworkInterface struct {
96-
// GuestDeviceName is the name of the network interface to create in the microvm.
97-
// +kubebuilder:validation:Required
98-
GuestDeviceName string `json:"guestDeviceName"`
99-
// GuestMAC allows the specifying of a specific MAC address to use for the interface. If
100-
// not supplied a autogenerated MAC address will be used.
101-
// +optional
102-
GuestMAC string `json:"guestMac,omitempty"`
103-
// Type is the type of host network interface type to create to use by the guest.
104-
// +kubebuilder:validation:Enum=macvtap;tap
105-
Type IfaceType `json:"type"`
106-
// Address is an optional IP address to assign to this interface. If not supplied then DHCP will be used.
107-
// +optional
108-
Address string `json:"address,omitempty"`
109-
}
110-
111-
// VMState is a type that represents the state of a microvm.
112-
type VMState string
113-
114-
var (
115-
// VMStatePending indicates the microvm hasn't been started.
116-
VMStatePending = VMState("pending")
117-
// VMStateRunning indicates the microvm is running.
118-
VMStateRunning = VMState("running")
119-
// VMStateFailed indicates the microvm has failed.
120-
VMStateFailed = VMState("failed")
121-
// VMStateDeleted indicates the microvm has been deleted.
122-
VMStateDeleted = VMState("deleted")
123-
// VMStateUnknown indicates the microvm is in an state that is unknown/supported by CAPMVM.
124-
VMStateUnknown = VMState("unknown")
125-
)
126-
12721
// Placement represents configuration relating to the placement of the microvms. The number of placement
12822
// options will grow and so we need to ensure in the validation webhook that only 1 placement types
12923
// is configured.
@@ -167,7 +61,8 @@ type MicrovmHost struct {
16761
// Name is an optional name for the host.
16862
// +optional
16963
Name string `json:"name,omitempty"`
170-
// Endpoint is the API endpoint for the microvm service (i.e. flintlock).
64+
// Endpoint is the API endpoint for the microvm service (i.e. flintlock)
65+
// including the port.
17166
// +kubebuilder:validation:Required
17267
Endpoint string `json:"endpoint"`
17368
// ControlPlaneAllowed marks this host as suitable for running control plane nodes in
@@ -176,12 +71,6 @@ type MicrovmHost struct {
17671
ControlPlaneAllowed bool `json:"controlplaneAllowed"`
17772
}
17873

179-
// Proxy represents a proxy server.
180-
type Proxy struct {
181-
// Endpoint is the address of the proxy.
182-
Endpoint string `json:"endpoint"`
183-
}
184-
18574
// TLSConfig represents config for connecting to TLS enabled hosts.
18675
type TLSConfig struct {
18776
Cert []byte `json:"cert"`

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)