@@ -23,12 +23,14 @@ import (
23
23
"encoding/json"
24
24
"fmt"
25
25
"os"
26
+ "strings"
26
27
"time"
27
28
28
29
"github.com/red-hat-storage/ocs-client-operator/api/v1alpha1"
29
30
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"
30
31
31
32
configv1 "github.com/openshift/api/config/v1"
33
+ opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
32
34
providerClient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
33
35
"google.golang.org/grpc/codes"
34
36
"google.golang.org/grpc/status"
@@ -59,6 +61,8 @@ const (
59
61
storageClientNameLabel = "ocs.openshift.io/storageclient.name"
60
62
storageClientNamespaceLabel = "ocs.openshift.io/storageclient.namespace"
61
63
storageClientFinalizer = "storageclient.ocs.openshift.io"
64
+
65
+ csvPrefix = "ocs-client-operator"
62
66
)
63
67
64
68
// StorageClientReconciler reconciles a StorageClient object
@@ -110,6 +114,7 @@ func (s *StorageClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
110
114
//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclients/finalizers,verbs=update
111
115
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch
112
116
//+kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;create;update;watch;delete
117
+ //+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=get;list;watch
113
118
114
119
func (s * StorageClientReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
115
120
var err error
@@ -266,9 +271,23 @@ func (s *StorageClientReconciler) onboardConsumer(instance *v1alpha1.StorageClie
266
271
return reconcile.Result {}, fmt .Errorf ("failed to get the clusterVersion version of the OCP cluster: %v" , err )
267
272
}
268
273
274
+ // TODO Have a version file corresponding to the release
275
+ csvList := opv1a1.ClusterServiceVersionList {}
276
+ if err = s .list (& csvList , client .InNamespace (s .OperatorNamespace )); err != nil {
277
+ return reconcile.Result {}, fmt .Errorf ("failed to list csv resources in ns: %v, err: %v" , s .OperatorNamespace , err )
278
+ }
279
+ csv := utils .Find (csvList .Items , func (csv * opv1a1.ClusterServiceVersion ) bool {
280
+ return strings .HasPrefix (csv .Name , csvPrefix )
281
+ })
282
+ if csv == nil {
283
+ return reconcile.Result {}, fmt .Errorf ("unable to find csv with prefix %q" , csvPrefix )
284
+ }
269
285
name := fmt .Sprintf ("storageconsumer-%s" , clusterVersion .Spec .ClusterID )
270
- response , err := externalClusterClient .OnboardConsumer (
271
- s .ctx , instance .Spec .OnboardingTicket , name )
286
+ onboardRequest := providerClient .NewOnboardConsumerRequest ().
287
+ SetConsumerName (name ).
288
+ SetOnboardingTicket (instance .Spec .OnboardingTicket ).
289
+ SetClientOperatorVersion (csv .Spec .Version .String ())
290
+ response , err := externalClusterClient .OnboardConsumer (s .ctx , onboardRequest )
272
291
if err != nil {
273
292
if st , ok := status .FromError (err ); ok {
274
293
s .logGrpcErrorAndReportEvent (instance , OnboardConsumer , err , st .Code ())
@@ -436,17 +455,16 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
436
455
var podDeadLineSeconds int64 = 120
437
456
jobDeadLineSeconds := podDeadLineSeconds + 35
438
457
var keepJobResourceSeconds int32 = 600
439
- var reducedKeptSuccecsful int32 = 1
440
-
458
+ var reducedKeptSuccecsful int32 = 1
441
459
442
460
_ , err := controllerutil .CreateOrUpdate (s .ctx , s .Client , cronJob , func () error {
443
461
cronJob .Spec = batchv1.CronJobSpec {
444
- Schedule : "* * * * *" ,
445
- ConcurrencyPolicy : batchv1 .ForbidConcurrent ,
462
+ Schedule : "* * * * *" ,
463
+ ConcurrencyPolicy : batchv1 .ForbidConcurrent ,
446
464
SuccessfulJobsHistoryLimit : & reducedKeptSuccecsful ,
447
465
JobTemplate : batchv1.JobTemplateSpec {
448
466
Spec : batchv1.JobSpec {
449
- ActiveDeadlineSeconds : & jobDeadLineSeconds ,
467
+ ActiveDeadlineSeconds : & jobDeadLineSeconds ,
450
468
TTLSecondsAfterFinished : & keepJobResourceSeconds ,
451
469
Template : corev1.PodTemplateSpec {
452
470
Spec : corev1.PodSpec {
@@ -488,3 +506,7 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
488
506
}
489
507
return reconcile.Result {}, nil
490
508
}
509
+
510
+ func (s * StorageClientReconciler ) list (obj client.ObjectList , listOptions ... client.ListOption ) error {
511
+ return s .Client .List (s .ctx , obj , listOptions ... )
512
+ }
0 commit comments