Skip to content

Commit

Permalink
Cleanup / New version readiness (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus authored May 10, 2022
1 parent 61270e2 commit 66373e7
Show file tree
Hide file tree
Showing 90 changed files with 821 additions and 2,814 deletions.
3 changes: 3 additions & 0 deletions apis/compute/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/onmetal/onmetal-api/apis/networking"
)

// EphemeralNetworkInterfaceSource is a definition for an ephemeral (i.e. coupled to the lifetime of the surrounding
// object) networking.NetworkInterface.
type EphemeralNetworkInterfaceSource struct {
// NetworkInterfaceTemplate is the template definition of the networking.NetworkInterface.
NetworkInterfaceTemplate *networking.NetworkInterfaceTemplateSpec
}
67 changes: 36 additions & 31 deletions apis/compute/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type MachineSpec struct {
MachinePoolSelector map[string]string
// MachinePoolRef defines machine pool to run the machine in.
// If empty, a scheduler will figure out an appropriate pool to run the machine in.
MachinePoolRef corev1.LocalObjectReference
MachinePoolRef *corev1.LocalObjectReference
// Image is the URL providing the operating system image of the machine.
Image string
// Interfaces define a list of network interfaces present on the machine
Interfaces []Interface
// NetworkInterfaces define a list of network interfaces present on the machine
NetworkInterfaces []NetworkInterface
// Volumes are volumes attached to this machine.
Volumes []Volume
// IgnitionRef is a reference to a config map containing the ignition YAML for the machine to boot up.
Expand All @@ -50,23 +50,26 @@ type MachineSpec struct {

// EFIVar is a variable to pass to EFI while booting up.
type EFIVar struct {
Name string
UUID string
// Name is the name of the EFIVar.
Name string
// UUID is the uuid of the EFIVar.
UUID string
// Value is the value of the EFIVar.
Value string
}

// DefaultIgnitionKey is the default key for MachineSpec.UserData.
const DefaultIgnitionKey = "ignition.yaml"

// Interface is the definition of a single interface
type Interface struct {
// NetworkInterface is the definition of a single interface
type NetworkInterface struct {
// Name is the name of the network interface.
Name string
// InterfaceSource is where to obtain the interface from.
InterfaceSource
// NetworkInterfaceSource is where to obtain the interface from.
NetworkInterfaceSource
}

type InterfaceSource struct {
type NetworkInterfaceSource struct {
// NetworkInterfaceRef instructs to use the NetworkInterface at the target reference.
NetworkInterfaceRef *corev1.LocalObjectReference
// Ephemeral instructs to create an ephemeral (i.e. coupled to the lifetime of the surrounding object)
Expand All @@ -88,17 +91,13 @@ type VolumeSource struct {
VolumeClaimRef *corev1.LocalObjectReference
}

type RetainPolicy string

const (
RetainPolicyDeleteOnTermination RetainPolicy = "DeleteOnTermination"
RetainPolicyPersistent RetainPolicy = "Persistent"
)

// InterfaceStatus reports the status of an InterfaceSource.
type InterfaceStatus struct {
Name string
IPs []commonv1alpha1.IP
// NetworkInterfaceStatus reports the status of an NetworkInterfaceSource.
type NetworkInterfaceStatus struct {
// Name is the name of the NetworkInterface to whom the status belongs to.
Name string
// IPs are the ips allocated for the network interface.
IPs []commonv1alpha1.IP
// VirtualIP is the virtual ip allocated for the network interface.
VirtualIP *commonv1alpha1.IP
}

Expand All @@ -112,23 +111,31 @@ type VolumeStatus struct {

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
State MachineState
Conditions []MachineCondition
Interfaces []InterfaceStatus
VolumeAttachments []VolumeStatus
// State is the state of the machine.
State MachineState
// Conditions are the conditions of the machines.
Conditions []MachineCondition
// NetworkInterfaces is the list of network interface states for the machine.
NetworkInterfaces []NetworkInterfaceStatus
// Volumes is the list of volume states for the machine.
Volumes []VolumeStatus
}

// MachineState is the state of a machine.
//+enum
type MachineState string

const (
// MachineStatePending means the Machine has been accepted by the system, but not yet completely started.
// This includes time before being bound to a MachinePool, as well as time spent setting up the Machine on that
// MachinePool.
MachineStatePending MachineState = "Pending"
MachineStateRunning MachineState = "Running"
MachineStatePending MachineState = "Pending"
// MachineStateRunning means the machine is running on a MachinePool.
MachineStateRunning MachineState = "Running"
// MachineStateShutdown means the machine is shut down.
MachineStateShutdown MachineState = "Shutdown"
MachineStateError MachineState = "Error"
MachineStateInitial MachineState = "Initial"
// MachineStateError means the machine is in an error state.
MachineStateError MachineState = "Error"
)

// MachineConditionType is a type a MachineCondition can have.
Expand All @@ -151,8 +158,6 @@ type MachineCondition struct {
Message string
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
ObservedGeneration int64
// LastUpdateTime is the last time a condition has been updated.
LastUpdateTime metav1.Time
// LastTransitionTime is the last time the status of a condition has transitioned from one state to another.
LastTransitionTime metav1.Time
}
Expand Down
11 changes: 7 additions & 4 deletions apis/compute/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ type MachinePoolCondition struct {
Message string
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
ObservedGeneration int64
// LastUpdateTime is the last time a condition has been updated.
LastUpdateTime metav1.Time
// LastTransitionTime is the last time the status of a condition has transitioned from one state to another.
LastTransitionTime metav1.Time
}

// MachinePoolState is a state a MachinePool can be in.
//+enum
type MachinePoolState string

const (
MachinePoolStateReady MachinePoolState = "Ready"
// MachinePoolStateReady marks a MachinePool as ready for accepting a Machine.
MachinePoolStateReady MachinePoolState = "Ready"
// MachinePoolStatePending marks a MachinePool as pending readiness.
MachinePoolStatePending MachinePoolState = "Pending"
MachinePoolStateError MachinePoolState = "Error"
// MachinePoolStateError marks a MachinePool in an error state.
MachinePoolStateError MachinePoolState = "Error"
// MachinePoolStateOffline marks a MachinePool as offline.
MachinePoolStateOffline MachinePoolState = "Offline"
)

Expand Down
7 changes: 6 additions & 1 deletion apis/compute/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

package v1alpha1

import networkingv1alpha1 "github.com/onmetal/onmetal-api/apis/networking/v1alpha1"
import (
networkingv1alpha1 "github.com/onmetal/onmetal-api/apis/networking/v1alpha1"
)

// EphemeralNetworkInterfaceSource is a definition for an ephemeral (i.e. coupled to the lifetime of the surrounding
// object) networking.NetworkInterface.
type EphemeralNetworkInterfaceSource struct {
// NetworkInterfaceTemplate is the template definition of the networking.NetworkInterface.
NetworkInterfaceTemplate *networkingv1alpha1.NetworkInterfaceTemplateSpec `json:"networkInterfaceTemplate,omitempty"`
}
81 changes: 43 additions & 38 deletions apis/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ type MachineSpec struct {
MachinePoolSelector map[string]string `json:"machinePoolSelector,omitempty"`
// MachinePoolRef defines machine pool to run the machine in.
// If empty, a scheduler will figure out an appropriate pool to run the machine in.
MachinePoolRef corev1.LocalObjectReference `json:"machinePoolRef,omitempty"`
MachinePoolRef *corev1.LocalObjectReference `json:"machinePoolRef,omitempty"`
// Image is the URL providing the operating system image of the machine.
Image string `json:"image"`
// Interfaces define a list of network interfaces present on the machine
Interfaces []Interface `json:"interfaces,omitempty"`
// NetworkInterfaces define a list of network interfaces present on the machine
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`
// Volumes are volumes attached to this machine.
Volumes []Volume `json:"volumes,omitempty"`
// IgnitionRef is a reference to a config map containing the ignition YAML for the machine to boot up.
// If key is empty, DefaultIgnitionKey will be used as fallback.
IgnitionRef *commonv1alpha1.ConfigMapKeySelector `json:"ignition,omitempty"`
IgnitionRef *commonv1alpha1.ConfigMapKeySelector `json:"ignitionRef,omitempty"`
// EFIVars are variables to pass to EFI while booting up.
EFIVars []EFIVar `json:"efiVars,omitempty"`
// Tolerations define tolerations the Machine has. Only MachinePools whose taints
Expand All @@ -50,23 +50,26 @@ type MachineSpec struct {

// EFIVar is a variable to pass to EFI while booting up.
type EFIVar struct {
Name string `json:"name,omitempty"`
UUID string `json:"uuid,omitempty"`
// Name is the name of the EFIVar.
Name string `json:"name"`
// UUID is the uuid of the EFIVar.
UUID string `json:"uuid"`
// Value is the value of the EFIVar.
Value string `json:"value"`
}

// DefaultIgnitionKey is the default key for MachineSpec.UserData.
const DefaultIgnitionKey = "ignition.yaml"

// Interface is the definition of a single interface
type Interface struct {
// NetworkInterface is the definition of a single interface
type NetworkInterface struct {
// Name is the name of the network interface.
Name string `json:"name"`
// InterfaceSource is where to obtain the interface from.
InterfaceSource `json:",inline"`
// NetworkInterfaceSource is where to obtain the interface from.
NetworkInterfaceSource `json:",inline"`
}

type InterfaceSource struct {
type NetworkInterfaceSource struct {
// NetworkInterfaceRef instructs to use the NetworkInterface at the target reference.
NetworkInterfaceRef *corev1.LocalObjectReference `json:"networkInterfaceRef,omitempty"`
// Ephemeral instructs to create an ephemeral (i.e. coupled to the lifetime of the surrounding object)
Expand All @@ -84,22 +87,18 @@ type Volume struct {

// VolumeSource specifies the source to use for a Volume.
type VolumeSource struct {
// VolumeClaim instructs the Volume to use a VolumeClaim as source for the attachment.
// VolumeClaimRef instructs the Volume to use a VolumeClaimRef as source for the attachment.
VolumeClaimRef *corev1.LocalObjectReference `json:"volumeClaimRef,omitempty"`
}

type RetainPolicy string

const (
RetainPolicyDeleteOnTermination RetainPolicy = "DeleteOnTermination"
RetainPolicyPersistent RetainPolicy = "Persistent"
)

// InterfaceStatus reports the status of an InterfaceSource.
type InterfaceStatus struct {
Name string `json:"name,omitempty"`
IPs []commonv1alpha1.IP `json:"ips"`
VirtualIP *commonv1alpha1.IP `json:"virtualIP,omitempty"`
// NetworkInterfaceStatus reports the status of an NetworkInterfaceSource.
type NetworkInterfaceStatus struct {
// Name is the name of the NetworkInterface to whom the status belongs to.
Name string `json:"name"`
// IPs are the ips allocated for the network interface.
IPs []commonv1alpha1.IP `json:"ips,omitempty"`
// VirtualIP is the virtual ip allocated for the network interface.
VirtualIP *commonv1alpha1.IP `json:"virtualIP,omitempty"`
}

// VolumeStatus is the status of a Volume.
Expand All @@ -112,23 +111,31 @@ type VolumeStatus struct {

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
State MachineState `json:"state,omitempty"`
Conditions []MachineCondition `json:"conditions,omitempty"`
Interfaces []InterfaceStatus `json:"interfaces,omitempty"`
VolumeAttachments []VolumeStatus `json:"volumes,omitempty"`
// State is the state of the machine.
State MachineState `json:"state,omitempty"`
// Conditions are the conditions of the machines.
Conditions []MachineCondition `json:"conditions,omitempty"`
// NetworkInterfaces is the list of network interface states for the machine.
NetworkInterfaces []NetworkInterfaceStatus `json:"networkInterfaces,omitempty"`
// Volumes is the list of volume states for the machine.
Volumes []VolumeStatus `json:"volumes,omitempty"`
}

// MachineState is the state of a machine.
//+enum
type MachineState string

const (
// MachineStatePending means the Machine has been accepted by the system, but not yet completely started.
// This includes time before being bound to a MachinePool, as well as time spent setting up the Machine on that
// MachinePool.
MachineStatePending MachineState = "Pending"
MachineStateRunning MachineState = "Running"
MachineStatePending MachineState = "Pending"
// MachineStateRunning means the machine is running on a MachinePool.
MachineStateRunning MachineState = "Running"
// MachineStateShutdown means the machine is shut down.
MachineStateShutdown MachineState = "Shutdown"
MachineStateError MachineState = "Error"
MachineStateInitial MachineState = "Initial"
// MachineStateError means the machine is in an error state.
MachineStateError MachineState = "Error"
)

// MachineConditionType is a type a MachineCondition can have.
Expand All @@ -139,26 +146,24 @@ const (
MachineSynced MachineConditionType = "Synced"
)

// MachineCondition is one of the conditions of a Machine.
// MachineCondition is one of the conditions of a volume.
type MachineCondition struct {
// Type is the type of the condition.
Type MachineConditionType `json:"type"`
// Status is the status of the condition.
Status corev1.ConditionStatus `json:"status"`
// Reason is a machine-readable indication of why the condition is in a certain state.
Reason string `json:"reason"`
Reason string `json:"reason,omitempty"`
// Message is a human-readable explanation of why the condition has a certain reason / state.
Message string `json:"message"`
Message string `json:"message,omitempty"`
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// LastUpdateTime is the last time a condition has been updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// LastTransitionTime is the last time the status of a condition has transitioned from one state to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient

// Machine is the Schema for the machines API
type Machine struct {
Expand Down
11 changes: 7 additions & 4 deletions apis/compute/v1alpha1/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ type MachinePoolCondition struct {
Message string `json:"message"`
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// LastUpdateTime is the last time a condition has been updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// LastTransitionTime is the last time the status of a condition has transitioned from one state to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// MachinePoolState is a state a MachinePool can be in.
//+enum
type MachinePoolState string

const (
MachinePoolStateReady MachinePoolState = "Ready"
// MachinePoolStateReady marks a MachinePool as ready for accepting a Machine.
MachinePoolStateReady MachinePoolState = "Ready"
// MachinePoolStatePending marks a MachinePool as pending readiness.
MachinePoolStatePending MachinePoolState = "Pending"
MachinePoolStateError MachinePoolState = "Error"
// MachinePoolStateError marks a MachinePool in an error state.
MachinePoolStateError MachinePoolState = "Error"
// MachinePoolStateOffline marks a MachinePool as offline.
MachinePoolStateOffline MachinePoolState = "Offline"
)

Expand Down
Loading

0 comments on commit 66373e7

Please sign in to comment.