From cde722bdfb8fdca1ea9e901d9abb336a60ab7691 Mon Sep 17 00:00:00 2001 From: Leela Venkaiah G Date: Wed, 25 Oct 2023 09:54:26 +0530 Subject: [PATCH] store client information on storageconsumer status - adds new fields to existing RPC message - these fields are updated in status of corresponding storageconsumer CRs - the status will be helpful for exporting new metrics Signed-off-by: Leela Venkaiah G --- api/v1alpha1/storageconsumer_types.go | 10 ++ api/v1alpha1/zz_generated.deepcopy.go | 16 ++ .../ocs.openshift.io_storageconsumers.yaml | 10 ++ .../ocs.openshift.io_storageconsumers.yaml | 10 ++ .../manifests/storageconsumer.crd.yaml | 10 ++ services/provider/client/client.go | 8 +- services/provider/consumerstatus/status.go | 21 +++ services/provider/pb/provider.pb.go | 139 ++++++++++-------- services/provider/proto/provider.proto | 2 + services/provider/server/consumer.go | 30 +++- services/provider/server/consumer_test.go | 42 +++++- services/provider/server/server.go | 23 ++- services/provider/server/server_test.go | 13 +- 13 files changed, 250 insertions(+), 84 deletions(-) create mode 100644 services/provider/consumerstatus/status.go diff --git a/api/v1alpha1/storageconsumer_types.go b/api/v1alpha1/storageconsumer_types.go index f0ae411b95..341d162b0e 100644 --- a/api/v1alpha1/storageconsumer_types.go +++ b/api/v1alpha1/storageconsumer_types.go @@ -54,6 +54,14 @@ type CephResourcesSpec struct { CephClients map[string]string `json:"cephClients,omitempty"` } +// ClientInfo is the information pushed from connected storage client +type ClientInfo struct { + // StorageClient Cluster Version + ClusterVersion string `json:"clusterVersion,omitempty"` + // StorageClient Operator Version + OperatorVersion string `json:"operatorVersion,omitempty"` +} + // StorageConsumerStatus defines the observed state of StorageConsumer type StorageConsumerStatus struct { // State describes the state of StorageConsumer @@ -62,6 +70,8 @@ type StorageConsumerStatus struct { CephResources []*CephResourcesSpec `json:"cephResources,omitempty"` // Timestamp of last heartbeat received from consumer LastHeartbeat metav1.Time `json:"lastHeartbeat,omitempty"` + // Information of storage client received from consumer + Info ClientInfo `json:"info,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 7614dbbfe4..9ea027ad05 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -47,6 +47,21 @@ func (in *CephResourcesSpec) DeepCopy() *CephResourcesSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClientInfo) DeepCopyInto(out *ClientInfo) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClientInfo. +func (in *ClientInfo) DeepCopy() *ClientInfo { + if in == nil { + return nil + } + out := new(ClientInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StorageClassRequest) DeepCopyInto(out *StorageClassRequest) { *out = *in @@ -236,6 +251,7 @@ func (in *StorageConsumerStatus) DeepCopyInto(out *StorageConsumerStatus) { } } in.LastHeartbeat.DeepCopyInto(&out.LastHeartbeat) + out.Info = in.Info } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageConsumerStatus. diff --git a/config/crd/bases/ocs.openshift.io_storageconsumers.yaml b/config/crd/bases/ocs.openshift.io_storageconsumers.yaml index b53da54942..821968197a 100644 --- a/config/crd/bases/ocs.openshift.io_storageconsumers.yaml +++ b/config/crd/bases/ocs.openshift.io_storageconsumers.yaml @@ -66,6 +66,16 @@ spec: type: string type: object type: array + info: + description: Information of storage client received from consumer + properties: + clusterVersion: + description: StorageClient Cluster Version + type: string + operatorVersion: + description: StorageClient Operator Version + type: string + type: object lastHeartbeat: description: Timestamp of last heartbeat received from consumer format: date-time diff --git a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageconsumers.yaml b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageconsumers.yaml index b53da54942..821968197a 100644 --- a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageconsumers.yaml +++ b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageconsumers.yaml @@ -66,6 +66,16 @@ spec: type: string type: object type: array + info: + description: Information of storage client received from consumer + properties: + clusterVersion: + description: StorageClient Cluster Version + type: string + operatorVersion: + description: StorageClient Operator Version + type: string + type: object lastHeartbeat: description: Timestamp of last heartbeat received from consumer format: date-time diff --git a/deploy/ocs-operator/manifests/storageconsumer.crd.yaml b/deploy/ocs-operator/manifests/storageconsumer.crd.yaml index d30f49b5d1..6b5afc2504 100644 --- a/deploy/ocs-operator/manifests/storageconsumer.crd.yaml +++ b/deploy/ocs-operator/manifests/storageconsumer.crd.yaml @@ -65,6 +65,16 @@ spec: type: string type: object type: array + info: + description: Information of storage client received from consumer + properties: + clusterVersion: + description: StorageClient Cluster Version + type: string + operatorVersion: + description: StorageClient Operator Version + type: string + type: object lastHeartbeat: description: Timestamp of last heartbeat received from consumer format: date-time diff --git a/services/provider/client/client.go b/services/provider/client/client.go index bbfd8db0bf..4083bf97de 100644 --- a/services/provider/client/client.go +++ b/services/provider/client/client.go @@ -6,6 +6,7 @@ import ( "fmt" "time" + consumerstatus "github.com/red-hat-storage/ocs-operator/v4/services/provider/consumerstatus" pb "github.com/red-hat-storage/ocs-operator/v4/services/provider/pb" "google.golang.org/grpc" @@ -188,12 +189,15 @@ func (cc *OCSProviderClient) GetStorageClassClaimConfig(ctx context.Context, con return cc.Client.GetStorageClassClaimConfig(apiCtx, req) } -func (cc *OCSProviderClient) ReportStatus(ctx context.Context, consumerUUID string) (*pb.ReportStatusResponse, error) { +func (cc *OCSProviderClient) ReportStatus(ctx context.Context, consumerUUID string, status consumerstatus.Status) (*pb.ReportStatusResponse, error) { if cc.Client == nil || cc.clientConn == nil { return nil, fmt.Errorf("Provider client is closed") } + req := &pb.ReportStatusRequest{ - StorageConsumerUUID: consumerUUID, + StorageConsumerUUID: consumerUUID, + ClientClusterVersion: status.GetClusterVersion(), + ClientOperatorVersion: status.GetOperatorVersion(), } apiCtx, cancel := context.WithTimeout(ctx, cc.timeout) defer cancel() diff --git a/services/provider/consumerstatus/status.go b/services/provider/consumerstatus/status.go new file mode 100644 index 0000000000..4f0fe71de9 --- /dev/null +++ b/services/provider/consumerstatus/status.go @@ -0,0 +1,21 @@ +package consumerstatus + +type StatusResponse interface { + GetClusterVersion() string + GetOperatorVersion() string +} + +type Status struct { + ClusterVersion string + OperatorVersion string +} + +var _ StatusResponse = &Status{} + +func (s *Status) GetClusterVersion() string { + return s.ClusterVersion +} + +func (s *Status) GetOperatorVersion() string { + return s.OperatorVersion +} diff --git a/services/provider/pb/provider.pb.go b/services/provider/pb/provider.pb.go index 4816a535fa..4e373a8bce 100644 --- a/services/provider/pb/provider.pb.go +++ b/services/provider/pb/provider.pb.go @@ -852,7 +852,9 @@ type ReportStatusRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - StorageConsumerUUID string `protobuf:"bytes,1,opt,name=storageConsumerUUID,proto3" json:"storageConsumerUUID,omitempty"` + StorageConsumerUUID string `protobuf:"bytes,1,opt,name=storageConsumerUUID,proto3" json:"storageConsumerUUID,omitempty"` + ClientClusterVersion string `protobuf:"bytes,2,opt,name=clientClusterVersion,proto3" json:"clientClusterVersion,omitempty"` + ClientOperatorVersion string `protobuf:"bytes,3,opt,name=clientOperatorVersion,proto3" json:"clientOperatorVersion,omitempty"` } func (x *ReportStatusRequest) Reset() { @@ -894,6 +896,20 @@ func (x *ReportStatusRequest) GetStorageConsumerUUID() string { return "" } +func (x *ReportStatusRequest) GetClientClusterVersion() string { + if x != nil { + return x.ClientClusterVersion + } + return "" +} + +func (x *ReportStatusRequest) GetClientOperatorVersion() string { + if x != nil { + return x.ClientOperatorVersion + } + return "" +} + type ReportStatusResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1031,65 +1047,72 @@ var file_provider_proto_rawDesc = []byte{ 0x0b, 0x32, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x10, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, - 0x47, 0x0a, 0x13, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x30, 0x0a, 0x13, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x55, 0x55, 0x49, 0x44, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x13, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x73, - 0x75, 0x6d, 0x65, 0x72, 0x55, 0x55, 0x49, 0x44, 0x22, 0x16, 0x0a, 0x14, 0x52, 0x65, 0x70, 0x6f, - 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x32, 0xb4, 0x06, 0x0a, 0x0b, 0x4f, 0x43, 0x53, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x12, 0x58, 0x0a, 0x0f, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, - 0x6d, 0x65, 0x72, 0x12, 0x20, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x4f, - 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x2e, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x55, 0x0a, 0x10, 0x47, 0x65, - 0x74, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1e, - 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, - 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x5b, 0x0a, 0x10, 0x4f, 0x66, 0x66, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, - 0x73, 0x75, 0x6d, 0x65, 0x72, 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x2e, 0x4f, 0x66, 0x66, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, - 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, - 0x64, 0x65, 0x72, 0x2e, 0x4f, 0x66, 0x66, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, - 0x75, 0x6d, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6a, - 0x0a, 0x15, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x4f, 0x6e, 0x62, - 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x26, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, - 0x65, 0x72, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x4f, 0x6e, - 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x27, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, - 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x73, 0x0a, 0x18, 0x46, 0x75, - 0x6c, 0x66, 0x69, 0x6c, 0x6c, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, - 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x29, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, - 0x72, 0x2e, 0x46, 0x75, 0x6c, 0x66, 0x69, 0x6c, 0x6c, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, - 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x2a, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x46, 0x75, 0x6c, + 0xb1, 0x01, 0x0a, 0x13, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x30, 0x0a, 0x13, 0x73, 0x74, 0x6f, 0x72, 0x61, + 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x55, 0x55, 0x49, 0x44, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x13, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, + 0x73, 0x75, 0x6d, 0x65, 0x72, 0x55, 0x55, 0x49, 0x44, 0x12, 0x32, 0x0a, 0x14, 0x63, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x34, 0x0a, + 0x15, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x56, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x63, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x56, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x22, 0x16, 0x0a, 0x14, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xb4, 0x06, 0x0a, 0x0b, + 0x4f, 0x43, 0x53, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x58, 0x0a, 0x0f, 0x4f, + 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x12, 0x20, + 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x4f, 0x6e, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x55, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, + 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x76, + 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x76, + 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5b, 0x0a, 0x10, + 0x4f, 0x66, 0x66, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, + 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x4f, 0x66, 0x66, 0x62, + 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x4f, + 0x66, 0x66, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6a, 0x0a, 0x15, 0x41, 0x63, 0x6b, + 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, + 0x6e, 0x67, 0x12, 0x26, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x41, 0x63, + 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x70, 0x72, 0x6f, + 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x41, 0x63, 0x6b, 0x6e, 0x6f, 0x77, 0x6c, 0x65, 0x64, 0x67, + 0x65, 0x4f, 0x6e, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x73, 0x0a, 0x18, 0x46, 0x75, 0x6c, 0x66, 0x69, 0x6c, 0x6c, + 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, + 0x6d, 0x12, 0x29, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x46, 0x75, 0x6c, 0x66, 0x69, 0x6c, 0x6c, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, - 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x70, 0x0a, 0x17, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, - 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x28, 0x2e, 0x70, 0x72, 0x6f, - 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x53, 0x74, 0x6f, 0x72, - 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x71, + 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x70, + 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x46, 0x75, 0x6c, 0x66, 0x69, 0x6c, 0x6c, 0x53, + 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x70, 0x0a, 0x17, 0x52, 0x65, + 0x76, 0x6f, 0x6b, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, + 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x28, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, + 0x2e, 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, + 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x29, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x76, 0x6f, 0x6b, + 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, + 0x69, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x73, 0x0a, 0x1a, + 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, + 0x6c, 0x61, 0x69, 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x28, 0x2e, 0x70, 0x72, 0x6f, + 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, + 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, - 0x52, 0x65, 0x76, 0x6f, 0x6b, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, - 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0x00, 0x12, 0x73, 0x0a, 0x1a, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, - 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, - 0x28, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, - 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x72, 0x6f, 0x76, - 0x69, 0x64, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, - 0x73, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, - 0x72, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, - 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x3b, 0x70, 0x72, - 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x43, 0x6c, 0x61, 0x69, + 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x4f, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x70, + 0x6f, 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x70, 0x6f, + 0x72, 0x74, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, + 0x72, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/services/provider/proto/provider.proto b/services/provider/proto/provider.proto index dc76790d5e..95add10749 100644 --- a/services/provider/proto/provider.proto +++ b/services/provider/proto/provider.proto @@ -155,6 +155,8 @@ message StorageClassClaimConfigResponse{ message ReportStatusRequest{ string storageConsumerUUID = 1; + string clientClusterVersion = 2; + string clientOperatorVersion = 3; } message ReportStatusResponse{} diff --git a/services/provider/server/consumer.go b/services/provider/server/consumer.go index 0d6fca2b91..1cf89e03c6 100644 --- a/services/provider/server/consumer.go +++ b/services/provider/server/consumer.go @@ -8,6 +8,7 @@ import ( "sync" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1" + "github.com/red-hat-storage/ocs-operator/v4/services/provider/consumerstatus" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -199,7 +200,7 @@ func (c *ocsConsumerManager) Get(ctx context.Context, id string) (*ocsv1alpha1.S return consumerObj, nil } -func (c *ocsConsumerManager) UpdateStatusLastHeatbeat(ctx context.Context, id string) error { +func (c *ocsConsumerManager) UpdateConsumerStatus(ctx context.Context, id string, status consumerstatus.StatusResponse) error { uid := types.UID(id) c.mutex.RLock() @@ -211,24 +212,37 @@ func (c *ocsConsumerManager) UpdateStatusLastHeatbeat(ctx context.Context, id st } c.mutex.RUnlock() - patchInfo := struct { + patchInfo := []struct { Op string `json:"op"` Path string `json:"path"` Value interface{} `json:"value"` }{ - Op: "replace", - Path: "/status/lastHeartbeat", - Value: metav1.Now(), + { + Op: "replace", + Path: "/status/lastHeartbeat", + Value: metav1.Now(), + }, + { + Op: "replace", + Path: "/status/info/clusterVersion", + Value: status.GetClusterVersion(), + }, + { + Op: "replace", + Path: "/status/info/operatorVersion", + Value: status.GetOperatorVersion(), + }, } - jsonPatchInfo, _ := json.Marshal([]interface{}{patchInfo}) + + jsonPatchInfo, _ := json.Marshal(patchInfo) patch := client.RawPatch(types.JSONPatchType, jsonPatchInfo) consumerObj := &ocsv1alpha1.StorageConsumer{} consumerObj.Name = consumerName consumerObj.Namespace = c.namespace if err := c.client.Status().Patch(ctx, consumerObj, patch); err != nil { - return fmt.Errorf("Failed to patch Status.LastHeartbeat for StorageConsumer %v: %v", consumerName, err) + return fmt.Errorf("Failed to patch Status for StorageConsumer %v: %v", consumerName, err) } - klog.Infof("successfully updated Status.LastHeartbeat for StorageConsumer %v", consumerName) + klog.Infof("successfully updated Status for StorageConsumer %v", consumerName) return nil } diff --git a/services/provider/server/consumer_test.go b/services/provider/server/consumer_test.go index 088d7acda7..bc2ab8d5ae 100644 --- a/services/provider/server/consumer_test.go +++ b/services/provider/server/consumer_test.go @@ -6,12 +6,12 @@ import ( api "github.com/red-hat-storage/ocs-operator/v4/api/v1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1" + "github.com/red-hat-storage/ocs-operator/v4/services/provider/consumerstatus" rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" ) @@ -47,7 +47,7 @@ var ( } ) -func newFakeClient(t *testing.T, obj ...runtime.Object) client.Client { +func newFakeClient(t *testing.T, obj ...client.Object) client.Client { scheme, err := api.SchemeBuilder.Build() assert.NoError(t, err, "unable to build scheme") @@ -60,12 +60,15 @@ func newFakeClient(t *testing.T, obj ...runtime.Object) client.Client { err = rookCephv1.AddToScheme(scheme) assert.NoError(t, err, "failed to add rookCephv1 scheme") - return fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(obj...).Build() + return fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(obj...). + WithStatusSubresource(obj...).Build() } func TestNewConsumerManager(t *testing.T) { ctx := context.TODO() - obj := []runtime.Object{} + obj := []client.Object{} // Test NewConsumerManager with no StorageConsumer resources client := newFakeClient(t) @@ -89,7 +92,7 @@ func TestNewConsumerManager(t *testing.T) { func TestCreateStorageConsumer(t *testing.T) { ctx := context.TODO() - obj := []runtime.Object{} + obj := []client.Object{} obj = append(obj, consumer1) client := newFakeClient(t, obj...) @@ -115,7 +118,7 @@ func TestCreateStorageConsumer(t *testing.T) { func TestDeleteStorageConsumer(t *testing.T) { ctx := context.TODO() - obj := []runtime.Object{} + obj := []client.Object{} obj = append(obj, consumer1) client := newFakeClient(t, obj...) @@ -142,7 +145,7 @@ func TestDeleteStorageConsumer(t *testing.T) { func TestGetStorageConsumer(t *testing.T) { ctx := context.TODO() - obj := []runtime.Object{} + obj := []client.Object{} obj = append(obj, consumer1) client := newFakeClient(t, obj...) @@ -158,3 +161,28 @@ func TestGetStorageConsumer(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "consumer1", consumer.Name) } + +func TestUpdateConsumerStatus(t *testing.T) { + ctx := context.TODO() + obj := []client.Object{} + + obj = append(obj, consumer1) + client := newFakeClient(t, obj...) + consumerManager, err := newConsumerManager(ctx, client, + testNamespace) + assert.NoError(t, err) + + // with fields + fields := consumerstatus.Status{ + ClusterVersion: "1.0.0", + OperatorVersion: "1.0.0", + } + err = consumerManager.UpdateConsumerStatus(ctx, "uid1", &fields) + assert.NoError(t, err) + + c1, err := consumerManager.Get(ctx, "uid1") + assert.NoError(t, err) + assert.NotEmpty(t, c1.Status.LastHeartbeat) + assert.Equal(t, fields.ClusterVersion, c1.Status.Info.ClusterVersion) + assert.Equal(t, fields.OperatorVersion, c1.Status.Info.OperatorVersion) +} diff --git a/services/provider/server/server.go b/services/provider/server/server.go index 261825a1fc..ae4c639e13 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -19,6 +19,7 @@ import ( "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/v4/api/v1alpha1" controllers "github.com/red-hat-storage/ocs-operator/v4/controllers/storageconsumer" + "github.com/red-hat-storage/ocs-operator/v4/services/provider/consumerstatus" pb "github.com/red-hat-storage/ocs-operator/v4/services/provider/pb" rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" @@ -650,14 +651,30 @@ func (s *OCSProviderServer) GetStorageClassClaimConfig(ctx context.Context, req } +type ConsumerStatus struct { + *pb.ReportStatusRequest +} + +var _ consumerstatus.StatusResponse = &ConsumerStatus{} + +func (c *ConsumerStatus) GetClusterVersion() string { + return c.ClientClusterVersion +} + +func (c *ConsumerStatus) GetOperatorVersion() string { + return c.ClientOperatorVersion +} + // ReportStatus rpc call to check if a consumer can reach to the provider. func (s *OCSProviderServer) ReportStatus(ctx context.Context, req *pb.ReportStatusRequest) (*pb.ReportStatusResponse, error) { // Update the status in storageConsumer CR - if err := s.consumerManager.UpdateStatusLastHeatbeat(ctx, req.StorageConsumerUUID); err != nil { + + consStatus := &ConsumerStatus{req} + if err := s.consumerManager.UpdateConsumerStatus(ctx, req.StorageConsumerUUID, consStatus); err != nil { if kerrors.IsNotFound(err) { - return nil, status.Errorf(codes.NotFound, "Failed to update lastHeartbeat in the storageConsumer resource: %v", err) + return nil, status.Errorf(codes.NotFound, "Failed to update lastHeartbeat payload in the storageConsumer resource: %v", err) } - return nil, status.Errorf(codes.Internal, "Failed to update lastHeartbeat in the storageConsumer resource: %v", err) + return nil, status.Errorf(codes.Internal, "Failed to update lastHeartbeat payload in the storageConsumer resource: %v", err) } return &pb.ReportStatusResponse{}, nil diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index a263032a0c..3fcc80d17b 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -17,6 +17,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + crClient "sigs.k8s.io/controller-runtime/pkg/client" ) type externalResource struct { @@ -138,7 +139,7 @@ var ( func TestGetExternalResources(t *testing.T) { ctx := context.TODO() - objects := []runtime.Object{ + objects := []crClient.Object{ consumerResource, consumerResource1, consumerResource2, @@ -278,7 +279,7 @@ func TestGetExternalResources(t *testing.T) { assert.Nil(t, storageConRes) // When CephClient status is empty - objects = []runtime.Object{ + objects = []crClient.Object{ &rookCephv1.CephClient{}, } s := runtime.NewScheme() @@ -303,7 +304,7 @@ func TestGetExternalResources(t *testing.T) { // When CephClient status info is empty - objects = []runtime.Object{ + objects = []crClient.Object{ &rookCephv1.CephClient{}, } s = runtime.NewScheme() @@ -389,7 +390,7 @@ func TestOCSProviderServerStorageClassRequest(t *testing.T) { } ctx := context.TODO() - objects := []runtime.Object{ + objects := []crClient.Object{ consumerResource, claimResourceUnderDeletion, } @@ -455,7 +456,7 @@ func TestOCSProviderServerRevokeStorageClassClaim(t *testing.T) { } ctx := context.TODO() - objects := []runtime.Object{ + objects := []crClient.Object{ consumerResource, claimResource, } @@ -673,7 +674,7 @@ func TestOCSProviderServerGetStorageClassClaimConfig(t *testing.T) { ) ctx := context.TODO() - objects := []runtime.Object{ + objects := []crClient.Object{ consumerResource, blockPoolClaimResource, sharedFilesystemClaimResource,