Skip to content

Commit

Permalink
This commit incorporates the review comments
Browse files Browse the repository at this point in the history
Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
mittachaitu committed Mar 19, 2020
1 parent 0a7d5d1 commit 9c5f16f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/openebs/api v0.0.0-20200316115502-9a4c0b1367c3
github.com/openebs/api v0.0.0-20200319173602-da787ed9fcbf
github.com/openebs/maya v0.0.0-20200226142318-6daf5f0486e8
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.5
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ github.com/openebs/api v0.0.0-20200311104100-f6a5bd72fae3 h1:30wuJe3AEcwYsq3w6t0
github.com/openebs/api v0.0.0-20200311104100-f6a5bd72fae3/go.mod h1:Mj6izkLZT0jNKLs9u1CnbgNoP9BEgY/mgVI7Mc3/Hwc=
github.com/openebs/api v0.0.0-20200316115502-9a4c0b1367c3 h1:/R2zYRJ0N9knT71TGXZHRJQIwj1RS/JWlQD8SB7vdnI=
github.com/openebs/api v0.0.0-20200316115502-9a4c0b1367c3/go.mod h1:Mj6izkLZT0jNKLs9u1CnbgNoP9BEgY/mgVI7Mc3/Hwc=
github.com/openebs/api v0.0.0-20200319152258-4190ca81ae69 h1:KRLrzRLf7oBnVSMDRCaSt0i+XwW7ucQ0sziey1CZAXw=
github.com/openebs/api v0.0.0-20200319152258-4190ca81ae69/go.mod h1:Mj6izkLZT0jNKLs9u1CnbgNoP9BEgY/mgVI7Mc3/Hwc=
github.com/openebs/api v0.0.0-20200319173602-da787ed9fcbf h1:QGAdLxow+WVfxTOxeli3RdzWp9SPRJl1GzNS/M8mOow=
github.com/openebs/api v0.0.0-20200319173602-da787ed9fcbf/go.mod h1:Mj6izkLZT0jNKLs9u1CnbgNoP9BEgY/mgVI7Mc3/Hwc=
github.com/openebs/maya v0.0.0-20200226142318-6daf5f0486e8 h1:ud86nr1TRU9fB3IeBzymBqYjaha/GjgjHCTeFTKeT8A=
github.com/openebs/maya v0.0.0-20200226142318-6daf5f0486e8/go.mod h1:QQY9cOHKQwZ73qbv6O//UYUBLNV2S0MRDIfG7t5KOCk=
github.com/openebs/maya v0.0.0-20200305100821-7118ad163bb4 h1:beXxZA3gQlP+r1mtNKfmdVjhs6NA5O3IXpNMoMoQXSY=
Expand Down
21 changes: 16 additions & 5 deletions pkg/controllers/cspi-controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ func (c *CStorPoolInstanceController) updateStatus(cspi *cstor.CStorPoolInstance
pool := zpool.PoolName()
propertyList := []string{"health", "io.openebs:readonly"}

// Since we quarried in following order health and io.openebs:readonly output also
// will be in same order
valueList, er := zpool.GetListOfPropertyValues(pool, propertyList)
if er != nil || len(valueList) != len(propertyList) {
return errors.Wrapf(err, "Failed to fetch %v output: %v", propertyList, valueList)
} else {
// valueList[0] will hold the value of health of cStor pool
// valueList[1] will hold the value of io.openebs:readonly of cStor pool
status.Phase = cstor.CStorPoolInstancePhase(valueList[0])
if valueList[1] == "on" {
status.ReadOnly = true
Expand Down Expand Up @@ -231,17 +235,23 @@ func (c *CStorPoolInstanceController) updateStatus(cspi *cstor.CStorPoolInstance
// 1. If pool used space reached to roThresholdLimit then pool will be set to readonly mode
// 2. If pool was in readonly mode if roThresholdLimit/pool expansion was happened then it
// unsets the ReadOnly Mode.
// NOTE: This function must be invoked after having the updated cspiStatus information
// NOTE: This function must be invoked after having the updated
// cspiStatus information from zfs/zpool
func (c *CStorPoolInstanceController) updateROMode(
cspiStatus *cstor.CStorPoolInstanceStatus, cspi cstor.CStorPoolInstance) {
roThresholdLimit := cspi.Spec.PoolConfig.ROThresholdLimit
if cspi.Spec.PoolConfig.ROThresholdLimit == nil {
return
}
roThresholdLimit := *cspi.Spec.PoolConfig.ROThresholdLimit
totalInBytes := cspiStatus.Capacity.Total.Value()
usedInBytes := cspiStatus.Capacity.Used.Value()
pool := zpool.PoolName()

usedPercentage := (usedInBytes * 100) / totalInBytes
if (int(usedPercentage) >= roThresholdLimit) &&
(roThresholdLimit != 0 && roThresholdLimit != 100) {
// If roThresholdLimit sets 100% and pool used storage reached to 100%
// then there might be chances that operations will hung so it is not
// recommended to perform operations
if (int(usedPercentage) >= roThresholdLimit) && roThresholdLimit != 100 {
if !cspiStatus.ReadOnly {
if err := zpool.SetPoolRDMode(pool, true); err != nil {
// Here, we are just logging in next reconciliation it will be retried
Expand All @@ -251,7 +261,8 @@ func (c *CStorPoolInstanceController) updateROMode(
c.recorder.Event(&cspi,
corev1.EventTypeWarning,
"PoolReadOnlyThreshold",
"Pool storage limit reached to thresholdLimit. Pool expansion is required to make it's volume replicas RW",
"Pool storage limit reached to read only threshold limit. "+
"Pool expansion is required to make its volume replicas RW",
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cspc/algorithm/build_csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
// GetCSPSpec returns a CSPI spec that should be created and claims all the
// block device present in the CSPI spec
func (ac *Config) GetCSPISpec() (*cstor.CStorPoolInstance, error) {
defaultROThresholdLimit := 85
poolSpec, nodeName, err := ac.SelectNode()
if err != nil {
return nil, errors.Wrapf(err, "failed to select a node")
Expand All @@ -58,8 +59,8 @@ func (ac *Config) GetCSPISpec() (*cstor.CStorPoolInstance, error) {
poolSpec.PoolConfig.PriorityClassName = ac.CSPC.Spec.DefaultPriorityClassName
}

if poolSpec.PoolConfig.ROThresholdLimit == 0 {
poolSpec.PoolConfig.ROThresholdLimit = 85
if poolSpec.PoolConfig.ROThresholdLimit == nil {
poolSpec.PoolConfig.ROThresholdLimit = &defaultROThresholdLimit
}

cspiLabels := ac.buildLabelsForCSPI(nodeName)
Expand Down
6 changes: 6 additions & 0 deletions pkg/pool/operations/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func GetPropertyValue(poolName, property string) (string, error) {
}

// GetListOfPropertyValues will return value list for given property list
// NOTE: It will return the property values in the same order as property list
func GetListOfPropertyValues(poolName string, propertyList []string) ([]string, error) {
ret, err := zfs.NewPoolGetProperty().
WithScriptedMode(true).
Expand Down Expand Up @@ -71,6 +72,11 @@ func GetCSPICapacity(poolName string) (cstor.CStorPoolInstanceCapacity, error) {
err,
)
}
// Since it was quarried in free, allocated and size output also
// will be in same order.
// valueList[0] contains value of free capacity in cStor pool
// valueList[1] contains value of allocated capacity in cStor pool
// valueList[2] contains total capacity of cStor pool
freeSizeInBinarySI := GetCapacityInBinarySi(valueList[0])
allocatedSizeInBinarySI := GetCapacityInBinarySi(valueList[1])
totalSizeInBinarySI := GetCapacityInBinarySi(valueList[2])
Expand Down

0 comments on commit 9c5f16f

Please sign in to comment.