|
| 1 | +// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package v1alpha1 |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/stmcginnis/gofish/redfish" |
| 8 | + corev1 "k8s.io/api/core/v1" |
| 9 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 10 | +) |
| 11 | + |
| 12 | +type BIOSVersionState string |
| 13 | + |
| 14 | +const ( |
| 15 | + // BIOSVersionStatePending specifies that the bios upgrade maintenance is waiting |
| 16 | + BIOSVersionStatePending BIOSVersionState = "Pending" |
| 17 | + // BIOSVersionStateInProgress specifies that upgrading bios is in progress. |
| 18 | + BIOSVersionStateInProgress BIOSVersionState = "Processing" |
| 19 | + // BIOSVersionStateApplied specifies that the bios upgrade maintenance has been completed. |
| 20 | + BIOSVersionStateCompleted BIOSVersionState = "Completed" |
| 21 | + // BIOSVersionStateFailed specifies that the bios upgrade maintenance has failed. |
| 22 | + BIOSVersionStateFailed BIOSVersionState = "Failed" |
| 23 | +) |
| 24 | + |
| 25 | +// BIOSVersionSpec defines the desired state of BIOSVersion. |
| 26 | +type BIOSVersionSpec struct { |
| 27 | + // Spec specifies the spec for upgrading BIOS for specific serverRef. |
| 28 | + BIOSVersionSpec VersionSpec `json:"biosVersionSpec,omitempty"` |
| 29 | + |
| 30 | + // BiosSettingsRef is a reference to a specific BIOSSettings object which holds settings for this version |
| 31 | + // we use this to avoid multiple BIOS related ref on Server resources. |
| 32 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="BiosSettingsRef is immutable" |
| 33 | + BiosSettingsRef *corev1.LocalObjectReference `json:"biosSettingsRef,omitempty"` |
| 34 | + |
| 35 | + // ServerRef is a reference to a specific server to apply bios upgrade on. |
| 36 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="serverRef is immutable" |
| 37 | + ServerRef *corev1.LocalObjectReference `json:"serverRef,omitempty"` |
| 38 | + |
| 39 | + // ServerMaintenancePolicy is maintenance policy to be enforced on the server. |
| 40 | + ServerMaintenancePolicyType ServerMaintenancePolicy `json:"serverMaintenancePolicyType,omitempty"` |
| 41 | + |
| 42 | + // ServerMaintenanceRef is a reference to a ServerMaintenance object that that Controller has requested for the referred server. |
| 43 | + ServerMaintenanceRef *corev1.ObjectReference `json:"serverMaintenanceRef,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +type VersionSpec struct { |
| 47 | + // Version contains BIOS version to upgrade |
| 48 | + // +required |
| 49 | + Version string `json:"version"` |
| 50 | + // An indication of whether the server's upgrade service should bypass vendor update policies |
| 51 | + ForceUpdate bool `json:"forceUpdate,omitempty"` |
| 52 | + // details regarding the image to use to upgrade to given bios version |
| 53 | + Image ImageSpec `json:"image,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +type ImageSpec struct { |
| 57 | + // ImageSecretRef is a reference to the Kubernetes Secret (of type SecretTypeBasicAuth) object that contains the credentials |
| 58 | + // to access the ImageURI. This secret includes sensitive information such as usernames and passwords. |
| 59 | + SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` |
| 60 | + // The network protocol that the server's update service uses to retrieve 'ImageURI' |
| 61 | + TransferProtocol string `json:"transferProtocol,omitempty"` |
| 62 | + // The URI of the software image to update/install." |
| 63 | + // +required |
| 64 | + URI string `json:"URI,omitempty"` |
| 65 | +} |
| 66 | + |
| 67 | +// BIOSVersionStatus defines the observed state of BIOSVersion. |
| 68 | +type BIOSVersionStatus struct { |
| 69 | + // State represents the current state of the bios configuration task. |
| 70 | + State BIOSVersionState `json:"state,omitempty"` |
| 71 | + |
| 72 | + // UpgradeTaskStatus contains the state of the Upgrade Task created by the BMC |
| 73 | + UpgradeTaskStatus *TaskStatus `json:"upgradeTaskStatus,omitempty"` |
| 74 | + // Conditions represents the latest available observations of the Bios version upgrade state. |
| 75 | + // +patchStrategy=merge |
| 76 | + // +patchMergeKey=type |
| 77 | + // +optional |
| 78 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 79 | +} |
| 80 | + |
| 81 | +type TaskStatus struct { |
| 82 | + TaskURI string `json:"taskURI,omitempty"` |
| 83 | + State redfish.TaskState `json:"taskState,omitempty"` |
| 84 | + PercentComplete int `json:"percentageComplete,omitempty"` |
| 85 | +} |
| 86 | + |
| 87 | +// +kubebuilder:object:root=true |
| 88 | +// +kubebuilder:subresource:status |
| 89 | +// +kubebuilder:resource:scope=Cluster |
| 90 | +// +kubebuilder:printcolumn:name="BIOSVersion",type=string,JSONPath=`.spec.biosVersionSpec.version` |
| 91 | +// +kubebuilder:printcolumn:name="ForceUpdate",type=string,JSONPath=`.spec.biosVersionSpec.forceUpdate` |
| 92 | +// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state` |
| 93 | +// +kubebuilder:printcolumn:name="ServerRef",type=string,JSONPath=`.spec.serverRef.name` |
| 94 | +// +kubebuilder:printcolumn:name="ServerMaintenanceRef",type=string,JSONPath=`.spec.serverMaintenanceRef.name` |
| 95 | + |
| 96 | +// BIOSVersion is the Schema for the biosversions API. |
| 97 | +type BIOSVersion struct { |
| 98 | + metav1.TypeMeta `json:",inline"` |
| 99 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 100 | + |
| 101 | + Spec BIOSVersionSpec `json:"spec,omitempty"` |
| 102 | + Status BIOSVersionStatus `json:"status,omitempty"` |
| 103 | +} |
| 104 | + |
| 105 | +// +kubebuilder:object:root=true |
| 106 | + |
| 107 | +// BIOSVersionList contains a list of BIOSVersion. |
| 108 | +type BIOSVersionList struct { |
| 109 | + metav1.TypeMeta `json:",inline"` |
| 110 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 111 | + Items []BIOSVersion `json:"items"` |
| 112 | +} |
| 113 | + |
| 114 | +func init() { |
| 115 | + SchemeBuilder.Register(&BIOSVersion{}, &BIOSVersionList{}) |
| 116 | +} |
0 commit comments