Skip to content

Commit 32bce3b

Browse files
authored
Merge pull request #46 from leelavg/5072-onboard
supply client operator version while onboarding
2 parents 38824f7 + d26b8ef commit 32bce3b

File tree

13 files changed

+296
-210
lines changed

13 files changed

+296
-210
lines changed

bundle/manifests/ocs-client-operator.clusterserviceversion.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ spec:
217217
- get
218218
- patch
219219
- update
220+
- apiGroups:
221+
- operators.coreos.com
222+
resources:
223+
- clusterserviceversions
224+
verbs:
225+
- get
226+
- list
227+
- watch
220228
- apiGroups:
221229
- security.openshift.io
222230
resources:

config/rbac/role.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ rules:
189189
- get
190190
- patch
191191
- update
192+
- apiGroups:
193+
- operators.coreos.com
194+
resources:
195+
- clusterserviceversions
196+
verbs:
197+
- get
198+
- list
199+
- watch
192200
- apiGroups:
193201
- security.openshift.io
194202
resources:

controllers/storageclient_controller.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"os"
26+
"strings"
2627
"time"
2728

2829
"github.com/red-hat-storage/ocs-client-operator/api/v1alpha1"
2930
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"
3031

3132
configv1 "github.com/openshift/api/config/v1"
33+
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
3234
providerClient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
3335
"google.golang.org/grpc/codes"
3436
"google.golang.org/grpc/status"
@@ -59,6 +61,8 @@ const (
5961
storageClientNameLabel = "ocs.openshift.io/storageclient.name"
6062
storageClientNamespaceLabel = "ocs.openshift.io/storageclient.namespace"
6163
storageClientFinalizer = "storageclient.ocs.openshift.io"
64+
65+
csvPrefix = "ocs-client-operator"
6266
)
6367

6468
// StorageClientReconciler reconciles a StorageClient object
@@ -110,6 +114,7 @@ func (s *StorageClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
110114
//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclients/finalizers,verbs=update
111115
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch
112116
//+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
113118

114119
func (s *StorageClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
115120
var err error
@@ -266,9 +271,23 @@ func (s *StorageClientReconciler) onboardConsumer(instance *v1alpha1.StorageClie
266271
return reconcile.Result{}, fmt.Errorf("failed to get the clusterVersion version of the OCP cluster: %v", err)
267272
}
268273

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+
}
269285
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)
272291
if err != nil {
273292
if st, ok := status.FromError(err); ok {
274293
s.logGrpcErrorAndReportEvent(instance, OnboardConsumer, err, st.Code())
@@ -436,17 +455,16 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
436455
var podDeadLineSeconds int64 = 120
437456
jobDeadLineSeconds := podDeadLineSeconds + 35
438457
var keepJobResourceSeconds int32 = 600
439-
var reducedKeptSuccecsful int32 = 1
440-
458+
var reducedKeptSuccecsful int32 = 1
441459

442460
_, err := controllerutil.CreateOrUpdate(s.ctx, s.Client, cronJob, func() error {
443461
cronJob.Spec = batchv1.CronJobSpec{
444-
Schedule: "* * * * *",
445-
ConcurrencyPolicy: batchv1.ForbidConcurrent,
462+
Schedule: "* * * * *",
463+
ConcurrencyPolicy: batchv1.ForbidConcurrent,
446464
SuccessfulJobsHistoryLimit: &reducedKeptSuccecsful,
447465
JobTemplate: batchv1.JobTemplateSpec{
448466
Spec: batchv1.JobSpec{
449-
ActiveDeadlineSeconds: &jobDeadLineSeconds,
467+
ActiveDeadlineSeconds: &jobDeadLineSeconds,
450468
TTLSecondsAfterFinished: &keepJobResourceSeconds,
451469
Template: corev1.PodTemplateSpec{
452470
Spec: corev1.PodSpec{
@@ -488,3 +506,7 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
488506
}
489507
return reconcile.Result{}, nil
490508
}
509+
510+
func (s *StorageClientReconciler) list(obj client.ObjectList, listOptions ...client.ListOption) error {
511+
return s.Client.List(s.ctx, obj, listOptions...)
512+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/operator-framework/api v0.20.0
1919
github.com/pkg/errors v0.9.1
2020
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
21-
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231220130936-5e04cc22fcf6
21+
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231221111740-6704e7366b4d
2222
github.com/stretchr/testify v1.8.4
2323
google.golang.org/grpc v1.60.0
2424
gopkg.in/yaml.v2 v2.4.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne
121121
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
122122
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
123123
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
124-
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231220130936-5e04cc22fcf6 h1:iqp9/JpGB5AU8GfB7Ws0WJcyYHIuphIOV/n1Py3gUgQ=
125-
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231220130936-5e04cc22fcf6/go.mod h1:vO4tyV9JHtbaUJXnCzl3Mv7JIUtFunswDad+H96qIUE=
124+
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231221111740-6704e7366b4d h1:7StPE9Z3vli+Cc6rTEy1abIc6IzCIeTcjBjepjWxDqo=
125+
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231221111740-6704e7366b4d/go.mod h1:vO4tyV9JHtbaUJXnCzl3Mv7JIUtFunswDad+H96qIUE=
126126
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
127127
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
128128
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
configv1 "github.com/openshift/api/config/v1"
3232
consolev1alpha1 "github.com/openshift/api/console/v1alpha1"
3333
secv1 "github.com/openshift/api/security/v1"
34+
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
3435
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3536
appsv1 "k8s.io/api/apps/v1"
3637
"k8s.io/apimachinery/pkg/runtime"
@@ -59,6 +60,7 @@ func init() {
5960
utilruntime.Must(apiv1alpha1.AddToScheme(scheme))
6061
utilruntime.Must(monitoringv1.AddToScheme(scheme))
6162
utilruntime.Must(consolev1alpha1.AddToScheme(scheme))
63+
utilruntime.Must(opv1a1.AddToScheme(scheme))
6264
//+kubebuilder:scaffold:scheme
6365
}
6466

vendor/github.com/red-hat-storage/ocs-operator/v4/services/provider/client/client.go

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/red-hat-storage/ocs-operator/v4/services/provider/clientstatus/status.go

-9
This file was deleted.

vendor/github.com/red-hat-storage/ocs-operator/v4/services/provider/interfaces/interfaces.go

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)