Merge pull request #6475 from subhamkrai/cluster-storage

ceph: export the storage capacity of the ceph cluster
This commit is contained in:
Sébastien Han authored and GitHub committed 2020-10-27 14:34:00 +01:00
commit 16d3895fbc
4 files changed
+63

No files matched your search

+8
View File
@@ -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 {
@@ -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
}
+11
View File
@@ -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
}
@@ -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) {