Skip to content

Commit

Permalink
controllers: set storage utilization ratio in heartbeat
Browse files Browse the repository at this point in the history
Signed-off-by: rchikatw <[email protected]>
  • Loading branch information
rchikatw committed Oct 22, 2024
1 parent 7d67155 commit fe0a8a4
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 62 deletions.
2 changes: 1 addition & 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-20241015071140-98c8184c6eec
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.66.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
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-20241015071140-98c8184c6eec h1:M64BdwKMV3jKxcRsZiaGbRKsvlbhRGVZgcb4V/MFeWk=
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241015071140-98c8184c6eec/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 {
total, totalExists := clusterResourceQuota.Status.Total.Hard["requests.storage"]
used, usedExists := clusterResourceQuota.Status.Total.Used["requests.storage"]
if totalExists && usedExists && total.AsApproximateFloat64() > 0 {
ratio := used.AsApproximateFloat64() / total.AsApproximateFloat64()
status.SetStorageQuotaUtilizationRatio(math.Min(ratio, 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.

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

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ github.com/ramendr/ramen/api/v1alpha1
# github.com/red-hat-storage/ocs-client-operator/api v0.0.0-00010101000000-000000000000 => ./api
## explicit; go 1.22.5
github.com/red-hat-storage/ocs-client-operator/api/v1alpha1
# 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-20241015071140-98c8184c6eec
## explicit; go 1.22.5
github.com/red-hat-storage/ocs-operator/services/provider/api/v4
github.com/red-hat-storage/ocs-operator/services/provider/api/v4/client
Expand Down

0 comments on commit fe0a8a4

Please sign in to comment.