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(scheduling): add zfs pool capacity tracking #335

Merged
merged 7 commits into from May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions buildscripts/generate-manifests.sh
Expand Up @@ -92,6 +92,20 @@ echo '
cat deploy/yamls/zfs.openebs.io_zfsrestores.yaml >> deploy/yamls/zfsrestore-crd.yaml
rm deploy/yamls/zfs.openebs.io_zfsrestores.yaml

echo '
##############################################
########### ############
########### ZFSNode CRD ############
########### ############
##############################################

# ZFSNode CRD is autogenerated via `make manifests` command.
# Do the modification in the code and run the `make manifests` command
# to generate the CRD definition' > deploy/yamls/zfsnode-crd.yaml

cat deploy/yamls/zfs.openebs.io_zfsnodes.yaml >> deploy/yamls/zfsnode-crd.yaml
rm deploy/yamls/zfs.openebs.io_zfsnodes.yaml

## create the operator file using all the yamls

echo '# This manifest is autogenerated via `make manifests` command
Expand All @@ -117,6 +131,9 @@ cat deploy/yamls/zfsbackup-crd.yaml >> deploy/zfs-operator.yaml
# Add ZFSRestore v1 CRDs to the Operator yaml
cat deploy/yamls/zfsrestore-crd.yaml >> deploy/zfs-operator.yaml

# Add ZFSNode v1alpha1 CRDs to the Operator yaml
cat deploy/yamls/zfsnode-crd.yaml >> deploy/zfs-operator.yaml

# Add the driver deployment to the Operator yaml
cat deploy/yamls/zfs-driver.yaml >> deploy/zfs-operator.yaml

Expand Down
7 changes: 5 additions & 2 deletions deploy/yamls/zfs-driver.yaml
Expand Up @@ -677,6 +677,9 @@ rules:
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses", "csinodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [ "storage.k8s.io" ]
resources: [ "csistoragecapacities"]
verbs: ["*"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
Expand All @@ -690,7 +693,7 @@ rules:
resources: ["pods"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: ["*"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores", "zfsnodes"]
verbs: ["*"]
---

Expand Down Expand Up @@ -897,7 +900,7 @@ rules:
resources: ["persistentvolumes", "nodes", "services"]
verbs: ["get", "list"]
- apiGroups: ["*"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores", "zfsnodes"]
verbs: ["get", "list", "watch", "create", "update", "patch"]

---
Expand Down
87 changes: 87 additions & 0 deletions deploy/yamls/zfsnode-crd.yaml
@@ -0,0 +1,87 @@

##############################################
########### ############
########### ZFSNode CRD ############
########### ############
##############################################

# ZFSNode CRD is autogenerated via `make manifests` command.
# Do the modification in the code and run the `make manifests` command
# to generate the CRD definition

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
creationTimestamp: null
name: zfsnodes.zfs.openebs.io
spec:
group: zfs.openebs.io
names:
kind: ZFSNode
listKind: ZFSNodeList
plural: zfsnodes
shortNames:
- zfsnode
singular: zfsnode
scope: Namespaced
versions:
- name: v1
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
schema:
openAPIV3Schema:
description: ZFSNode records information about all zfs pools available in
a node. In general, the openebs node-agent creates the ZFSNode object &
periodically synchronizing the zfs pools available in the node. ZFSNode
has an owner reference pointing to the corresponding node object.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
pools:
items:
description: Pool specifies attributes of a given zfs pool exists on
node.
properties:
free:
anyOf:
- type: integer
- type: string
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
name:
description: Name of the zfs zfs pool.
minLength: 1
type: string
uuid:
description: UUID denotes a unique identity of a zfs pool.
minLength: 1
type: string
required:
- free
- name
- uuid
type: object
type: array
required:
- pools
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
94 changes: 92 additions & 2 deletions deploy/zfs-operator.yaml
Expand Up @@ -1206,6 +1206,93 @@ status:
conditions: []
storedVersions: []

##############################################
########### ############
########### ZFSNode CRD ############
########### ############
##############################################

# ZFSNode CRD is autogenerated via `make manifests` command.
# Do the modification in the code and run the `make manifests` command
# to generate the CRD definition

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
creationTimestamp: null
name: zfsnodes.zfs.openebs.io
spec:
group: zfs.openebs.io
names:
kind: ZFSNode
listKind: ZFSNodeList
plural: zfsnodes
shortNames:
- zfsnode
singular: zfsnode
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: ZFSNode records information about all zfs pools available in
a node. In general, the openebs node-agent creates the ZFSNode object &
periodically synchronizing the zfs pools available in the node. ZFSNode
has an owner reference pointing to the corresponding node object.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
pools:
items:
description: Pool specifies attributes of a given zfs pool exists on
node.
properties:
free:
anyOf:
- type: integer
- type: string
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
name:
description: Name of the zfs zfs pool.
minLength: 1
type: string
uuid:
description: UUID denotes a unique identity of a zfs pool.
minLength: 1
type: string
required:
- free
- name
- uuid
type: object
type: array
required:
- pools
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

---

# Create the CSI Driver object
Expand Down Expand Up @@ -1884,6 +1971,9 @@ rules:
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses", "csinodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [ "storage.k8s.io" ]
resources: [ "csistoragecapacities"]
verbs: ["*"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
Expand All @@ -1897,7 +1987,7 @@ rules:
resources: ["pods"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: ["*"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores", "zfsnodes"]
verbs: ["*"]
---

Expand Down Expand Up @@ -2104,7 +2194,7 @@ rules:
resources: ["persistentvolumes", "nodes", "services"]
verbs: ["get", "list"]
- apiGroups: ["*"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores"]
resources: ["zfsvolumes", "zfssnapshots", "zfsbackups", "zfsrestores", "zfsnodes"]
verbs: ["get", "list", "watch", "create", "update", "patch"]

---
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/register.go
Expand Up @@ -77,6 +77,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&ZFSBackupList{},
&ZFSRestore{},
&ZFSRestoreList{},
&ZFSNode{},
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
&ZFSNodeList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
66 changes: 66 additions & 0 deletions pkg/apis/openebs.io/zfs/v1/zfsnode.go
@@ -0,0 +1,66 @@
/*
Copyright 2021 The OpenEBS Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfsnode

// ZFSNode records information about all zfs pools available
// in a node. In general, the openebs node-agent creates the ZFSNode
// object & periodically synchronizing the zfs pools available in the node.
// ZFSNode has an owner reference pointing to the corresponding node object.
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced,shortName=zfsnode
type ZFSNode struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Pools []Pool `json:"pools"`
}

// Pool specifies attributes of a given zfs pool exists on node.
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
type Pool struct {
// Name of the zfs zfs pool.
shubham14bajpai marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`

// UUID denotes a unique identity of a zfs pool.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
UUID string `json:"uuid"`

// Free specifies the available capacity of zfs pool.
// +kubebuilder:validation:Required
Free resource.Quantity `json:"free"`
}

// ZFSNodeList is a collection of ZFSNode resources
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=zfsnodes
type ZFSNodeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []ZFSNode `json:"items"`
}