Skip to content

Commit 298c52c

Browse files
committed
ServerBootConfig Conditions Populations from Internal APIs
1 parent b5cd2cc commit 298c52c

File tree

9 files changed

+922
-17
lines changed

9 files changed

+922
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.dll
66
*.so
77
*.dylib
8+
.DS_Store
89
bin/*
910
Dockerfile.cross
1011

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ ADDLICENSE ?= $(LOCALBIN)/addlicense
192192
GOIMPORTS ?= $(LOCALBIN)/goimports
193193
GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs
194194
KUBEBUILDER ?= $(LOCALBIN)/kubebuilder
195+
SETUP_ENVTEST_VERSION ?= v0.17.1 # example pre-0.22
195196

196197
## Tool Versions
197198
KUSTOMIZE_VERSION ?= v5.5.0

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/ironcore-dev/boot-operator
22

3-
go 1.24.0
3+
go 1.25.0
44

55
require (
66
github.com/containerd/containerd v1.7.28
77
github.com/coreos/butane v0.25.1
88
github.com/go-logr/logr v1.4.3
99
github.com/ironcore-dev/controller-utils v0.11.0
1010
github.com/ironcore-dev/metal v0.0.0-20240624131301-18385f342755
11-
github.com/ironcore-dev/metal-operator v0.1.0
11+
github.com/ironcore-dev/metal-operator v0.1.1-0.20251106073609-33d5f16e0db1
1212
github.com/onsi/ginkgo/v2 v2.27.2
1313
github.com/onsi/gomega v1.38.2
1414
github.com/opencontainers/image-spec v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ github.com/ironcore-dev/controller-utils v0.11.0 h1:vQhZgPxxFwmSi+fSlPEuwCmI5sOP
140140
github.com/ironcore-dev/controller-utils v0.11.0/go.mod h1:kPIgIjGNMA5zUlwH04rCdDbYnvvDtd79z3Rgav1Yrpg=
141141
github.com/ironcore-dev/metal v0.0.0-20240624131301-18385f342755 h1:EmR3Ngg2wmOXJkxgsdYVuPXLRfwWmO2Fi+htjih6QGY=
142142
github.com/ironcore-dev/metal v0.0.0-20240624131301-18385f342755/go.mod h1:+/bmkghOE7acqXDT/LDH57RemaUzlVwnQjttsOjdoyg=
143-
github.com/ironcore-dev/metal-operator v0.1.0 h1:0GqpKgfH5hG5jULUESsTr1dUH73ip3YJYIqtV8kBqoY=
144-
github.com/ironcore-dev/metal-operator v0.1.0/go.mod h1:JMxYoN5PJ0jvKhWlpV6kR9fhBXdLy2NNtvzJXXN/Iuc=
143+
github.com/ironcore-dev/metal-operator v0.1.1-0.20251106073609-33d5f16e0db1 h1:29bxRPvWNYGfMvAD06uS+bmfFndsAiCNtYbErEdOACc=
144+
github.com/ironcore-dev/metal-operator v0.1.1-0.20251106073609-33d5f16e0db1/go.mod h1:v6j2+CC/3iyRmXUp7JzyGpp/2EGDTEIQGYhlcegD+as=
145145
github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE=
146146
github.com/joshdk/go-junit v1.0.0/go.mod h1:TiiV0PqkaNfFXjEiyjWM3XXrhVyCa1K4Zfga6W52ung=
147147
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=

go.work.sum

Lines changed: 804 additions & 0 deletions
Large diffs are not rendered by default.

internal/controller/serverbootconfiguration_http_controller.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"fmt"
1010
"strings"
1111

12+
apimeta "k8s.io/apimachinery/pkg/api/meta"
13+
1214
"github.com/containerd/containerd/remotes/docker"
1315
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1416

@@ -133,15 +135,26 @@ func (r *ServerBootConfigurationHTTPReconciler) reconcile(ctx context.Context, l
133135
return ctrl.Result{}, nil
134136
}
135137

136-
func (r *ServerBootConfigurationHTTPReconciler) patchConfigStateFromHTTPState(ctx context.Context, httpBootConfig *bootv1alpha1.HTTPBootConfig, config *metalv1alpha1.ServerBootConfiguration) error {
137-
if httpBootConfig.Status.State == bootv1alpha1.HTTPBootConfigStateReady {
138-
return r.patchState(ctx, config, metalv1alpha1.ServerBootConfigurationStateReady)
138+
func (r *ServerBootConfigurationHTTPReconciler) patchConfigStateFromHTTPState(ctx context.Context, httpBootConfig *bootv1alpha1.HTTPBootConfig, cfg *metalv1alpha1.ServerBootConfiguration) error {
139+
key := types.NamespacedName{Name: cfg.Name, Namespace: cfg.Namespace}
140+
var cur metalv1alpha1.ServerBootConfiguration
141+
if err := r.Client.Get(ctx, key, &cur); err != nil {
142+
return err
139143
}
144+
base := cur.DeepCopy()
140145

141-
if httpBootConfig.Status.State == bootv1alpha1.HTTPBootConfigStateError {
142-
return r.patchState(ctx, config, metalv1alpha1.ServerBootConfigurationStateError)
146+
switch httpBootConfig.Status.State {
147+
case bootv1alpha1.HTTPBootConfigStateReady:
148+
cur.Status.State = metalv1alpha1.ServerBootConfigurationStateReady
149+
case bootv1alpha1.HTTPBootConfigStateError:
150+
cur.Status.State = metalv1alpha1.ServerBootConfigurationStateError
143151
}
144-
return nil
152+
153+
for _, c := range httpBootConfig.Status.Conditions {
154+
apimeta.SetStatusCondition(&cur.Status.Conditions, c)
155+
}
156+
157+
return r.Client.Status().Patch(ctx, &cur, client.MergeFrom(base))
145158
}
146159

147160
func (r *ServerBootConfigurationHTTPReconciler) patchState(ctx context.Context, config *metalv1alpha1.ServerBootConfiguration, state metalv1alpha1.ServerBootConfigurationState) error {

internal/controller/serverbootconfiguration_pxe_controller.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3131

3232
"github.com/ironcore-dev/boot-operator/api/v1alpha1"
33+
apimeta "k8s.io/apimachinery/pkg/api/meta"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3536

@@ -159,15 +160,26 @@ func (r *ServerBootConfigurationPXEReconciler) reconcile(ctx context.Context, lo
159160
return ctrl.Result{}, nil
160161
}
161162

162-
func (r *ServerBootConfigurationPXEReconciler) patchConfigStateFromIPXEState(ctx context.Context, ipxeConfig *v1alpha1.IPXEBootConfig, config *metalv1alpha1.ServerBootConfiguration) error {
163-
if ipxeConfig.Status.State == v1alpha1.IPXEBootConfigStateReady {
164-
return r.patchState(ctx, config, metalv1alpha1.ServerBootConfigurationStateReady)
163+
func (r *ServerBootConfigurationPXEReconciler) patchConfigStateFromIPXEState(ctx context.Context, ipxeConfig *v1alpha1.IPXEBootConfig, cfg *metalv1alpha1.ServerBootConfiguration) error {
164+
key := types.NamespacedName{Name: cfg.Name, Namespace: cfg.Namespace}
165+
var cur metalv1alpha1.ServerBootConfiguration
166+
if err := r.Client.Get(ctx, key, &cur); err != nil {
167+
return err
165168
}
169+
base := cur.DeepCopy()
166170

167-
if ipxeConfig.Status.State == v1alpha1.IPXEBootConfigStateError {
168-
return r.patchState(ctx, config, metalv1alpha1.ServerBootConfigurationStateError)
171+
switch ipxeConfig.Status.State {
172+
case v1alpha1.IPXEBootConfigStateReady:
173+
cur.Status.State = metalv1alpha1.ServerBootConfigurationStateReady
174+
case v1alpha1.IPXEBootConfigStateError:
175+
cur.Status.State = metalv1alpha1.ServerBootConfigurationStateError
169176
}
170-
return nil
177+
178+
for _, c := range ipxeConfig.Status.Conditions {
179+
apimeta.SetStatusCondition(&cur.Status.Conditions, c)
180+
}
181+
182+
return r.Client.Status().Patch(ctx, &cur, client.MergeFrom(base))
171183
}
172184

173185
func (r *ServerBootConfigurationPXEReconciler) patchState(ctx context.Context, config *metalv1alpha1.ServerBootConfiguration, state metalv1alpha1.ServerBootConfigurationState) error {

internal/controller/serverbootconfiguration_pxe_controller_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,78 @@ var _ = Describe("ServerBootConfiguration Controller", func() {
152152
HaveField("Spec.IgnitionSecretRef.Name", "foo"),
153153
))
154154
})
155+
156+
It("should mirror IPXEScriptFetched condition onto ServerBootConfiguration", func(ctx SpecContext) {
157+
By("creating a new Server object")
158+
server := &metalv1alpha1.Server{
159+
ObjectMeta: metav1.ObjectMeta{
160+
GenerateName: "server-",
161+
},
162+
Spec: metalv1alpha1.ServerSpec{
163+
UUID: "12345",
164+
},
165+
}
166+
Expect(k8sClient.Create(ctx, server)).To(Succeed())
167+
168+
By("patching the Server NICs in Server status")
169+
Eventually(UpdateStatus(server, func() {
170+
server.Status.NetworkInterfaces = []metalv1alpha1.NetworkInterface{
171+
{
172+
Name: "foo",
173+
IP: metalv1alpha1.MustParseIP("1.1.1.1"),
174+
MACAddress: "abcd",
175+
},
176+
}
177+
})).Should(Succeed())
178+
179+
By("creating a new ServerBootConfiguration")
180+
cfg := &metalv1alpha1.ServerBootConfiguration{
181+
ObjectMeta: metav1.ObjectMeta{
182+
Namespace: ns.Name,
183+
GenerateName: "test-",
184+
},
185+
Spec: metalv1alpha1.ServerBootConfigurationSpec{
186+
ServerRef: corev1.LocalObjectReference{
187+
Name: server.Name,
188+
},
189+
Image: "ghcr.io/ironcore-dev/os-images/gardenlinux:1877.0",
190+
IgnitionSecretRef: &corev1.LocalObjectReference{Name: "foo"},
191+
},
192+
}
193+
Expect(k8sClient.Create(ctx, cfg)).To(Succeed())
194+
195+
By("waiting for the IPXEBootConfig to be created")
196+
ipxe := &v1alpha1.IPXEBootConfig{
197+
ObjectMeta: metav1.ObjectMeta{
198+
Namespace: ns.Name,
199+
Name: cfg.Name,
200+
},
201+
}
202+
Eventually(Object(ipxe)).Should(Succeed())
203+
204+
By("setting IPXEScriptFetched=True on the IPXEBootConfig status")
205+
Eventually(UpdateStatus(ipxe, func() {
206+
ipxe.Status.State = v1alpha1.IPXEBootConfigStateReady
207+
ipxe.Status.Conditions = []metav1.Condition{
208+
{
209+
Type: "IPXEScriptFetched",
210+
Status: metav1.ConditionTrue,
211+
Reason: "ScriptDelivered",
212+
Message: "iPXE script has been successfully delivered to the client.",
213+
},
214+
}
215+
})).Should(Succeed())
216+
217+
By("verifying the condition appears on the ServerBootConfiguration status")
218+
Eventually(Object(cfg)).Should(SatisfyAll(
219+
WithTransform(func(c *metalv1alpha1.ServerBootConfiguration) bool {
220+
for _, cond := range c.Status.Conditions {
221+
if cond.Type == "IPXEScriptFetched" && cond.Status == metav1.ConditionTrue {
222+
return true
223+
}
224+
}
225+
return false
226+
}, BeTrue()),
227+
))
228+
})
155229
})

0 commit comments

Comments
 (0)