Skip to content

Commit

Permalink
feat: Generate MicrovmDeployment
Browse files Browse the repository at this point in the history
```
 kubebuilder create api \
   --group infrastructure \
   --version v1alpha1 \
   --kind MicrovmDeployment
```
  • Loading branch information
Callisto13 committed Dec 7, 2022
1 parent b33bbd6 commit 4c3aac3
Show file tree
Hide file tree
Showing 15 changed files with 789 additions and 15 deletions.
17 changes: 13 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
domain: flintlock.x-k8s.io
domain: liquid-metal.io
layout:
- go.kubebuilder.io/v3
projectName: microvm-operator
Expand All @@ -8,7 +8,7 @@ resources:
crdVersion: v1
namespaced: true
controller: true
domain: flintlock.x-k8s.io
domain: liquid-metal.io
group: infrastructure
kind: Microvm
path: github.com/weaveworks-liquidmetal/microvm-operator/api/v1alpha1
Expand All @@ -17,17 +17,26 @@ resources:
crdVersion: v1
namespaced: true
controller: true
domain: flintlock.x-k8s.io
domain: liquid-metal.io
group: infrastructure
kind: MicrovmReplicaSet
path: github.com/weaveworks-liquidmetal/microvm-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: flintlock.x-k8s.io
domain: liquid-metal.io
group: infrastructure
kind: MicrovmTemplate
path: github.com/weaveworks-liquidmetal/microvm-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: liquid-metal.io
group: infrastructure
kind: MicrovmDeployment
path: github.com/weaveworks-liquidmetal/microvm-operator/api/v1alpha1
version: v1alpha1
version: "3"
96 changes: 96 additions & 0 deletions api/v1alpha1/microvmdeployment_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
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

import (
microvm "github.com/weaveworks-liquidmetal/controller-pkg/types/microvm"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// MicrovmDeploymentSpec defines the desired state of MicrovmDeployment
type MicrovmDeploymentSpec struct {
// Replicas is the number of Microvms to create on the given Host with the given
// Microvm spec
// +kubebuilder:default=1
Replicas *int32 `json:"replicas,omitempty"`
// Host sets the host device address for Microvm creation.
// +kubebuilder:validation:Required
Hosts []microvm.Host `json:"hosts,omitempty"`
// Template is the object that describes the Microvm that will be created if
// insufficient replicas are detected.
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template
// +optional
Template MicrovmTemplateSpec `json:"template,omitempty" protobuf:"bytes,3,opt,name=template"`
}

// MicrovmDeploymentStatus defines the observed state of MicrovmDeployment
type MicrovmDeploymentStatus struct {
// Ready is true when all Replicas report ready
// +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.
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

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

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// MicrovmDeployment is the Schema for the microvmdeployments API
type MicrovmDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MicrovmDeploymentSpec `json:"spec,omitempty"`
Status MicrovmDeploymentStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// MicrovmDeploymentList contains a list of MicrovmDeployment
type MicrovmDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MicrovmDeployment `json:"items"`
}

func init() {
SchemeBuilder.Register(&MicrovmDeployment{}, &MicrovmDeploymentList{})
}

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

// SetConditions sets the underlying service state of the MicrovmMachine to the predescribed clusterv1.Conditions.
func (r *MicrovmDeployment) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}
4 changes: 0 additions & 4 deletions api/v1alpha1/microvmreplicaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ type MicrovmReplicaSetSpec struct {
// Host sets the host device address for Microvm creation.
// +kubebuilder:validation:Required
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.
// Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"`
// Template is the object that describes the Microvm that will be created if
// insufficient replicas are detected.
// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template
Expand Down
107 changes: 107 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 4c3aac3

Please sign in to comment.