@@ -18,11 +18,10 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "encoding/json"
21
22
"fmt"
22
23
"time"
23
24
24
- osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
25
- consoleclient "github.com/kairos-io/osbuilder/pkg/client"
26
25
console "github.com/pluralsh/console/go/client"
27
26
batchv1 "k8s.io/api/batch/v1"
28
27
corev1 "k8s.io/api/core/v1"
@@ -41,6 +40,9 @@ import (
41
40
"sigs.k8s.io/controller-runtime/pkg/log"
42
41
"sigs.k8s.io/controller-runtime/pkg/predicate"
43
42
"sigs.k8s.io/controller-runtime/pkg/reconcile"
43
+
44
+ osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
45
+ consoleclient "github.com/kairos-io/osbuilder/pkg/client"
44
46
)
45
47
46
48
const (
@@ -406,7 +408,7 @@ func (r *OSArtifactReconciler) checkExport(ctx context.Context, artifact *osbuil
406
408
} else if job .Spec .Completions != nil {
407
409
if job .Status .Succeeded > 0 && artifact .Status .Phase == osbuilder .Exporting {
408
410
artifact .Status .Phase = osbuilder .Ready
409
- if err := r .upsertClusterIsoImage (artifact ); err != nil {
411
+ if err := r .upsertClusterIsoImage (ctx , artifact ); err != nil {
410
412
artifact .Status .Phase = osbuilder .Error
411
413
meta .SetStatusCondition (& artifact .Status .Conditions , metav1.Condition {
412
414
Type : "Ready" ,
@@ -444,11 +446,25 @@ func (r *OSArtifactReconciler) checkExport(ctx context.Context, artifact *osbuil
444
446
return requeue , nil
445
447
}
446
448
447
- func (r * OSArtifactReconciler ) upsertClusterIsoImage (artifact * osbuilder.OSArtifact ) error {
449
+ func (r * OSArtifactReconciler ) upsertClusterIsoImage (ctx context.Context , artifact * osbuilder.OSArtifact ) error {
450
+ cloudConfig , err := r .getCloudConfig (ctx , artifact )
451
+ if err != nil {
452
+ return err
453
+ }
454
+
455
+ var projectID * string = nil
456
+ project , _ := r .ConsoleClient .GetProject (artifact .Spec .Project )
457
+ if project != nil {
458
+ projectID = & project .ID
459
+ }
460
+
448
461
image := fmt .Sprintf ("%s:%s" , artifact .Spec .Exporter .Registry .Image .Repository , artifact .Spec .Exporter .Registry .Image .Tag )
449
462
attr := console.ClusterIsoImageAttributes {
450
- Image : image ,
451
- Registry : artifact .Spec .Exporter .Registry .Name ,
463
+ Image : image ,
464
+ Registry : artifact .Spec .Exporter .Registry .Name ,
465
+ User : cloudConfig .Users .FirstUser ().GetName (),
466
+ Password : cloudConfig .Users .FirstUser ().GetPasswd (),
467
+ ProjectID : projectID ,
452
468
}
453
469
454
470
getResponse , err := r .ConsoleClient .GetClusterIsoImage (& image )
@@ -518,3 +534,27 @@ func (r *OSArtifactReconciler) CreateConfigMap(ctx context.Context, artifact *os
518
534
519
535
return nil
520
536
}
537
+
538
+ func (r * OSArtifactReconciler ) getCloudConfig (ctx context.Context , artifact * osbuilder.OSArtifact ) (* osbuilder.CloudConfig , error ) {
539
+ config := & osbuilder.CloudConfig {}
540
+ secret := & corev1.Secret {}
541
+ key := client.ObjectKey {
542
+ Namespace : artifact .Namespace ,
543
+ Name : artifact .Spec .CloudConfigRef .Name ,
544
+ }
545
+
546
+ if err := r .Get (ctx , key , secret ); err != nil {
547
+ return config , err
548
+ }
549
+
550
+ configBytes , exists := secret .Data [artifact .Spec .CloudConfigRef .Key ]
551
+ if ! exists {
552
+ return config , fmt .Errorf ("could not find key %s in secret %s" , artifact .Spec .CloudConfigRef .Key , artifact .Spec .CloudConfigRef .Name )
553
+ }
554
+
555
+ if err := json .Unmarshal (configBytes , config ); err != nil {
556
+ return config , err
557
+ }
558
+
559
+ return config , nil
560
+ }
0 commit comments