Skip to content

Commit

Permalink
Add ServerMaintenance API types
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Feb 7, 2025
1 parent 0429e71 commit ac88aa0
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ifndef ignore-not-found
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: manifests kustomize kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -

.PHONY: uninstall
Expand Down
84 changes: 84 additions & 0 deletions api/v1alpha1/servermaintenance_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

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

const (
ServerMaintenanceReasonAnnotationKey = "metal.ironcore.dev/reason"
)

// ServerBootConfigurationTemplate defines the parameters to be used for rendering a boot configuration.
type ServerBootConfigurationTemplate struct {
// Name specifies the name of the boot configuration.
Name string `json:"name"`
// Parameters specifies the parameters to be used for rendering the boot configuration.
Spec ServerBootConfigurationSpec `json:"spec"`
}

// ServerMaintenanceSpec defines the desired state of a ServerMaintenance
type ServerMaintenanceSpec struct {
// Policy specifies the maintenance policy to be enforced on the server.
Policy ServerMaintenancePolicy `json:"policy,omitempty"`
// ServerRef is a reference to the server that is to be maintained.
ServerRef corev1.LocalObjectReference `json:"serverRef"`
// ServerPower specifies the power state of the server during maintenance.
ServerPower Power `json:"serverPower,omitempty"`
// ServerBootConfigurationTemplate specifies the boot configuration to be applied to the server during maintenance.
ServerBootConfigurationTemplate *ServerBootConfigurationTemplate `json:"serverBootConfigurationTemplate,omitempty"`
}

type ServerMaintenancePolicy string

const (
ServerMaintenancePolicyOwnerApproval ServerMaintenancePolicy = "OwnerApproval"
ServerMaintenancePolicyEnforced ServerMaintenancePolicy = "Enforced"
)

// ServerMaintenanceStatus defines the observed state of a ServerMaintenance
type ServerMaintenanceStatus struct {
State ServerMaintenanceState `json:"state,omitempty"`
}

type ServerMaintenanceState string

const (
ServerMaintenanceStatePending ServerMaintenanceState = "Pending"
ServerMaintenanceStateInMaintenance ServerMaintenanceState = "InMaintenance"
ServerMaintenanceStateCompleted ServerMaintenanceState = "Completed"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Server",type="string",JSONPath=".spec.serverRef.name"
// +kubebuilder:printcolumn:name="Policy",type="string",JSONPath=`.spec.policy`
// +kubebuilder:printcolumn:name="BootConfiguration",type="string",JSONPath=`.spec.serverBootConfigurationTemplate.name`
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=`.metadata.annotations.metal\.ironcore\.dev\/reason`
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

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

Spec ServerMaintenanceSpec `json:"spec,omitempty"`
Status ServerMaintenanceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&ServerMaintenance{}, &ServerMaintenanceList{})
}
113 changes: 112 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

151 changes: 151 additions & 0 deletions config/crd/bases/metal.ironcore.dev_servermaintenances.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.1
name: servermaintenances.metal.ironcore.dev
spec:
group: metal.ironcore.dev
names:
kind: ServerMaintenance
listKind: ServerMaintenanceList
plural: servermaintenances
singular: servermaintenance
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.serverRef.name
name: Server
type: string
- jsonPath: .spec.policy
name: Policy
type: string
- jsonPath: .spec.serverBootConfigurationTemplate.name
name: BootConfiguration
type: string
- jsonPath: .metadata.annotations.metal\.ironcore\.dev\/reason
name: Reason
type: string
- jsonPath: .status.state
name: State
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: ServerMaintenance is the Schema for the ServerMaintenance API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ServerMaintenanceSpec defines the desired state of a ServerMaintenance
properties:
policy:
description: Policy specifies the maintenance policy to be enforced
on the server.
type: string
serverBootConfigurationTemplate:
description: ServerBootConfigurationTemplate specifies the boot configuration
to be applied to the server during maintenance.
properties:
name:
description: Name specifies the name of the boot configuration.
type: string
spec:
description: Parameters specifies the parameters to be used for
rendering the boot configuration.
properties:
ignitionSecretRef:
description: |-
IgnitionSecretRef is a reference to the Kubernetes Secret object that contains
the ignition configuration for the server. This field is optional and can be omitted if not specified.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
image:
description: |-
Image specifies the boot image to be used for the server.
This field is optional and can be omitted if not specified.
type: string
serverRef:
description: ServerRef is a reference to the server for which
this boot configuration is intended.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
required:
- serverRef
type: object
required:
- name
- spec
type: object
serverPower:
description: ServerPower specifies the power state of the server during
maintenance.
type: string
serverRef:
description: ServerRef is a reference to the server that is to be
maintained.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
required:
- serverRef
type: object
status:
description: ServerMaintenanceStatus defines the observed state of a ServerMaintenance
properties:
state:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ resources:
- bases/metal.ironcore.dev_servers.yaml
- bases/metal.ironcore.dev_serverbootconfigurations.yaml
- bases/metal.ironcore.dev_serverclaims.yaml
- bases/metal.ironcore.dev_servermaintenances.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
Expand Down
Loading

0 comments on commit ac88aa0

Please sign in to comment.