Skip to content

Commit

Permalink
controllers: send cluster and operator version 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 6, 2023
1 parent 9975ecd commit 328d3b4
Show file tree
Hide file tree
Showing 52 changed files with 8,192 additions and 2 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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.27.9
github.com/openshift/api v0.0.0-20230816181854-a7ca92db022a
github.com/operator-framework/api v0.17.7-0.20230626210316-aa3e49803e7b
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.67.1
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20230915072501-d290a4270291
Expand All @@ -31,6 +32,7 @@ require (

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
Expand Down Expand Up @@ -61,6 +63,7 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -106,6 +108,8 @@ github.com/onsi/gomega v1.27.9 h1:qIyVWbOsvQEye2QCqLsNSeH/5L1RS9vS382erEWfT3o=
github.com/onsi/gomega v1.27.9/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/openshift/api v0.0.0-20230816181854-a7ca92db022a h1:1bylAza0mFIchRCRPVY9qy62CxJE18fpjEAUSpIA5O4=
github.com/openshift/api v0.0.0-20230816181854-a7ca92db022a/go.mod h1:yimSGmjsI+XF1mr+AKBs2//fSXIOhhetHGbMlBEfXbs=
github.com/operator-framework/api v0.17.7-0.20230626210316-aa3e49803e7b h1:prJEMyFQde4yxxaTuvqx1A/ukuCg/EZ2MbfdZiJwlls=
github.com/operator-framework/api v0.17.7-0.20230626210316-aa3e49803e7b/go.mod h1:lnurXgadLnoZ7pufKMHkErr2BVOIZSpHtvEkHBcKvdk=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -123,6 +127,8 @@ github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -186,6 +192,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
51 changes: 49 additions & 2 deletions service/status-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ 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"
"github.com/red-hat-storage/ocs-operator/v4/services/provider/status"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -34,6 +38,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 @@ -77,6 +85,43 @@ func main() {
klog.Exitf("Failed to get storageClient %q/%q: %v", storageClient.Namespace, storageClient.Name, err)
}

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

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

if opVersion == "" {
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 cVersion string
for idx := range clusterVersion.Status.History {
candidate := &clusterVersion.Status.History[idx]
if candidate.State == configv1.CompletedUpdate {
cVersion = candidate.Version
break
}
}

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

providerClient, err := providerclient.NewProviderClient(
ctx,
storageClient.Spec.StorageProviderEndpoint,
Expand All @@ -87,8 +132,10 @@ func main() {
}
defer providerClient.Close()

if _, err = providerClient.ReportStatus(ctx, storageClient.Status.ConsumerID); err != nil {
klog.Exitf("Failed to update lastHeartbeat of storageClient %v: %v", storageClient.Status.ConsumerID, err)
if _, err = providerClient.ReportStatus(ctx, storageClient.Status.ConsumerID,
status.AddClusterVersion(cVersion),
status.AddOperatorVersion(opVersion)); err != nil {
klog.Exitf("Failed to report status of storageClient %v: %v", storageClient.Status.ConsumerID, err)
}

var csiClusterConfigEntry = new(csi.ClusterConfigEntry)
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/blang/semver/v4/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions vendor/github.com/blang/semver/v4/json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 328d3b4

Please sign in to comment.