Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(usedcapcity): kubectl describe zfsnode should show the used capacity information #485

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading