Skip to content

Commit

Permalink
serverbios api types and controller
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Bortnikov <[email protected]>
  • Loading branch information
aobort committed Oct 4, 2024
1 parent 99c0891 commit e663a97
Show file tree
Hide file tree
Showing 12 changed files with 869 additions and 157 deletions.
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ resources:
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
controller: true
domain: ironcore.dev
group: metal
kind: ServerBIOS
path: github.com/ironcore-dev/metal-operator/api/v1alpha1
version: v1alpha1
version: "3"
20 changes: 20 additions & 0 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ import (
"k8s.io/apimachinery/pkg/util/runtime"
)

type JobType string

const (
ScanBIOSVersionJobType JobType = "ScanBIOSVersion"
UpdateBIOSVersionJobType JobType = "UpdateBIOSVersion"
ApplyBIOSSettingsJobType JobType = "ApplyBiosSettings"
)

// RunningJobRef contains job type and reference to Job object
type RunningJobRef struct {
// Type reflects the type of the job.
// +kubebuilder:validation:Enum=ScanBIOSVersion;UpdateBIOSVersion;ApplyBiosSettings
// +required
Type JobType `json:"type"`

// JobRef contains the reference to the Job object.
// +required
JobRef v1.ObjectReference `json:"jobRef"`
}

// IP is an IP address.
type IP struct {
netip.Addr `json:"-"`
Expand Down
41 changes: 16 additions & 25 deletions api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ type BootOrder struct {
Device string `json:"device"`
}

// BIOSSettings represents the BIOS settings for a server.
type BIOSSettings struct {
// Version specifies the version of the server BIOS for which the settings are defined.
Version string `json:"version"`
// Settings is a map of key-value pairs representing the BIOS settings.
Settings map[string]string `json:"settings,omitempty"`
}

// ServerSpec defines the desired state of a Server.
type ServerSpec struct {
// UUID is the unique identifier for the server.
Expand Down Expand Up @@ -103,8 +95,9 @@ type ServerSpec struct {

// BootOrder specifies the boot order of the server.
BootOrder []BootOrder `json:"bootOrder,omitempty"`
// BIOS specifies the BIOS settings for the server.
BIOS []BIOSSettings `json:"BIOS,omitempty"`

// BIOSSettingsRef is a reference to a ServerBIOS object.
BIOSSettingsRef v1.LocalObjectReference `json:"biOSSettingsRef,omitempty"`
}

// ServerState defines the possible states of a server.
Expand Down Expand Up @@ -168,8 +161,6 @@ type ServerStatus struct {
// NetworkInterfaces is a list of network interfaces associated with the server.
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`

BIOS BIOSSettings `json:"BIOS,omitempty"`

// Conditions represents the latest available observations of the server's current state.
// +patchStrategy=merge
// +patchMergeKey=type
Expand All @@ -192,18 +183,18 @@ type NetworkInterface struct {
MACAddress string `json:"macAddress"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="UUID",type=string,JSONPath=`.spec.uuid`
//+kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
//+kubebuilder:printcolumn:name="Model",type=string,JSONPath=`.status.model`
//+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="PowerState",type=string,JSONPath=`.status.powerState`
//+kubebuilder:printcolumn:name="IndicatorLED",type=string,JSONPath=`.status.indicatorLED`,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=`.spec.uuid`
// +kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
// +kubebuilder:printcolumn:name="Model",type=string,JSONPath=`.status.model`
// +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="PowerState",type=string,JSONPath=`.status.powerState`
// +kubebuilder:printcolumn:name="IndicatorLED",type=string,JSONPath=`.status.indicatorLED`,priority=100
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// Server is the Schema for the servers API
type Server struct {
Expand All @@ -214,7 +205,7 @@ type Server struct {
Status ServerStatus `json:"status,omitempty"`
}

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

// ServerList contains a list of Server
type ServerList struct {
Expand Down
82 changes: 82 additions & 0 deletions api/v1alpha1/serverbios_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ServerBIOSSpec defines the desired state of ServerBIOS
type ServerBIOSSpec struct {
// ScanPeriodMinutes defines the period in minutes after which scanned data is considered obsolete.
// +kubebuilder:default=30
// +optional
ScanPeriodMinutes int32 `json:"scanPeriodMinutes,omitempty"`

// ServerRef is a reference to Server object
// +optional
ServerRef v1.LocalObjectReference `json:"serverRef,omitempty"`

// BIOS contains a bios version and settings.
// +optional
BIOS BIOSSettings `json:"bios,omitempty"`
}

// BIOSSettings contains a version, settings and a flag defining whether it is a current version
type BIOSSettings struct {
// Version contains BIOS version
// +required
Version string `json:"version"`

// Settings contains BIOS settings as map
// +optional
Settings map[string]string `json:"settings,omitempty"`
}

// ServerBIOSStatus defines the observed state of ServerBIOS
type ServerBIOSStatus struct {
// LastScanTime reflects the timestamp when the scanning for installed firmware was performed
// +optional
LastScanTime metav1.Time `json:"lastScanTime,omitempty"`

// BIOS contains a bios version and settings.
// +optional
BIOS BIOSSettings `json:"bios,omitempty"`

// RunningJob reflects the invoked scan or update job running
// +optional
RunningJob RunningJobRef `json:"runningJob,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="Server",type=string,JSONPath=`.spec.serverRef.name`,description="Server name"
// +kubebuilder:printcolumn:name="BIOS Version",type=string,JSONPath=`.status.version`,description="Installed BIOS Version"

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

Spec ServerBIOSSpec `json:"spec,omitempty"`
Status ServerBIOSStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ServerBIOS{}, &ServerBIOSList{})
}
119 changes: 111 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.

Loading

0 comments on commit e663a97

Please sign in to comment.