Skip to content

Commit 07911bc

Browse files
committed
Deprecate the endpointRef field on the BMC resource
Signed-off-by: Andreas Fritzler <andreas.fritzler@sap.com>
1 parent bf726ac commit 07911bc

11 files changed

Lines changed: 152 additions & 5 deletions

File tree

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ linters:
5656
- linters:
5757
- staticcheck
5858
text: "SA1019.*metalv1alpha1\\.Endpoint"
59+
# BMC.spec.endpointRef references the deprecated Endpoint resource. The operator
60+
# still serves existing BMCs that use it, so legacy consumers reference the field
61+
# until the Endpoint resource is fully removed.
62+
- linters:
63+
- staticcheck
64+
text: "SA1019.*\\.EndpointRef is deprecated"
5965
paths:
6066
- third_party$
6167
- builtin$

api/v1alpha1/applyconfiguration/api/v1alpha1/bmcspec.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/bmc_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ type BMCSpec struct {
3030
BMCUUID string `json:"bmcUUID,omitempty"`
3131

3232
// EndpointRef is a reference to the Endpoint object that contains the network access information for the BMC.
33+
//
34+
// Deprecated: The Endpoint resource is deprecated. Specify the network access inline via
35+
// access (an InlineEndpoint carrying the MAC address and IP) instead of referencing an
36+
// Endpoint object.
3337
// +optional
3438
// +kubebuilder:validation:Optional
3539
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="endpointRef is immutable"

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,13 @@ func main() { // nolint: gocyclo
649649
}
650650
}
651651
// nolint:goconst
652+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
653+
if err := webhookv1alpha1.SetupBMCWebhookWithManager(mgr); err != nil {
654+
setupLog.Error(err, "Failed to create webhook", "webhook", "bmc")
655+
os.Exit(1)
656+
}
657+
}
658+
// nolint:goconst
652659
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
653660
if err := webhookv1alpha1.SetupBMCSecretWebhookWithManager(mgr); err != nil {
654661
setupLog.Error(err, "Failed to create webhook", "webhook", "bmcsecret")

config/crd/bases/metal.ironcore.dev_bmcs.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ spec:
140140
- port
141141
type: object
142142
endpointRef:
143-
description: EndpointRef is a reference to the Endpoint object that
144-
contains the network access information for the BMC.
143+
description: |-
144+
EndpointRef is a reference to the Endpoint object that contains the network access information for the BMC.
145+
146+
Deprecated: The Endpoint resource is deprecated. Specify the network access inline via
147+
access (an InlineEndpoint carrying the MAC address and IP) instead of referencing an
148+
Endpoint object.
145149
properties:
146150
name:
147151
default: ""

config/webhook/manifests.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ webhooks:
4646
resources:
4747
- biosversions
4848
sideEffects: None
49+
- admissionReviewVersions:
50+
- v1
51+
clientConfig:
52+
service:
53+
name: webhook-service
54+
namespace: system
55+
path: /validate-metal-ironcore-dev-v1alpha1-bmc
56+
failurePolicy: Fail
57+
name: vbmc-v1alpha1.kb.io
58+
rules:
59+
- apiGroups:
60+
- metal.ironcore.dev
61+
apiVersions:
62+
- v1alpha1
63+
operations:
64+
- CREATE
65+
- UPDATE
66+
resources:
67+
- bmcs
68+
sideEffects: None
4969
- admissionReviewVersions:
5070
- v1
5171
clientConfig:

dist/chart/templates/crd/metal.ironcore.dev_bmcs.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ spec:
146146
- port
147147
type: object
148148
endpointRef:
149-
description: EndpointRef is a reference to the Endpoint object that
150-
contains the network access information for the BMC.
149+
description: |-
150+
EndpointRef is a reference to the Endpoint object that contains the network access information for the BMC.
151+
152+
Deprecated: The Endpoint resource is deprecated. Specify the network access inline via
153+
access (an InlineEndpoint carrying the MAC address and IP) instead of referencing an
154+
Endpoint object.
151155
properties:
152156
name:
153157
default: ""

dist/chart/templates/webhook/webhooks.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ webhooks:
5353
- v1alpha1
5454
resources:
5555
- biosversions
56+
- name: vbmc-v1alpha1.kb.io
57+
clientConfig:
58+
service:
59+
name: metal-operator-webhook-service
60+
namespace: {{ .Release.Namespace }}
61+
path: /validate-metal-ironcore-dev-v1alpha1-bmc
62+
failurePolicy: Fail
63+
sideEffects: None
64+
admissionReviewVersions:
65+
- v1
66+
rules:
67+
- operations:
68+
- CREATE
69+
- UPDATE
70+
apiGroups:
71+
- metal.ironcore.dev
72+
apiVersions:
73+
- v1alpha1
74+
resources:
75+
- bmcs
5676
- name: vbmcsecret-v1alpha1.kb.io
5777
clientConfig:
5878
service:

docs/api-reference/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ _Appears in:_
635635
| Field | Description | Default | Validation |
636636
| --- | --- | --- | --- |
637637
| `bmcUUID` _string_ | BMCUUID is the unique identifier for the BMC as defined in Redfish API. | | Optional: \{\} <br /> |
638-
| `endpointRef` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.36/#localobjectreference-v1-core)_ | EndpointRef is a reference to the Endpoint object that contains the network access information for the BMC. | | Optional: \{\} <br /> |
638+
| `endpointRef` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.36/#localobjectreference-v1-core)_ | EndpointRef is a reference to the Endpoint object that contains the network access information for the BMC.<br />Deprecated: The Endpoint resource is deprecated. Specify the network access inline via<br />access (an InlineEndpoint carrying the MAC address and IP) instead of referencing an<br />Endpoint object. | | Optional: \{\} <br /> |
639639
| `access` _[InlineEndpoint](#inlineendpoint)_ | Endpoint specifies inline network access details for the BMC. | | Optional: \{\} <br /> |
640640
| `bmcSecretRef` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.36/#localobjectreference-v1-core)_ | BMCSecretRef is a reference to the BMCSecret object that contains the credentials<br />required to access the BMC. | | |
641641
| `protocol` _[Protocol](#protocol)_ | Protocol specifies the protocol to be used for communicating with the BMC. | | |
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-FileCopyrightText: 2026 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+
"context"
8+
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
11+
ctrl "sigs.k8s.io/controller-runtime"
12+
logf "sigs.k8s.io/controller-runtime/pkg/log"
13+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
14+
15+
metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1"
16+
)
17+
18+
// log is for logging in this package.
19+
var bmclog = logf.Log.WithName("bmc-resource")
20+
21+
// SetupBMCWebhookWithManager registers the webhook for BMC in the manager.
22+
func SetupBMCWebhookWithManager(mgr ctrl.Manager) error {
23+
return ctrl.NewWebhookManagedBy(mgr, &metalv1alpha1.BMC{}).
24+
WithValidator(&BMCCustomValidator{Client: mgr.GetClient()}).
25+
Complete()
26+
}
27+
28+
// NOTE: The 'path' attribute must follow a specific pattern and should not be modified directly here.
29+
// Modifying the path for an invalid path can cause API server errors; failing to locate the webhook.
30+
// +kubebuilder:webhook:path=/validate-metal-ironcore-dev-v1alpha1-bmc,mutating=false,failurePolicy=fail,sideEffects=None,groups=metal.ironcore.dev,resources=bmcs,verbs=create;update,versions=v1alpha1,name=vbmc-v1alpha1.kb.io,admissionReviewVersions=v1
31+
32+
// BMCCustomValidator struct is responsible for validating the BMC resource
33+
// when it is created, updated, or deleted.
34+
//
35+
// NOTE: The +kubebuilder:object:generate=false marker prevents controller-gen from generating DeepCopy methods,
36+
// as this struct is used only for temporary operations and does not need to be deeply copied.
37+
// +kubebuilder:object:generate=false
38+
type BMCCustomValidator struct {
39+
Client client.Client
40+
}
41+
42+
// bmcEndpointRefDeprecationWarning is the admission warning surfaced on BMC create/update
43+
// when spec.endpointRef is set, to direct users toward the inlined BMC.spec.access path.
44+
const bmcEndpointRefDeprecationWarning = "spec.endpointRef is deprecated; specify the network access inline via spec.access (an InlineEndpoint with macAddress and ip) instead"
45+
46+
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type BMC.
47+
func (v *BMCCustomValidator) ValidateCreate(ctx context.Context, obj *metalv1alpha1.BMC) (admission.Warnings, error) {
48+
bmclog.Info("Validating BMC upon creation", "name", obj.GetName())
49+
50+
return bmcEndpointRefWarnings(obj), nil
51+
}
52+
53+
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type BMC.
54+
func (v *BMCCustomValidator) ValidateUpdate(ctx context.Context, oldObj, newObj *metalv1alpha1.BMC) (admission.Warnings, error) {
55+
bmclog.Info("Validating BMC upon update", "name", newObj.GetName())
56+
57+
return bmcEndpointRefWarnings(newObj), nil
58+
}
59+
60+
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type BMC.
61+
func (v *BMCCustomValidator) ValidateDelete(ctx context.Context, obj *metalv1alpha1.BMC) (admission.Warnings, error) {
62+
bmclog.Info("Validating BMC upon deletion", "name", obj.GetName())
63+
64+
return nil, nil
65+
}
66+
67+
// bmcEndpointRefWarnings returns the deprecation warning when the BMC references an Endpoint
68+
// via spec.endpointRef. It never rejects the object; the access/endpointRef exactly-one-of and
69+
// immutability rules are enforced by CEL XValidation markers on the BMCSpec type.
70+
func bmcEndpointRefWarnings(bmc *metalv1alpha1.BMC) admission.Warnings {
71+
if bmc.Spec.EndpointRef != nil {
72+
return admission.Warnings{bmcEndpointRefDeprecationWarning}
73+
}
74+
return nil
75+
}

0 commit comments

Comments
 (0)