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 27, 2024
1 parent fc172d5 commit aa92d56
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 29 deletions.
50 changes: 49 additions & 1 deletion common/e2e_agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Lvm struct {
Pv string `json:"pv"` // Physical volume
Vg string `json:"vg"` // Volume group
ThinPoolAutoExtendThreshold int `json:"thinPoolAutoExtendThreshold"` // thin pool auto extend threshold
ThinPoolAutoExtendPercent int `json:"ThinPoolAutoExtendPercent"` // thin pool auto extend percent
ThinPoolAutoExtendPercent int `json:"thinPoolAutoExtendPercent"` // thin pool auto extend percent
}

type LoopDevice struct {
Expand Down Expand Up @@ -1095,3 +1095,51 @@ 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
}

// LvmLvRemoveThinPool delete lvm thin pool lv
func LvmLvRemoveThinPool(serverAddr string, vgName string) (string, error) {
data := Lvm{
Vg: vgName,
}
logf.Log.Info("Executing lvchange", "addr", serverAddr, "data", data)
url := "http://" + getAgentAddress(serverAddr) + "/lvmlvremovethinpool"
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 remove lvm thin pool lv, errcode %d", e2eagenterrcode)
}
logf.Log.Info("LvmLvRemoveThinPool succeeded", "output", out)
return out, err
}
44 changes: 44 additions & 0 deletions common/lvm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,47 @@ 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(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")
}
/*
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.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
}
38 changes: 38 additions & 0 deletions scripts/k8s/deployer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SCRIPT_DIR="$(dirname "$0")"
TMP_KIND="/tmp/kind/openebs-e2e"
TMP_KIND_CONFIG="$TMP_KIND/config.yaml"
TMP_KIND_ZFS="$TMP_KIND/zfs"
TMP_KIND_LVM="$TMP_KIND/lvm"
TMP_KIND_ZFS="$TMP_KIND/zpool"
WORKERS=2
DELAY="false"
CORES=1
Expand Down Expand Up @@ -205,6 +207,42 @@ EOF
EOF
fi

if [ "$SETUP_ZFS" = "true" ]; then
# Should already be installed by prereq script
ZPOOL=$(realpath $(which zpool))
cat <<EOF >>$TMP_KIND_ZPOOL
#/bin/sh
chroot /host $ZPOOL "\$@"
EOF
chmod +x $TMP_KIND_ZPOOL
cat <<EOF >> "$TMP_KIND_CONFIG"
- hostPath: /
containerPath: /host
propagation: HostToContainer
- hostPath: $TMP_KIND_ZPOOL
containerPath: /sbin/zpool
propagation: HostToContainer
EOF
fi

if [ "$SETUP_LVM" = "true" ]; then
# Should already be installed by prereq script
LVM=$(realpath $(which lvm))
cat <<EOF >>$TMP_KIND_LVM
#/bin/sh
chroot /host $LVM "\$@"
EOF
chmod +x $TMP_KIND_LVM
cat <<EOF >> "$TMP_KIND_CONFIG"
- hostPath: /
containerPath: /host
propagation: HostToContainer
- hostPath: $TMP_KIND_LVM
containerPath: /sbin/lvm
propagation: HostToContainer
EOF
fi

if [ "$SETUP_MAYASTOR" = "true" ]; then
if [ "$LABEL" = "true" ]; then
cat <<EOF >> "$TMP_KIND_CONFIG"
Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY ./ /
# It ensures that devices are configured as soon as they are plugged in and discovered.
# It propagates information about a processed device.
RUN apt-get update; apt-get install net-tools iptables wget parted udev nvme-cli build-essential gettext gettext-base \
libinih-dev uuid-dev liburcu-dev libblkid-dev btrfs-progs lvm2 zfsutils-linux -y;
libinih-dev uuid-dev liburcu-dev libblkid-dev btrfs-progs -y;
RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz; \
tar -C /usr/local/ -xzf go${GO_VERSION}.linux-amd64.tar.gz; \
rm -rf go${GO_VERSION}.linux-amd64.tar.gz; \
Expand Down
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
35 changes: 33 additions & 2 deletions tools/e2e-agent/e2e-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ data:
else
chroot /host zfs "$@"
fi
ZPOOL: |
#!/bin/sh
if [ -x /host/sbin/zpool ]; then
chroot /host /sbin/zpool "$@"
elif [ -x /host/usr/sbin/zpool ]; then
chroot /host /usr/sbin/zpool "$@"
else
chroot /host zpool "$@"
fi
LVM: |
#!/bin/sh
if [ -x /host/sbin/lvm ]; then
chroot /host /sbin/lvm "$@"
elif [ -x /host/usr/sbin/lvm ]; then
chroot /host /usr/sbin/lvm "$@"
else
chroot /host lvm "$@"
fi
---
kind: DaemonSet
Expand Down Expand Up @@ -50,7 +68,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 All @@ -63,6 +81,12 @@ spec:
- mountPath: /sbin/zfs
name: chroot-zfs
subPath: ZFS
- mountPath: /sbin/lvm
name: chroot-lvm
subPath: LVM
- mountPath: /sbin/zpool
name: chroot-zpool
subPath: ZPOOL
volumes:
- name: host-root
hostPath:
Expand All @@ -80,6 +104,13 @@ spec:
configMap:
defaultMode: 0555
name: test-vars
- name: chroot-lvm
configMap:
defaultMode: 0555
name: test-vars
- name: chroot-zpool
configMap:
defaultMode: 0555
name: test-vars


---
13 changes: 7 additions & 6 deletions tools/e2e-agent/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ type E2eAgentErrcode int

const (
// general errors
ErrNone E2eAgentErrcode = 0
ErrGeneral E2eAgentErrcode = 1
ErrJsonDecode E2eAgentErrcode = 2
ErrJsonEncode E2eAgentErrcode = 3
ErrReadFail E2eAgentErrcode = 4
ErrExecFailed E2eAgentErrcode = 5
ErrNone E2eAgentErrcode = 0
ErrGeneral E2eAgentErrcode = 1
ErrJsonDecode E2eAgentErrcode = 2
ErrJsonEncode E2eAgentErrcode = 3
ErrReadFail E2eAgentErrcode = 4
ErrExecFailed E2eAgentErrcode = 5
ErrFileNotExist E2eAgentErrcode = 6

// event errors
ErrConnectFail E2eAgentErrcode = 101
Expand Down
Loading

0 comments on commit aa92d56

Please sign in to comment.