@@ -18,13 +18,13 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"time"
22
23
23
24
"github.com/IBM-Cloud/power-go-client/power/models"
24
25
"github.com/go-logr/logr"
25
26
"github.com/pkg/errors"
26
27
27
- "github.com/IBM/go-sdk-core/v5/core"
28
28
apierrors "k8s.io/apimachinery/pkg/api/errors"
29
29
"k8s.io/apimachinery/pkg/runtime"
30
30
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -108,26 +108,41 @@ func (r *IBMPowerVSImageReconciler) reconcile(ctx context.Context, cluster *v1be
108
108
return ctrl.Result {}, nil
109
109
}
110
110
111
+ if jobID := imageScope .GetJobID (); jobID != "" {
112
+ job , err := imageScope .IBMPowerVSClient .GetJob (jobID )
113
+ if err != nil {
114
+ imageScope .Info ("Unable to get job details" )
115
+ return ctrl.Result {RequeueAfter : 2 * time .Minute }, err
116
+ }
117
+ switch * job .Status .State {
118
+ case "completed" :
119
+ conditions .MarkTrue (imageScope .IBMPowerVSImage , v1beta1 .ImageImportedCondition )
120
+ case "failed" :
121
+ imageScope .SetNotReady ()
122
+ imageScope .SetImageState (string (v1beta1 .PowerVSImageStateFailed ))
123
+ conditions .MarkFalse (imageScope .IBMPowerVSImage , v1beta1 .ImageImportedCondition , v1beta1 .ImageImportFailedReason , clusterv1 .ConditionSeverityError , job .Status .Message )
124
+ return ctrl.Result {RequeueAfter : 2 * time .Minute }, fmt .Errorf ("failed to import image, message: %s" , job .Status .Message )
125
+ case "queued" :
126
+ imageScope .SetNotReady ()
127
+ imageScope .SetImageState (string (v1beta1 .PowerVSImageStateQue ))
128
+ conditions .MarkFalse (imageScope .IBMPowerVSImage , v1beta1 .ImageImportedCondition , string (v1beta1 .PowerVSImageStateQue ), clusterv1 .ConditionSeverityInfo , job .Status .Message )
129
+ return ctrl.Result {RequeueAfter : 2 * time .Minute }, nil
130
+ default :
131
+ imageScope .SetNotReady ()
132
+ imageScope .SetImageState (string (v1beta1 .PowerVSImageStateImporting ))
133
+ conditions .MarkFalse (imageScope .IBMPowerVSImage , v1beta1 .ImageImportedCondition , * job .Status .State , clusterv1 .ConditionSeverityInfo , job .Status .Message )
134
+ return ctrl.Result {RequeueAfter : 2 * time .Minute }, nil
135
+ }
136
+ }
137
+
111
138
img , jobRef , err := r .getOrCreate (imageScope )
112
139
if err != nil {
113
140
imageScope .Error (err , "Unable to import image" )
114
141
return ctrl.Result {}, errors .Wrapf (err , "failed to reconcile Image for IBMPowerVSImage %s/%s" , imageScope .IBMPowerVSImage .Namespace , imageScope .IBMPowerVSImage .Name )
115
142
}
116
143
117
144
if jobRef != nil {
118
- job , err := imageScope .IBMPowerVSClient .GetJob (* jobRef .ID )
119
- if err != nil {
120
- imageScope .Info ("Unable to get job details" )
121
- return ctrl.Result {RequeueAfter : 2 * time .Minute }, err
122
- }
123
-
124
- if * job .Status .State != "completed" && * job .Status .State != "failed" {
125
- imageScope .Info ("Import job not yet finished - " + * job .Status .State )
126
- imageScope .SetNotReady ()
127
- imageScope .SetImageState (core .StringPtr ("" ))
128
- conditions .MarkFalse (imageScope .IBMPowerVSImage , v1beta1 .ImageReadyCondition , v1beta1 .ImageNotReadyReason , clusterv1 .ConditionSeverityWarning , "" )
129
- return ctrl.Result {}, nil
130
- }
145
+ imageScope .SetJobID (* jobRef .ID )
131
146
}
132
147
return reconcileImage (img , imageScope )
133
148
}
@@ -142,11 +157,11 @@ func reconcileImage(img *models.ImageReference, imageScope *scope.PowerVSImageSc
142
157
143
158
imageScope .SetImageID (image .ImageID )
144
159
imageScope .Info ("ImageID - " + imageScope .GetImageID ())
145
- imageScope .SetImageState (& image .State )
160
+ imageScope .SetImageState (image .State )
146
161
imageScope .Info ("ImageState - " + image .State )
147
162
148
163
switch imageScope .GetImageState () {
149
- case v1beta1 .PowerVSInstanceStateQue :
164
+ case v1beta1 .PowerVSImageStateQue :
150
165
imageScope .Info ("Image is in queued state" )
151
166
imageScope .SetNotReady ()
152
167
conditions .MarkFalse (imageScope .IBMPowerVSImage , v1beta1 .ImageReadyCondition , v1beta1 .ImageNotReadyReason , clusterv1 .ConditionSeverityWarning , "" )
0 commit comments