Skip to content

Commit 98bae53

Browse files
committed
Update PR
1 parent 16e2007 commit 98bae53

File tree

7 files changed

+42
-39
lines changed

7 files changed

+42
-39
lines changed

broker/machinebroker/server/reservation_create.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
1212
"github.com/ironcore-dev/ironcore/api/core/v1alpha1"
1313
"github.com/ironcore-dev/ironcore/broker/common/cleaner"
14+
brokerutils "github.com/ironcore-dev/ironcore/broker/common/utils"
1415
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
1516
"github.com/ironcore-dev/ironcore/broker/machinebroker/apiutils"
1617
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
@@ -21,22 +22,6 @@ import (
2122
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
)
2324

24-
func prepareIronCoreLabels[T metav1alpha1.Object](obj T, brokerDownwardAPILabels map[string]string) (map[string]string, error) {
25-
labels := make(map[string]string)
26-
27-
for downwardAPILabelName, defaultLabelName := range brokerDownwardAPILabels {
28-
value := obj.GetMetadata().GetLabels()[machinepoolletv1alpha1.DownwardAPILabel(downwardAPILabelName)]
29-
if value == "" {
30-
value = obj.GetMetadata().GetLabels()[defaultLabelName]
31-
}
32-
if value != "" {
33-
labels[machinepoolletv1alpha1.DownwardAPILabel(downwardAPILabelName)] = value
34-
}
35-
}
36-
37-
return labels, nil
38-
}
39-
4025
func prepareIronCoreAnnotations[T metav1alpha1.Object](obj T) (map[string]string, error) {
4126
annotationsValue, err := apiutils.EncodeAnnotationsAnnotation(obj.GetMetadata().GetAnnotations())
4227
if err != nil {
@@ -60,10 +45,11 @@ func (s *Server) createIronCoreReservation(
6045
iriReservation *iri.Reservation,
6146
) (res *computev1alpha1.Reservation, retErr error) {
6247

63-
labels, err := prepareIronCoreLabels(iriReservation, s.brokerDownwardAPILabels)
64-
if err != nil {
65-
return nil, fmt.Errorf("error preparing ironcore reservation labels: %w", err)
66-
}
48+
labels := brokerutils.PrepareDownwardAPILabels(
49+
iriReservation.GetMetadata().GetLabels(),
50+
s.brokerDownwardAPILabels,
51+
machinepoolletv1alpha1.MachineDownwardAPIPrefix,
52+
)
6753

6854
annotations, err := prepareIronCoreAnnotations(iriReservation)
6955
if err != nil {

broker/machinebroker/server/reservation_create_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package server_test
55

66
import (
7+
"fmt"
8+
79
computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
810
corev1alpha1 "github.com/ironcore-dev/ironcore/api/core/v1alpha1"
911
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
@@ -50,9 +52,9 @@ var _ = Describe("CreateReservation", func() {
5052

5153
By("inspecting the ironcore reservation")
5254
Expect(ironcoreReservation.Labels).To(Equal(map[string]string{
53-
machinepoolletv1alpha1.DownwardAPILabel("root-reservation-uid"): "foobar",
54-
machinebrokerv1alpha1.CreatedLabel: "true",
55-
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.ReservationBrokerManager,
55+
fmt.Sprint(machinepoolletv1alpha1.MachineDownwardAPIPrefix, "root-reservation-uid"): "foobar",
56+
machinebrokerv1alpha1.CreatedLabel: "true",
57+
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.ReservationBrokerManager,
5658
}))
5759
encodedIRIAnnotations, err := apiutils.EncodeAnnotationsAnnotation(nil)
5860
Expect(err).NotTo(HaveOccurred())

broker/machinebroker/server/server_suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ func SetupTest() (*corev1.Namespace, *server.Server) {
136136
newSrv, err := server.New(cfg, ns.Name, server.Options{
137137
BaseURL: baseURL,
138138
BrokerDownwardAPILabels: map[string]string{
139-
"root-machine-uid": machinepoolletv1alpha1.MachineUIDLabel,
140-
"root-nic-uid": machinepoolletv1alpha1.NetworkInterfaceUIDLabel,
141-
"root-network-uid": machinepoolletv1alpha1.NetworkUIDLabel,
139+
"root-machine-uid": machinepoolletv1alpha1.MachineUIDLabel,
140+
"root-nic-uid": machinepoolletv1alpha1.NetworkInterfaceUIDLabel,
141+
"root-network-uid": machinepoolletv1alpha1.NetworkUIDLabel,
142142
"root-reservation-uid": machinepoolletv1alpha1.ReservationUIDLabel,
143143
},
144144
})

client-go/informers/externalversions/compute/v1alpha1/reservation.go

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

poollet/common/utils/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func PrepareDownwardAPILabels(
7272
switch o := obj.(type) {
7373
case *computev1alpha1.Machine:
7474
value, err = fieldpath.ExtractFieldPathAsString(o, fieldPath)
75+
case *computev1alpha1.Reservation:
76+
value, err = fieldpath.ExtractFieldPathAsString(o, fieldPath)
7577
case *networkingv1alpha1.Network:
7678
value, err = fieldpath.ExtractFieldPathAsString(o, fieldPath)
7779
case *networkingv1alpha1.NetworkInterface:

poollet/machinepoollet/controllers/reservation_controller.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
irimachine "github.com/ironcore-dev/ironcore/iri/apis/machine"
1515
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1616
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
17+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
1718
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
1819
utilclient "github.com/ironcore-dev/ironcore/utils/client"
20+
utilsmaps "github.com/ironcore-dev/ironcore/utils/maps"
1921
"github.com/ironcore-dev/ironcore/utils/predicates"
2022
"google.golang.org/grpc/codes"
2123
"google.golang.org/grpc/status"
@@ -279,21 +281,18 @@ func (r *ReservationReconciler) reconcile(ctx context.Context, log logr.Logger,
279281
}
280282

281283
func (r *ReservationReconciler) iriReservationLabels(reservation *computev1alpha1.Reservation) (map[string]string, error) {
282-
annotations := map[string]string{
284+
labels := map[string]string{
283285
v1alpha1.ReservationUIDLabel: string(reservation.UID),
284286
v1alpha1.ReservationNamespaceLabel: reservation.Namespace,
285287
v1alpha1.ReservationNameLabel: reservation.Name,
286288
}
287289

288-
for name, fieldPath := range r.DownwardAPILabels {
289-
value, err := fieldpath.ExtractFieldPathAsString(reservation, fieldPath)
290-
if err != nil {
291-
return nil, fmt.Errorf("error extracting downward api label %q: %w", name, err)
292-
}
293-
294-
annotations[v1alpha1.DownwardAPILabel(name)] = value
290+
apiLabels, err := poolletutils.PrepareDownwardAPILabels(reservation, r.DownwardAPILabels, v1alpha1.MachineDownwardAPIPrefix)
291+
if err != nil {
292+
return nil, err
295293
}
296-
return annotations, nil
294+
labels = utilsmaps.AppendMap(labels, apiLabels)
295+
return labels, nil
297296
}
298297

299298
func (r *ReservationReconciler) iriReservationAnnotations(
@@ -308,7 +307,7 @@ func (r *ReservationReconciler) iriReservationAnnotations(
308307
return nil, fmt.Errorf("error extracting downward api annotation %q: %w", name, err)
309308
}
310309

311-
annotations[v1alpha1.DownwardAPIAnnotation(name)] = value
310+
annotations[poolletutils.DownwardAPIAnnotation(v1alpha1.MachineDownwardAPIPrefix, name)] = value
312311
}
313312

314313
return annotations, nil

poollet/machinepoollet/controllers/reservation_controller_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package controllers_test
55

66
import (
7+
"fmt"
8+
79
_ "github.com/ironcore-dev/ironcore/api/common/v1alpha1"
810
computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
911
corev1alpha1 "github.com/ironcore-dev/ironcore/api/core/v1alpha1"
@@ -60,7 +62,7 @@ var _ = Describe("MachineController", func() {
6062
_, iriReservation := GetSingleMapEntry(srv.Reservations)
6163

6264
By("inspecting the iri reservation")
63-
Expect(iriReservation.Metadata.Labels).To(HaveKeyWithValue(machinepoolletv1alpha1.DownwardAPILabel(fooDownwardAPILabel), fooAnnotationValue))
65+
Expect(iriReservation.Metadata.Labels).To(HaveKeyWithValue(fmt.Sprintf("%s%s", machinepoolletv1alpha1.MachineDownwardAPIPrefix, fooDownwardAPILabel), fooAnnotationValue))
6466

6567
By("setting the reservation state to accepted")
6668
iriReservation = &testingmachine.FakeReservation{Reservation: proto.Clone(iriReservation.Reservation).(*iri.Reservation)}

0 commit comments

Comments
 (0)