Skip to content

Commit

Permalink
chore(lvm): add support to configure auto lvm thin pool expansion cap…
Browse files Browse the repository at this point in the history
…ability to e2e agent

Signed-off-by: rohan2794 <[email protected]>
  • Loading branch information
rohan2794 committed Sep 23, 2024
1 parent fc172d5 commit f3394e9
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 2 deletions.
24 changes: 24 additions & 0 deletions common/e2e_agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,3 +1095,27 @@ func RemoveHostPathDisk(serverAddr string, diskPath string, mountPoint string) e
logf.Log.Info("RemoveHostPathDisk succeeded", "output", out)
return err
}

// LvmLvChangeMonitor monitor lvm lv
func LvmLvChangeMonitor(serverAddr string, vgName string) (string, error) {
data := Lvm{
Vg: vgName,
}
logf.Log.Info("Executing lvchange", "addr", serverAddr, "data", data)
url := "http://" + getAgentAddress(serverAddr) + "/lvmlvchangemonitor"
encodedresult, err := sendRequestGetResponse("POST", url, data, false)
if err != nil {
logf.Log.Info("sendRequestGetResponse", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
out, e2eagenterrcode, err := UnwrapResult(encodedresult)
if err != nil {
logf.Log.Info("unwrap failed", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
if e2eagenterrcode != ErrNone {
return out, fmt.Errorf("failed to monitor lvm lv, errcode %d", e2eagenterrcode)
}
logf.Log.Info("LvmLvChangeMonitor succeeded", "output", out)
return out, err
}
55 changes: 55 additions & 0 deletions common/lvm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,58 @@ func SetupLvmNodes(vgName string, size int64) (LvmNodesDevicePvVgConfig, error)
err = lvmNodeConfig.ConfigureLvmNodesWithDeviceAndVg()
return lvmNodeConfig, err
}

// EnableLvmThinPoolAutoExpansion enable auto extending of the Thin Pool (Configure Over-Provisioning protection)
func EnableLvmThinPoolAutoExpansion(vgName string, thinPoolAutoExtendThreshold, thinPoolAutoExtendPercent int) error {

workerNodes, err := ListLvmNode(common.NSOpenEBS())
if err != nil {
return fmt.Errorf("failed to list lvm worker nodes, error: %v", err)
}
if len(workerNodes) == 0 {
return fmt.Errorf("lvm worker nodes not found")
}
/*
1. Since we automatically create thin pool as part of first thin volume provisioning,
we need to enable the monitoring using lvchange command on the all thin pools across
the nodes to use the auto extend threshold feature.
monitor lvm lv thin pool
lvchange --monitor y lvmvg/lvmvg_thinpool
2. Editing the settings in the /etc/lvm/lvm.conf can allow auto growth of the thin pool when required.
By default, the threshold is 100% which means that the pool will not grow.
If we set this to, 75%, the Thin Pool will autoextend when the pool is 75% full.
It will increase by the default percentage of 20% if the value is not changed.
We can see these settings using the command grep against the file.
$ grep -E ‘^\s*thin_pool_auto’ /etc/lvm/lvm.conf
thin_pool_autoextend_threshold = 100
thin_pool_autoextend_percent = 20
*/

for _, node := range workerNodes {
nodeIp, err := k8stest.GetNodeIPAddress(node)
if err != nil {
return fmt.Errorf("failed to get node %s IP, error: %v", node, err)
}
out, err := e2e_agent.LvmLvChangeMonitor(*nodeIp, vgName)
if err != nil {
return fmt.Errorf("failed to set up lv monitor for vg %s on node %s,output: %s error: %v",
vgName, node, out, err)
}

out, err = e2e_agent.LvmThinPoolAutoExtendThreshold(*nodeIp, thinPoolAutoExtendThreshold)
if err != nil {
return fmt.Errorf("failed to set up thin_pool_autoextend_threshold value %d on node %s,output: %s error: %v",
thinPoolAutoExtendThreshold, node, out, err)
}

out, err = e2e_agent.LvmThinPoolAutoExtendPercent(*nodeIp, thinPoolAutoExtendPercent)
if err != nil {
return fmt.Errorf("failed to set up thin_pool_autoextend_percent value %d on node %s,output: %s error: %v",
thinPoolAutoExtendPercent, node, out, err)
}

}

return nil
}
2 changes: 1 addition & 1 deletion tools/e2e-agent/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# as long as we do not make breaking changes.
set -e
IMAGE="openebs/e2e-agent"
TAG="v3.0.3"
TAG="v3.0.4"
registry=""
tag_as_latest=""

Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-agent/e2e-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spec:
securityContext:
privileged: true
allowPrivilegeEscalation: true
image: openebs/e2e-agent:v3.0.3
image: openebs/e2e-agent:v3.0.4
imagePullPolicy: Always
volumeMounts:
- name: host-root
Expand Down
31 changes: 31 additions & 0 deletions tools/e2e-agent/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,34 @@ func LvmThinPoolAutoExtendPercent(w http.ResponseWriter, r *http.Request) {
}
WrapResult(output, ErrNone, w)
}

// LvmLvChangeMonitor monitor lvm lv
func LvmLvChangeMonitor(w http.ResponseWriter, r *http.Request) {
var msg string
var lvm Lvm
d := json.NewDecoder(r.Body)
if err := d.Decode(&lvm); err != nil {
msg = fmt.Sprintf("failed to read JSON encoded data, Error: %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrJsonDecode, w)
return
}

if lvm.Vg == "" {
msg = "no vg name passed"
klog.Error(msg)
WrapResult(msg, UnprocessableEntityErrorCode, w)
return
}
klog.Info("monitor lvm lv, data: %v", lvm)

lvmLvMonitorCommand := fmt.Sprintf("lvchange --monitor y %s/%s_thinpool", lvm.Vg, lvm.Vg)
output, err := bashLocal(lvmLvMonitorCommand)
if err != nil {
msg = fmt.Sprintf("cannot monitor lvm lv, Error %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrExecFailed, w)
return
}
WrapResult(output, ErrNone, w)
}
1 change: 1 addition & 0 deletions tools/e2e-agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func handleRequests() {
router.HandleFunc("/lvmremovevg", LvmRemoveVg).Methods("POST")
router.HandleFunc("/lvmthinpoolautoextendthreshold", LvmThinPoolAutoExtendThreshold).Methods("POST")
router.HandleFunc("/lvmthinpoolautoextendpercent", LvmThinPoolAutoExtendPercent).Methods("POST")
router.HandleFunc("/lvmlvchangemonitor", LvmLvChangeMonitor).Methods("POST")
//loop device
router.HandleFunc("/createloopdevice", CreateLoopDevice).Methods("POST")
router.HandleFunc("/deleteloopdevice", DeleteLoopDevice).Methods("POST")
Expand Down

0 comments on commit f3394e9

Please sign in to comment.