@@ -9,16 +9,17 @@ import (
99 "fmt"
1010 "maps"
1111
12- "github.com/ironcore-dev/ironcore/poollet/machinepoollet/controllers/events"
13- "github.com/ironcore-dev/ironcore/utils/annotations"
14-
1512 "github.com/go-logr/logr"
13+ commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1"
1614 computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
1715 storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
1816 computeclient "github.com/ironcore-dev/ironcore/internal/client/compute"
17+ "github.com/ironcore-dev/ironcore/poollet/machinepoollet/controllers/events"
18+ "github.com/ironcore-dev/ironcore/utils/annotations"
1919 corev1 "k8s.io/api/core/v1"
2020 apierrors "k8s.io/apimachinery/pkg/api/errors"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+ "k8s.io/apimachinery/pkg/types"
2223 "k8s.io/client-go/tools/record"
2324 "k8s.io/klog/v2"
2425 ctrl "sigs.k8s.io/controller-runtime"
@@ -130,6 +131,34 @@ func (r *MachineEphemeralVolumeReconciler) handleCreateVolume(ctx context.Contex
130131 return r .handleExistingVolume (ctx , log , machine , true , volume )
131132}
132133
134+ func (r * MachineEphemeralVolumeReconciler ) getMachineArchitecture (ctx context.Context , machine * computev1alpha1.Machine ) (* string , error ) {
135+ machineClass := & computev1alpha1.MachineClass {}
136+ if err := r .Get (ctx , types.NamespacedName {Name : machine .Spec .MachineClassRef .Name }, machineClass ); err != nil {
137+ return nil , fmt .Errorf ("error getting machine class %s: %w" , machine .Spec .MachineClassRef .Name , err )
138+ }
139+
140+ architecture , ok := machineClass .Labels [commonv1alpha1 .MachineArchitectureLabel ]
141+ if ! ok {
142+ return nil , nil
143+ }
144+
145+ return & architecture , nil
146+ }
147+
148+ func (r * MachineEphemeralVolumeReconciler ) addArchitectureIfNeeded (log logr.Logger , volume * storagev1alpha1.Volume , architecture * string ) {
149+ if volume .Spec .DataSource .OSImage == nil || architecture == nil {
150+ return
151+ }
152+
153+ if volume .Spec .DataSource .OSImage .Architecture != nil {
154+ log .V (2 ).Info ("Architecture already set" , "architecture" , volume .Spec .DataSource .OSImage .Architecture )
155+ return
156+ }
157+
158+ log .V (2 ).Info ("Adding architecture" , "architecture" , architecture )
159+ volume .Spec .DataSource .OSImage .Architecture = architecture
160+ }
161+
133162func (r * MachineEphemeralVolumeReconciler ) reconcile (ctx context.Context , log logr.Logger , machine * computev1alpha1.Machine ) (ctrl.Result , error ) {
134163 log .V (1 ).Info ("Reconcile" )
135164
@@ -141,6 +170,11 @@ func (r *MachineEphemeralVolumeReconciler) reconcile(ctx context.Context, log lo
141170 return ctrl.Result {}, fmt .Errorf ("error listing volumes: %w" , err )
142171 }
143172
173+ arch , err := r .getMachineArchitecture (ctx , machine )
174+ if err != nil {
175+ return ctrl.Result {}, fmt .Errorf ("error getting machine architecture: %w" , err )
176+ }
177+
144178 var (
145179 ephemVolumeByName = r .ephemeralMachineVolumeByName (machine )
146180 errs []error
@@ -157,6 +191,7 @@ func (r *MachineEphemeralVolumeReconciler) reconcile(ctx context.Context, log lo
157191
158192 for _ , volume := range ephemVolumeByName {
159193 log := log .WithValues ("Volume" , klog .KObj (volume ))
194+ r .addArchitectureIfNeeded (log , volume , arch )
160195 if err := r .handleCreateVolume (ctx , log , machine , volume ); err != nil {
161196 if apierrors .IsForbidden (err ) {
162197 r .Eventf (machine , corev1 .EventTypeNormal , events .VolumeNotReady , "Volume %s exceeded quota " , volume .Name )
0 commit comments