Skip to content

Commit

Permalink
Merge pull request #82 from onmetal/machine_resource
Browse files Browse the repository at this point in the history
Initial and `Machine` resource spec
  • Loading branch information
afritzler authored Jul 27, 2021
2 parents 0b87867 + 498bede commit b738d52
Show file tree
Hide file tree
Showing 16 changed files with 831 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,13 @@ resources:
kind: Subnet
path: github.com/onmetal/onmetal-api/apis/network/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: onmetal.de
group: compute
kind: Machine
path: github.com/onmetal/onmetal-api/apis/compute/v1alpha1
version: v1alpha1
version: "3"
10 changes: 10 additions & 0 deletions apis/common/v1alpha1/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ type RegionAvailability struct {

//+kubebuilder:object:generate=true

// Location describes the location of a resource
type Location struct {
// Region defines the region of a resource
Region string `json:"region"`
// AvailabilityZone is the availability zone of a resource
AvailabilityZone string `json:"availabilityZone"`
}

//+kubebuilder:object:generate=true

// ZoneAvailability defines the name of a zone
type ZoneAvailability struct {
// Name is the name of the availability zone
Expand Down
15 changes: 15 additions & 0 deletions apis/common/v1alpha1/zz_generated.deepcopy.go

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

121 changes: 121 additions & 0 deletions apis/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Copyright 2021.
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 (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// MachineSpec defines the desired state of Machine
type MachineSpec struct {
// Hostname is the hostname of the machine
Hostname string `json:"hostname"`
// MachineClass is the machine class/flavor of the machine
MachineClass common.ScopeReference `json:"machineClass"`
// MachinePool defines the compute pool of the machine
MachinePool common.ScopeReference `json:"machine_pool,omitempty"`
// Location is the physical location of the machine
Location common.Location `json:"location"`
// Image is the operating system image of the machine
Image common.ScopeReference `json:"image"`
// SSHPublicKeys is a list of SSH public keys of a machine
SSHPublicKeys []SSHPublicKeyEntry `json:"sshPublicKeys"`
// Interfaces define a list of network interfaces present on the machine
// TODO: define interfaces/network references
// SecurityGroups is a list of security groups of a machine
SecurityGroups []common.ScopeReference `json:"securityGroups"`
// VolumeClaims
VolumeClaims []VolumeClaim `json:"volumeClaims"`
// UserData defines the ignition file
UserData string `json:"userData,omitempty"`
}

// VolumeClaim defines a volume claim of a machine
type VolumeClaim struct {
// Name is the name of the VolumeClaim
Name string `json:"name"`
// RetainPolicy defines what should happen when the machine is being deleted
RetainPolicy RetainPolicy `json:"retainPolicy"`
// Device defines the device for a volume on the machine
Device string `json:"device"`
// StorageClass describes the storage class of the volumes
StorageClass common.ScopeReference `json:"storageClass"`
// Size defines the size of the volume
Size *resource.Quantity `json:"size,omitempty"`
// Volume is a reference to an existing volume
Volume common.ScopeReference `json:"volume,omitempty"`
}

type RetainPolicy string

const (
RetainPolicyDeleteOnTermination RetainPolicy = "DeleteOnTermination"
RetainPolicyPersistent RetainPolicy = "Persistent"
MachineStateRunning = "Running"
MachineStateShutdown = "Shutdown"
MachineStateError = "Error"
MachineStateInitial = "Initial"
)

// SSHPublicKeyEntry describes either a reference to a SSH public key or a selector
// to filter for a public key
type SSHPublicKeyEntry struct {
// Scope is the scope of a SSH public key
Scope string `json:"scope,omitempty"`
// Name is the name of the SSH public key
Name string `json:"name,omitempty"`
// Selector defines a LabelSelector to filter for a public key
Selector metav1.LabelSelector `json:"selector,omitempty"`
}

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
common.StateFields `json:",inline"`
//TODO: define machine state fields
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Hostname",type=string,JSONPath=`.spec.hostname`
//+kubebuilder:printcolumn:name="MachineClass",type=string,JSONPath=`.spec.machineClass.name`
//+kubebuilder:printcolumn:name="Image",type=string,JSONPath=`.spec.image.name`
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

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

Spec MachineSpec `json:"spec,omitempty"`
Status MachineStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Machine{}, &MachineList{})
}
151 changes: 151 additions & 0 deletions apis/compute/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 b738d52

Please sign in to comment.