Skip to content

Commit

Permalink
feat(usedcapcity): kubectl describe zfsnode should show the used capa…
Browse files Browse the repository at this point in the history
…city information (#485)

Signed-off-by: Hrudaya <hrudayaranjan.sahoo@datacore.com>
  • Loading branch information
hrudaya21 authored Nov 29, 2023
1 parent 1c8cc41 commit 932f002
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions deploy/yamls/zfsnode-crd.yaml
Original file line number Diff line number Diff line change
@@ -60,6 +60,13 @@ spec:
description: Free specifies the available capacity of zfs pool.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
used:
anyOf:
- type: integer
- type: string
description: Used specifies the used capacity of zfs pool.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
description: Name of the zfs pool.
minLength: 1
@@ -70,6 +77,7 @@ spec:
type: string
required:
- free
- used
- name
- uuid
type: object
8 changes: 8 additions & 0 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
@@ -1267,6 +1267,13 @@ spec:
description: Free specifies the available capacity of zfs pool.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
used:
anyOf:
- type: integer
- type: string
description: Used specifies the used capacity of zfs pool.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
description: Name of the zfs pool.
minLength: 1
@@ -1277,6 +1284,7 @@ spec:
type: string
required:
- free
- used
- name
- uuid
type: object
4 changes: 4 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/zfsnode.go
Original file line number Diff line number Diff line change
@@ -53,6 +53,10 @@ type Pool struct {
// Free specifies the available capacity of zfs pool.
// +kubebuilder:validation:Required
Free resource.Quantity `json:"free"`

// Used specifies the used capacity of zfs pool.
// +kubebuilder:validation:Required
Used resource.Quantity `json:"used"`
}

// ZFSNodeList is a collection of ZFSNode resources
9 changes: 8 additions & 1 deletion pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
@@ -922,7 +922,7 @@ func CreateRestore(rstr *apis.ZFSRestore) error {
func ListZFSPool() ([]apis.Pool, error) {
args := []string{
ZFSListArg, "-d", "1", "-s", "name",
"-o", "name,guid,available",
"-o", "name,guid,available,used",
"-H", "-p",
}
cmd := exec.Command(ZFSVolCmd, args...)
@@ -956,6 +956,13 @@ func decodeListOutput(raw []byte) ([]apis.Pool, error) {
return pools, err
}
pool.Free = *resource.NewQuantity(sizeBytes, resource.BinarySI)
usedBytes, err := strconv.ParseInt(items[3],
10, 64)
if err != nil {
err = fmt.Errorf("cannot get free size for pool %v: %v", pool.Name, err)
return pools, err
}
pool.Used = *resource.NewQuantity(usedBytes, resource.BinarySI)
pools = append(pools, pool)
}
}

0 comments on commit 932f002

Please sign in to comment.