Skip to content

Commit

Permalink
controllers: send versions and client phase while reporting status
Browse files Browse the repository at this point in the history
Signed-off-by: Leela Venkaiah G <[email protected]>
  • Loading branch information
leelavg committed Oct 4, 2023
1 parent 662f2c1 commit 9687c23
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
8 changes: 8 additions & 0 deletions config/rbac/status-reporter-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ rules:
- get
- list
- update
- apiGroups:
- config.openshift.io
resources:
- clusterversions
verbs:
- get
- list
- watch
15 changes: 15 additions & 0 deletions config/rbac/status-reporter-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: status-reporter
rules:
- apiGroups:
- operators.coreos.com
resources:
- clusterserviceversions
verbs:
- get
- list
- watch
12 changes: 12 additions & 0 deletions config/rbac/status-reporter-role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: status-reporter
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: status-reporter
subjects:
- kind: ServiceAccount
name: status-reporter
namespace: system
49 changes: 45 additions & 4 deletions service/status-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package main
import (
"context"
"os"
"strings"
"time"

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

configv1 "github.com/openshift/api/config/v1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
providerclient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -35,6 +37,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

const (
csvPrefix = "ocs-client-operator"
)

func main() {
scheme := runtime.NewScheme()
if err := v1alpha1.AddToScheme(scheme); err != nil {
Expand Down Expand Up @@ -79,7 +85,42 @@ func main() {
}

csvList := opv1a1.ClusterServiceVersionList{}
_ = cl.List(ctx, &csvList, client.InNamespace(storageClientNamespace))
if err = cl.List(ctx, &csvList, client.InNamespace(storageClientNamespace)); err != nil {
klog.Exitf("Failed to list csv resources: %v", err)
}

var operatorVersion string
for idx := range csvList.Items {
candidate := &csvList.Items[idx]
if strings.HasPrefix(candidate.Name, csvPrefix) {
operatorVersion = candidate.Spec.Version.String()
break
}
}

if operatorVersion == "" {
klog.Exitf("Unable to find csv with prefix %q", csvPrefix)
}

clusterVersion := &configv1.ClusterVersion{}
clusterVersion.Name = "version"
if err = cl.Get(ctx, types.NamespacedName{Name: clusterVersion.Name}, clusterVersion); err != nil {
klog.Exitf("Failed to get clusterVersion: %v", err)
}

var ocpVersion string
for idx := range clusterVersion.Status.History {
candidate := &clusterVersion.Status.History[idx]
if candidate.State == configv1.CompletedUpdate {
ocpVersion = candidate.Version
break
}
}

if ocpVersion == "" {
klog.Exitf("Unable to find ocp version with completed update")
}

providerClient, err := providerclient.NewProviderClient(
ctx,
storageClient.Spec.StorageProviderEndpoint,
Expand All @@ -90,9 +131,9 @@ func main() {
}
defer providerClient.Close()

temp := "Unknown"
if _, err = providerClient.ReportStatus(ctx, storageClient.Status.ConsumerID, temp, temp, string(storageClient.Status.Phase)); err != nil {
klog.Exitf("Failed to update lastHeartbeat of storageClient %v: %v", storageClient.Status.ConsumerID, err)
if _, err = providerClient.ReportStatus(ctx, storageClient.Status.ConsumerID, ocpVersion,
operatorVersion, string(storageClient.Status.Phase)); err != nil {
klog.Exitf("Failed to report status of storageClient %v: %v", storageClient.Status.ConsumerID, err)
}

var csiClusterConfigEntry = new(csi.ClusterConfigEntry)
Expand Down

0 comments on commit 9687c23

Please sign in to comment.