Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: set storage utilization ratio in heartbeat #254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
categories: Storage
console.openshift.io/plugins: '["odf-client-console"]'
containerImage: quay.io/ocs-dev/ocs-client-operator:latest
createdAt: "2024-10-07T10:43:06Z"
createdAt: "2024-10-09T02:36:41Z"
description: OpenShift Data Foundation client operator enables consumption of
storage services from a remote centralized OpenShift Data Foundation provider
cluster.
Expand Down Expand Up @@ -728,6 +728,12 @@ spec:
verbs:
- get
- list
- apiGroups:
- quota.openshift.io
resources:
- clusterresourcequotas
verbs:
- get
serviceAccountName: ocs-client-operator-status-reporter
deployments:
- label:
Expand Down
6 changes: 6 additions & 0 deletions config/rbac/status-reporter-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ rules:
verbs:
- get
- list
- apiGroups:
- quota.openshift.io
resources:
- clusterresourcequotas
verbs:
- get
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.76.0
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237
github.com/red-hat-storage/ocs-client-operator/api v0.0.0-00010101000000-000000000000
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20240917115204-741b9d6f263d
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241008135149-64a355b0de3d
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.66.0
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -46,6 +46,7 @@ require (
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1 // indirect
github.com/onsi/ginkgo/v2 v2.20.1 // indirect
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87 // indirect
github.com/x448/float16 v0.8.4 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo=
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
Expand Down Expand Up @@ -325,8 +325,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237 h1:ig6ePD0yopC5Qi5BRmhsIsKaOkdsGXTSmG3HTYIpquo=
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237/go.mod h1:nO6VM/+PEhcPGyFIQJdhY6ip822cA61PAy/s6IjenAA=
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20240917115204-741b9d6f263d h1:RK/zCM6xRwyeJ06u6xSLEwl5Q1g/6EZRQmSgzbqleT0=
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20240917115204-741b9d6f263d/go.mod h1:t9GJk69TGXABBF8fFPB+ImpbA9mJyRS86wW6+Qn8xHo=
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241008135149-64a355b0de3d h1:enFjPzyfS9Qb3qhlCkxzEVxGqhwm08gOlpLuzXqLnoM=
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241008135149-64a355b0de3d/go.mod h1:t9GJk69TGXABBF8fFPB+ImpbA9mJyRS86wW6+Qn8xHo=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
Expand Down
27 changes: 27 additions & 0 deletions service/status-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"os"
"reflect"
"strings"
Expand All @@ -33,6 +34,7 @@ import (

csiopv1a1 "github.com/ceph/ceph-csi-operator/api/v1alpha1"
configv1 "github.com/openshift/api/config/v1"
quotav1 "github.com/openshift/api/quota/v1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
providerclient "github.com/red-hat-storage/ocs-operator/services/provider/api/v4/client"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -70,6 +72,10 @@ func main() {
klog.Exitf("Failed to add csiopv1a1 to scheme: %v", err)
}

if err := quotav1.AddToScheme(scheme); err != nil {
klog.Exitf("Failed to add quotav1 to scheme: %v", err)
}

config, err := config.GetConfig()
if err != nil {
klog.Exitf("Failed to get config: %v", err)
Expand Down Expand Up @@ -112,6 +118,7 @@ func main() {
setPlatformInformation(ctx, cl, status)
setOperatorInformation(ctx, cl, status, operatorNamespace)
setClusterInformation(ctx, cl, status)
setStorageQuotaUtilizationRatio(ctx, cl, status)
statusResponse, err := providerClient.ReportStatus(ctx, storageClient.Status.ConsumerID, status)
if err != nil {
klog.Exitf("Failed to report status of storageClient %v: %v", storageClient.Status.ConsumerID, err)
Expand Down Expand Up @@ -215,6 +222,26 @@ func setClusterInformation(ctx context.Context, cl client.Client, status interfa

}

func setStorageQuotaUtilizationRatio(ctx context.Context, cl client.Client, status interfaces.StorageClientStatus) {
clusterResourceQuota := &quotav1.ClusterResourceQuota{}
clusterResourceQuota.Name = status.GetClientName()

// No need to check for NotFound because unlimited quota client will not have CRQ resource
if err := cl.Get(ctx, client.ObjectKeyFromObject(clusterResourceQuota), clusterResourceQuota); client.IgnoreNotFound(err) != nil {
klog.Warningf("Failed to get clusterResourceQuota %q: %v", clusterResourceQuota.Name, err)
}

if clusterResourceQuota.Status.Total.Hard != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure none of parts of .Status.Total.Hard is a pointer? If any is you will need a nil pointer check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have verified with multiple scenario.

total := clusterResourceQuota.Status.Total.Hard["requests.storage"]
if total.AsApproximateFloat64() > 0 {
used := clusterResourceQuota.Status.Total.Used["requests.storage"]
ratio := used.AsApproximateFloat64() / total.AsApproximateFloat64()
status.SetStorageQuotaUtilizationRatio(math.Min(float64(ratio), float64(1.0)))
}
}

}

func setOperatorInformation(ctx context.Context, cl client.Client, status interfaces.StorageClientStatus,
operatorNamespace string) {
var operatorVersion string
Expand Down

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

Loading
Loading