Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enum validation to CRDs #28

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// +kubebuilder:object:generate=true
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +groupName=metal.ironcore.dev
Expand Down
3 changes: 0 additions & 3 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// Package v1alpha1 contains API Schema definitions for the metal v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=metal.ironcore.dev
package v1alpha1

import (
Expand Down
76 changes: 41 additions & 35 deletions api/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ const (

// MachineSpec defines the desired state of Machine
type MachineSpec struct {
//+kubebuilder:validation:Pattern=`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
// +kubebuilder:validation:Pattern=`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
UUID string `json:"uuid"`

OOBRef v1.LocalObjectReference `json:"oobRef"`

InventoryRef *v1.LocalObjectReference `json:"inventoryRef,omitempty"`

//+optional
// +optional
MachineClaimRef *v1.ObjectReference `json:"machineClaimRef,omitempty"`

//+optional
// +optional
LoopbackAddressRef *v1.LocalObjectReference `json:"loopbackAddressRef,omitempty"`

//+optional
// +optional
ASN string `json:"asn,omitempty"`

//+optional
Power Power `json:"power,omitempty"` // TODO: Revisit whether this is really optional.
// +kubebuilder:validation:Enum=On;Off
// +optional
Power Power `json:"power,omitempty"`

//+optional
// +kubebuilder:validation:Enum=On;Off;Blinking
// +optional
LocatorLED LocatorLED `json:"locatorLED,omitempty"`
}

Expand All @@ -57,67 +59,71 @@ const (

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
//+optional
// +optional
Manufacturer string `json:"manufacturer,omitempty"`

//+optional
// +optional
SKU string `json:"sku,omitempty"`

//+optional
// +optional
SerialNumber string `json:"serialNumber,omitempty"`

//+optional
// +kubebuilder:validation:Enum=On;Off
// +optional
Power Power `json:"power,omitempty"`

//+optional
// +kubebuilder:validation:Enum=On;Off;Blinking
// +optional
LocatorLED LocatorLED `json:"locatorLED,omitempty"`

//+optional
// +optional
ShutdownDeadline *metav1.Time `json:"shutdownDeadline,omitempty"`

//+optional
// +optional
NetworkInterfaces []MachineNetworkInterface `json:"networkInterfaces"`

//+optional
// +optional
// +kubebuilder:validation:Enum=Ready;Unready;Error
State MachineState `json:"state,omitempty"`

//+patchStrategy=merge
//+patchMergeKey=type
//+optional
// +patchStrategy=merge
// +patchMergeKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

type MachineNetworkInterface struct {
Name string `json:"name"`

//+kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
// +kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
MacAddress string `json:"macAddress"`

//+optional
// +optional
IPRef *v1.LocalObjectReference `json:"IPRef,omitempty"`

//+optional
// +optional
SwitchRef *v1.LocalObjectReference `json:"switchRef,omitempty"`
}

type MachineState string

const (
MachineStateReady MachineState = "Ready"
MachineStateError MachineState = "Error"
MachineStateReady MachineState = "Ready"
MachineStateUneady MachineState = "Unready"
MachineStateError MachineState = "Error"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="UUID",type=string,JSONPath=`.status.uuid`
//+kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
//+kubebuilder:printcolumn:name="SKU",type=string,JSONPath=`.status.sku`,priority=100
//+kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
//+kubebuilder:printcolumn:name="Power",type=string,JSONPath=`.status.power`
//+kubebuilder:printcolumn:name="LocatorLED",type=string,JSONPath=`.status.locatorLED`,priority=100
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="UUID",type=string,JSONPath=`.status.uuid`
// +kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
// +kubebuilder:printcolumn:name="SKU",type=string,JSONPath=`.status.sku`,priority=100
// +kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
// +kubebuilder:printcolumn:name="Power",type=string,JSONPath=`.status.power`
// +kubebuilder:printcolumn:name="LocatorLED",type=string,JSONPath=`.status.locatorLED`,priority=100
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +genclient

// Machine is the Schema for the machines API
Expand All @@ -129,7 +135,7 @@ type Machine struct {
Status MachineStatus `json:"status,omitempty"`
}

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

// MachineList contains a list of Machine
type MachineList struct {
Expand Down
24 changes: 13 additions & 11 deletions api/v1alpha1/machineclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ import (
// MachineClaimSpec defines the desired state of MachineClaim
// TODO: Validate that exactly one of MachineRef or MachineSelector is set.
type MachineClaimSpec struct {
//+optional
// +optional
MachineRef *v1.LocalObjectReference `json:"machineRef,omitempty"`

//+optional
// +optional
MachineSelector *metav1.LabelSelector `json:"machineSelector,omitempty"`

Image string `json:"image"`

// +kubebuilder:validation:Enum=On;Off
Power Power `json:"power"`

//+optional
// +optional
IgnitionSecretRef *v1.LocalObjectReference `json:"ignitionSecretRef,omitempty"`

//+optional
NetworkInterfaces []MachineClaimNetworkInterface `json:"networkInterfaces,omitempty"` // TODO: Revisit whether this is really optional.
// +optional
NetworkInterfaces []MachineClaimNetworkInterface `json:"networkInterfaces,omitempty"`
}

type MachineClaimNetworkInterface struct {
Expand All @@ -36,7 +37,8 @@ type MachineClaimNetworkInterface struct {

// MachineClaimStatus defines the observed state of MachineClaim
type MachineClaimStatus struct {
//+optional
// +kubebuilder:validation:Enum=Bound;Unbound
// +optional
Phase MachineClaimPhase `json:"phase,omitempty"`
}

Expand All @@ -47,10 +49,10 @@ const (
MachineClaimPhaseUnbound MachineClaimPhase = "Unbound"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +genclient

// MachineClaim is the Schema for the machineclaims API
Expand All @@ -62,7 +64,7 @@ type MachineClaim struct {
Status MachineClaimStatus `json:"status,omitempty"`
}

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

// MachineClaimList contains a list of MachineClaim
type MachineClaimList struct {
Expand Down
58 changes: 30 additions & 28 deletions api/v1alpha1/oob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ const (

// OOBSpec defines the desired state of OOB
type OOBSpec struct {
//+kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
// +kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
MACAddress string `json:"macAddress"`

EndpointRef v1.LocalObjectReference `json:"endpointRef"`

//+optional
SecretRef v1.LocalObjectReference `json:"secretRef,omitempty"`
// +optional
SecretRef *v1.LocalObjectReference `json:"secretRef,omitempty"`

//+optional
Protocol Protocol `json:"protocol,omitempty"`
// +optional
Protocol *Protocol `json:"protocol,omitempty"`

//+optional
// +optional
Flags map[string]string `json:"flags,omitempty"`

//+optional
// +optional
ConsoleProtocol *ConsoleProtocol `json:"consoleProtocol,omitempty"`
}

Expand Down Expand Up @@ -62,27 +62,29 @@ const (

// OOBStatus defines the observed state of OOB
type OOBStatus struct {
//+optional
// +kubebuilder:validation:Enum=Machine;Router;Switch
// +optional
Type OOBType `json:"type,omitempty"`

//+optional
// +optional
Manufacturer string `json:"manufacturer,omitempty"`

//+optional
// +optional
SKU string `json:"sku,omitempty"`

//+optional
// +optional
SerialNumber string `json:"serialNumber,omitempty"`

//+optional
// +optional
FirmwareVersion string `json:"firmwareVersion,omitempty"`

//+optional
// +kubebuilder:validation:Enum=Ready;Unready;Error
// +optional
State OOBState `json:"state,omitempty"`

//+patchStrategy=merge
//+patchMergeKey=type
//+optional
// +patchStrategy=merge
// +patchMergeKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

Expand All @@ -102,17 +104,17 @@ const (
OOBStateError OOBState = "Error"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.spec.macAddress`
//+kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.status.type`
//+kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
//+kubebuilder:printcolumn:name="SKU",type=string,JSONPath=`.status.sku`,priority=100
//+kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
//+kubebuilder:printcolumn:name="FirmwareVersion",type=string,JSONPath=`.status.firmwareVersion`,priority=100
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.spec.macAddress`
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.status.type`
// +kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
// +kubebuilder:printcolumn:name="SKU",type=string,JSONPath=`.status.sku`,priority=100
// +kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
// +kubebuilder:printcolumn:name="FirmwareVersion",type=string,JSONPath=`.status.firmwareVersion`,priority=100
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +genclient

// OOB is the Schema for the oobs API
Expand All @@ -124,7 +126,7 @@ type OOB struct {
Status OOBStatus `json:"status,omitempty"`
}

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

// OOBList contains a list of OOB
type OOBList struct {
Expand Down
24 changes: 12 additions & 12 deletions api/v1alpha1/oobsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import (

// OOBSecretSpec defines the desired state of OOBSecret
type OOBSecretSpec struct {
//+kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
// +kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
MACAddress string `json:"macAddress"`

Username string `json:"username"`

Password string `json:"password"`

//+optional
ExpirationDate *metav1.Time `json:"expirationDate,omitempty"`
// +optional
ExpirationTime *metav1.Time `json:"expirationTime,omitempty"`
}

// OOBSecretStatus defines the observed state of OOBSecret
type OOBSecretStatus struct {
//+patchStrategy=merge
//+patchMergeKey=type
//+optional
// +patchStrategy=merge
// +patchMergeKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.spec.macAddress`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="MACAddress",type=string,JSONPath=`.spec.macAddress`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +genclient

// OOBSecret is the Schema for the oobsecrets API
Expand All @@ -44,7 +44,7 @@ type OOBSecret struct {
Status OOBSecretStatus `json:"status,omitempty"`
}

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

// OOBSecretList contains a list of OOBSecret
type OOBSecretList struct {
Expand Down
Loading