diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 017d149f4..5aac1b8cc 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -201,6 +201,14 @@ type CephStatus struct { LastChecked string `json:"lastChecked,omitempty"` LastChanged string `json:"lastChanged,omitempty"` PreviousHealth string `json:"previousHealth,omitempty"` + Capacity Capacity `json:"capacity,omitempty"` +} + +type Capacity struct { + TotalBytes uint64 `json:"bytesTotal,omitempty"` + UsedBytes uint64 `json:"bytesUsed,omitempty"` + AvailableBytes uint64 `json:"bytesAvailable,omitempty"` + LastUpdated string `json:"lastUpdated,omitempty"` } type CephStorage struct { diff --git a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go index b18757df4..c75e0f3d3 100644 --- a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go +++ b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go @@ -64,6 +64,22 @@ func (in *BucketStatus) DeepCopy() *BucketStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Capacity) DeepCopyInto(out *Capacity) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Capacity. +func (in *Capacity) DeepCopy() *Capacity { + if in == nil { + return nil + } + out := new(Capacity) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CephBlockPool) DeepCopyInto(out *CephBlockPool) { *out = *in @@ -861,6 +877,7 @@ func (in *CephStatus) DeepCopyInto(out *CephStatus) { (*out)[key] = val } } + out.Capacity = in.Capacity return } diff --git a/pkg/operator/ceph/cluster/cephstatus.go b/pkg/operator/ceph/cluster/cephstatus.go index 0a2316a83..0e8647985 100644 --- a/pkg/operator/ceph/cluster/cephstatus.go +++ b/pkg/operator/ceph/cluster/cephstatus.go @@ -163,6 +163,14 @@ func toCustomResourceStatus(currentStatus cephv1.ClusterStatus, newStatus *cephc Message: message.Summary.Message, } } + + if newStatus.PgMap.TotalBytes != 0 { + s.Capacity.TotalBytes = newStatus.PgMap.TotalBytes + s.Capacity.UsedBytes = newStatus.PgMap.UsedBytes + s.Capacity.AvailableBytes = newStatus.PgMap.AvailableBytes + s.Capacity.LastUpdated = formatTime(time.Now().UTC()) + } + if currentStatus.CephStatus != nil { s.PreviousHealth = currentStatus.CephStatus.PreviousHealth s.LastChanged = currentStatus.CephStatus.LastChanged @@ -170,6 +178,9 @@ func toCustomResourceStatus(currentStatus cephv1.ClusterStatus, newStatus *cephc s.PreviousHealth = currentStatus.CephStatus.Health s.LastChanged = s.LastChecked } + if newStatus.PgMap.TotalBytes == 0 { + s.Capacity = currentStatus.CephStatus.Capacity + } } return s } diff --git a/pkg/operator/ceph/cluster/cephstatus_test.go b/pkg/operator/ceph/cluster/cephstatus_test.go index ff3d72873..57c9dd110 100644 --- a/pkg/operator/ceph/cluster/cephstatus_test.go +++ b/pkg/operator/ceph/cluster/cephstatus_test.go @@ -91,6 +91,33 @@ func TestCephStatus(t *testing.T) { assert.Equal(t, osdDownMsg.Severity, aggregateStatus.Details["OSD_DOWN"].Severity) assert.Equal(t, pgAvailMsg.Summary.Message, aggregateStatus.Details["PG_AVAILABILITY"].Message) assert.Equal(t, pgAvailMsg.Severity, aggregateStatus.Details["PG_AVAILABILITY"].Severity) + + // Test for storage capacity of the ceph cluster when there is no disk + newStatus = &cephclient.CephStatus{ + PgMap: cephclient.PgMap{TotalBytes: 0}, + } + aggregateStatus = toCustomResourceStatus(currentStatus, newStatus) + assert.Equal(t, 0, int(aggregateStatus.Capacity.TotalBytes)) + assert.Equal(t, "", aggregateStatus.Capacity.LastUpdated) + + // Test for storage capacity of the ceph cluster when the disk of size 1024 bytes attached + newStatus = &cephclient.CephStatus{ + PgMap: cephclient.PgMap{TotalBytes: 1024}, + } + aggregateStatus = toCustomResourceStatus(currentStatus, newStatus) + assert.Equal(t, 1024, int(aggregateStatus.Capacity.TotalBytes)) + assert.Equal(t, formatTime(time.Now().UTC()), aggregateStatus.Capacity.LastUpdated) + + // Test for storage capacity of the ceph cluster when initially there is a disk of size + // 1024 bytes attached and then the disk is removed or newStatus.PgMap.TotalBytes is 0. + currentStatus.CephStatus.Capacity.TotalBytes = 1024 + newStatus = &cephclient.CephStatus{ + PgMap: cephclient.PgMap{TotalBytes: 0}, + } + + aggregateStatus = toCustomResourceStatus(currentStatus, newStatus) + assert.Equal(t, 1024, int(aggregateStatus.Capacity.TotalBytes)) + assert.Equal(t, formatTime(time.Now().Add(-time.Minute).UTC()), formatTime(time.Now().Add(-time.Minute).UTC())) } func TestNewCephStatusChecker(t *testing.T) {