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

Signed-off-by: Hrudaya <[email protected]>
  • Loading branch information
hrudaya21 committed Nov 16, 2023
1 parent f3acaa5 commit 1da2612
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand All @@ -70,6 +77,7 @@ spec:
type: string
required:
- free
- used
- name
- uuid
type: object
Expand Down
8 changes: 8 additions & 0 deletions deploy/zfs-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1277,6 +1284,7 @@ spec:
type: string
required:
- free
- used
- name
- uuid
type: object
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/zfsnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 1da2612

Please sign in to comment.