Skip to content

Commit

Permalink
feat: Initial MicrovmReplicaSet reconciler logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Callisto13 committed Dec 1, 2022
1 parent c0e4a20 commit 1ebe243
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 109 deletions.
12 changes: 12 additions & 0 deletions api/v1alpha1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ const (
// MicrovmUnknownStateReason indicates that the microvm in in an unknown or unsupported state
// for reconciliation.
MicrovmUnknownStateReason = "MicrovmUnknownState"

// MicrovmReplicaSetReadyCondition indicates that the microvmreplicaset is in a complete state.
MicrovmReplicaSetReadyCondition clusterv1.ConditionType = "MicrovmReplicaSetReady"

// MicrovmReplicaSetIncompleteReason indicates the microvmreplicaset does not have all replicas yet.
MicrovmReplicaSetIncompleteReason = "MicrovmReplicaSetIncomplete"

// MicrovmReplicaSetDeletingReason indicates the microvmreplicaset is in a deleted state.
MicrovmReplicaSetDeletingReason = "MicrovmReplicaSetDeleting"

// MicrovmReplicaSetDeletedFailedReason indicates the microvmreplicaset failed to deleted cleanly.
MicrovmReplicaSetDeleteFailedReason = "MicrovmReplicaSetDeleteFailed"
)
6 changes: 3 additions & 3 deletions api/v1alpha1/microvm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
// MicrovmSpec defines the desired state of Microvm
type MicrovmSpec struct {
// Host sets the host device address for Microvm creation.
// +kubebuilder:validation:Required
microvm.Host `json:",inline"`
// +optional
Host microvm.Host `json:"host,omitempty"`
// VMSpec contains the Microvm spec.
// +kubebuilder:validation:Required
microvm.VMSpec `json:",inline"`
Expand All @@ -52,7 +52,7 @@ type MicrovmSpec struct {
// owner: "root:root"
// permissions: "0755"
// +optional
UserData *string `json:"userdata"`
UserData *string `json:"userdata,omitempty"`
// SSHPublicKeys is list of SSH public keys which will be added to the Microvm.
// +optional
SSHPublicKeys []microvm.SSHPublicKey `json:"sshPublicKeys,omitempty"`
Expand Down
31 changes: 26 additions & 5 deletions api/v1alpha1/microvmreplicaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
// MvmRSFinalizer allows ReconcileMicrovmReplicaSet to clean up resources associated with the ReplicaSet
// before removing it from the apiserver.
MvmRSFinalizer = "microvmreplicaset.infrastructure.microvm.x-k8s.io"
)

// MicrovmReplicaSetSpec defines the desired state of MicrovmReplicaSet
type MicrovmReplicaSetSpec struct {
// Replicas is the number of Microvms to create on the given Host with the given
Expand All @@ -30,7 +36,7 @@ type MicrovmReplicaSetSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// Host sets the host device address for Microvm creation.
// +kubebuilder:validation:Required
microvm.Host `json:",inline"`
Host microvm.Host `json:"host,omitempty"`
// // Selector is a label query over microvms that should match the replica count.
// // Label keys and values that must match in order to be controlled by this replica set.
// // It must match the microvm template's labels.
Expand All @@ -44,19 +50,24 @@ type MicrovmReplicaSetSpec struct {

// MicrovmReplicaSetStatus defines the observed state of MicrovmReplicaSet
type MicrovmReplicaSetStatus struct {
// Replicas is the most recently observed number of replicas.
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/#what-is-a-replicationcontroller
// Ready is true when Replicas is Equal to ReadyReplicas.
// +optional
// +kubebuilder:default=false
Ready bool `json:"ready"`

// Replicas is the most recently observed number of replicas which have been created.
// +optional
Replicas int32 `json:"replicas"`

// readyReplicas is the number of pods targeted by this ReplicaSet with a Ready Condition.
// ReadyReplicas is the number of pods targeted by this ReplicaSet with a Ready Condition.
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

// Represents the latest available observations of a replica set's current state.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []clusterv1.Conditions `json:"conditions,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -83,3 +94,13 @@ type MicrovmReplicaSetList struct {
func init() {
SchemeBuilder.Register(&MicrovmReplicaSet{}, &MicrovmReplicaSetList{})
}

// GetConditions returns the observations of the operational state of the MicrovmMachine resource.
func (r *MicrovmReplicaSet) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

// SetConditions sets the underlying service state of the MicrovmMachine to the predescribed clusterv1.Conditions.
func (r *MicrovmReplicaSet) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}
10 changes: 2 additions & 8 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ spec:
spec:
description: MicrovmReplicaSetSpec defines the desired state of MicrovmReplicaSet
properties:
endpoint:
description: Endpoint is the API endpoint for the microvm service
(i.e. flintlock) including the port.
type: string
name:
description: Name is an optional name for the host.
type: string
host:
description: Host sets the host device address for Microvm creation.
properties:
endpoint:
description: Endpoint is the API endpoint for the microvm service
(i.e. flintlock) including the port.
type: string
name:
description: Name is an optional name for the host.
type: string
required:
- endpoint
type: object
replicas:
default: 1
description: Replicas is the number of Microvms to create on the given
Expand Down Expand Up @@ -71,10 +77,20 @@ spec:
v1 kind: Secret metadata: name: mybasicauthsecret namespace:
same-as-microvm type: Opaque data: token: YWRtaW4="
type: string
endpoint:
description: Endpoint is the API endpoint for the microvm
service (i.e. flintlock) including the port.
type: string
host:
description: Host sets the host device address for Microvm
creation.
properties:
endpoint:
description: Endpoint is the API endpoint for the microvm
service (i.e. flintlock) including the port.
type: string
name:
description: Name is an optional name for the host.
type: string
required:
- endpoint
type: object
initrd:
description: Initrd is an optional initial ramdisk to use.
properties:
Expand Down Expand Up @@ -134,9 +150,6 @@ spec:
required:
- endpoint
type: object
name:
description: Name is an optional name for the host.
type: string
networkInterfaces:
description: NetworkInterfaces specifies the network interfaces
attached to the microvm.
Expand Down Expand Up @@ -271,16 +284,13 @@ spec:
type: object
type: array
required:
- endpoint
- kernel
- memoryMb
- networkInterfaces
- rootVolume
- vcpu
type: object
type: object
required:
- endpoint
type: object
status:
description: MicrovmReplicaSetStatus defines the observed state of MicrovmReplicaSet
Expand All @@ -289,53 +299,52 @@ spec:
description: Represents the latest available observations of a replica
set's current state.
items:
description: Conditions provide observations of the operational
state of a Cluster API resource.
items:
description: Condition defines an observation of a Cluster API
resource operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one
status to another. This should be when the underlying condition
changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not
this field is considered a guaranteed API. This field may
not be empty.
type: string
severity:
description: Severity provides an explicit classification
of Reason code, so the users or machines can immediately
understand the current situation and act accordingly. The
Severity field MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False,
Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict
is important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not this
field is considered a guaranteed API. This field may not be
empty.
type: string
severity:
description: Severity provides an explicit classification of
Reason code, so the users or machines can immediately understand
the current situation and act accordingly. The Severity field
MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
ready:
default: false
description: Ready is true when Replicas is Equal to ReadyReplicas.
type: boolean
readyReplicas:
description: readyReplicas is the number of pods targeted by this
ReplicaSet with a Ready Condition.
Expand All @@ -346,8 +355,6 @@ spec:
More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/#what-is-a-replicationcontroller'
format: int32
type: integer
required:
- replicas
type: object
type: object
served: true
Expand Down
21 changes: 13 additions & 8 deletions config/crd/bases/infrastructure.liquid-metal.io_microvms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ spec:
\n apiVersion: v1 kind: Secret metadata: name: mybasicauthsecret
namespace: same-as-microvm type: Opaque data: token: YWRtaW4="
type: string
endpoint:
description: Endpoint is the API endpoint for the microvm service
(i.e. flintlock) including the port.
type: string
host:
description: Host sets the host device address for Microvm creation.
properties:
endpoint:
description: Endpoint is the API endpoint for the microvm service
(i.e. flintlock) including the port.
type: string
name:
description: Name is an optional name for the host.
type: string
required:
- endpoint
type: object
initrd:
description: Initrd is an optional initial ramdisk to use.
properties:
Expand Down Expand Up @@ -103,9 +112,6 @@ spec:
required:
- endpoint
type: object
name:
description: Name is an optional name for the host.
type: string
networkInterfaces:
description: NetworkInterfaces specifies the network interfaces attached
to the microvm.
Expand Down Expand Up @@ -233,7 +239,6 @@ spec:
type: object
type: array
required:
- endpoint
- kernel
- memoryMb
- networkInterfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ spec:
metadata: name: mybasicauthsecret namespace: same-as-microvm
type: Opaque data: token: YWRtaW4="
type: string
endpoint:
description: Endpoint is the API endpoint for the microvm service
(i.e. flintlock) including the port.
type: string
host:
description: Host sets the host device address for Microvm creation.
properties:
endpoint:
description: Endpoint is the API endpoint for the microvm
service (i.e. flintlock) including the port.
type: string
name:
description: Name is an optional name for the host.
type: string
required:
- endpoint
type: object
initrd:
description: Initrd is an optional initial ramdisk to use.
properties:
Expand Down Expand Up @@ -112,9 +121,6 @@ spec:
required:
- endpoint
type: object
name:
description: Name is an optional name for the host.
type: string
networkInterfaces:
description: NetworkInterfaces specifies the network interfaces
attached to the microvm.
Expand Down Expand Up @@ -246,7 +252,6 @@ spec:
type: object
type: array
required:
- endpoint
- kernel
- memoryMb
- networkInterfaces
Expand Down
Loading

0 comments on commit 1ebe243

Please sign in to comment.