diff --git a/Makefile b/Makefile index e44c59378..e324245b3 100644 --- a/Makefile +++ b/Makefile @@ -134,6 +134,10 @@ informer: --output-package $(SRC_PKG)/generated/informer \ --go-header-file ./buildscripts/custom-boilerplate.go.txt +manifests: + @echo "+ Generating zfs localPV crds" + $(PWD)/buildscripts/update-crd.sh + .PHONY: zfs-driver zfs-driver: format @echo "--------------------------------" diff --git a/buildscripts/update-crd.sh b/buildscripts/update-crd.sh new file mode 100755 index 000000000..18e15bac8 --- /dev/null +++ b/buildscripts/update-crd.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright 2019 The Kubernetes 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. + +#set -o errexit +set -o nounset +set -o pipefail + +## find or download controller-gen +CONTROLLER_GEN=$(which controller-gen) + +if [ "$CONTROLLER_GEN" = "" ] +then + TMP_DIR=$(mktemp -d); + cd $TMP_DIR; + go mod init tmp; + go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.8; + rm -rf $TMP_DIR; + CONTROLLER_GEN=$(which controller-gen) +fi + +if [ "$CONTROLLER_GEN" = "" ] +then + echo "ERROR: failed to get controller-gen"; + exit 1; +fi + +SCRIPT_ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) + +$CONTROLLER_GEN crd:trivialVersions=true,preserveUnknownFields=false paths=${SCRIPT_ROOT}/pkg/apis/openebs.io/zfs/v1alpha1 output:crd:artifacts:config=deploy/crds + +# To use your own boilerplate text use: +# --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt diff --git a/deploy/crds/zfs.openebs.io_zfssnapshots.yaml b/deploy/crds/zfs.openebs.io_zfssnapshots.yaml new file mode 100644 index 000000000..9db8e2ee8 --- /dev/null +++ b/deploy/crds/zfs.openebs.io_zfssnapshots.yaml @@ -0,0 +1,153 @@ + +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.2.8 + creationTimestamp: null + name: zfssnapshots.zfs.openebs.io +spec: + group: zfs.openebs.io + names: + kind: ZFSSnapshot + listKind: ZFSSnapshotList + plural: zfssnapshots + shortNames: + - zfssnap + singular: zfssnapshot + preserveUnknownFields: false + scope: Namespaced + validation: + openAPIV3Schema: + description: ZFSSnapshot represents a ZFS Snapshot of the zfsvolume + 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/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/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: VolumeInfo contains the volume related info for all types of + volumes in ZFSVolume + properties: + capacity: + description: Capacity of the volume + minLength: 1 + type: string + compression: + description: Controls the compression algorithm used for this dataset. + Compression specifies if the it should enabled on the zvol. Setting + compression to on indicates that the current default compression algorithm + should be used. The current default compression algorithm is either + lzjb or, if the lz4_compress feature is enabled, lz4. Changing this + property affects only newly-written data. + pattern: ^(on|off|lzjb|gzip|gzip-[1-9]|zle|lz4)$ + type: string + dedup: + description: Deduplication is the process for removing redundant data + at the block level, reducing the total amount of data stored. If a + file system has the dedup property enabled, duplicate data blocks + are removed synchronously. The result is that only unique data is + stored and common components are shared among files. Deduplication + can consume significant processing power (CPU) and memory as well + as generate additional disk IO. Before creating a pool with deduplication + enabled, ensure that you have planned your hardware requirements appropriately + and implemented appropriate recovery practices, such as regular backups. + As an alternative to deduplication consider using compression=lz4, + as a less resource-intensive alternative. should be enabled on the + zvol + enum: + - "on" + - "off" + type: string + encryption: + description: Enabling the encryption feature allows for the creation + of encrypted filesystems and volumes. ZFS will encrypt file and zvol + data, file attributes, ACLs, permission bits, directory listings, + FUID mappings, and userused / groupused data. ZFS will not encrypt + metadata related to the pool structure, including dataset and snapshot + names, dataset hierarchy, properties, file size, file holes, and deduplication + tables (though the deduplicated data itself is encrypted). + pattern: ^(on|off|aes-128-[c,g]cm|aes-192-[c,g]cm|aes-256-[c,g]cm)$ + type: string + fsType: + description: FsType specifies filesystem type for the zfs volume/dataset + type: string + keyformat: + description: KeyFormat specifies format of the encryption key + type: string + keylocation: + description: KeyLocation is the location of key for the encryption + type: string + ownerNodeID: + minLength: 1 + type: string + poolName: + description: poolName specifies the name of the pool where this volume + should be created + minLength: 1 + type: string + recordsize: + description: RecordSize specifies the record size for the zfs dataset + minLength: 1 + type: string + snapname: + description: SnapName specifies the name of the snapshot where this + volume should be cloned + type: string + thinProvision: + description: Thinprovision specifies if we should thin provisioned the + volume or not + enum: + - "Yes" + - "no" + type: string + volblocksize: + description: VolBlockSize specifies the block size for the zvol + minLength: 1 + type: string + volumeType: + description: volumeType determines whether the volume is of type "DATASET" + or "ZVOL". if fsttype provided in the storageclass as "zfs", then + it will create a volume of type "DATASET". If "ext4", "ext3", "ext2" + or "xfs" in mentioned as fstype in the storageclass, it will create + a volume of type "ZVOL" so that it can be further formatted with the + fstype provided in the storageclass. + enum: + - ZVOL + - DATASET + type: string + required: + - capacity + - ownerNodeID + - poolName + - volumeType + type: object + status: + properties: + state: + type: string + type: object + required: + - spec + - status + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/deploy/crds/zfs.openebs.io_zfsvolumes.yaml b/deploy/crds/zfs.openebs.io_zfsvolumes.yaml new file mode 100644 index 000000000..a84a70879 --- /dev/null +++ b/deploy/crds/zfs.openebs.io_zfsvolumes.yaml @@ -0,0 +1,180 @@ + +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.2.8 + creationTimestamp: null + name: zfsvolumes.zfs.openebs.io +spec: + additionalPrinterColumns: + - JSONPath: .spec.poolName + description: ZFS Pool where the volume is created + name: ZPool + type: string + - JSONPath: .spec.ownerNodeID + description: Node where the volume is created + name: Node + type: string + - JSONPath: .spec.capacity + description: Size of the volume + name: Size + type: string + - JSONPath: .spec.volblocksize + description: volblocksize of volume + name: volblocksize + type: string + - JSONPath: .spec.recordsize + description: recordsize of created zfs dataset + name: recordsize + type: string + - JSONPath: .spec.fsType + description: filesystem created on the volume + name: Filesystem + type: string + - JSONPath: .status.creationTime + description: Timestamp when the volume has been created. + name: CreationTime + type: date + - JSONPath: .metadata.creationTimestamp + name: Age + type: date + group: zfs.openebs.io + names: + kind: ZFSVolume + listKind: ZFSVolumeList + plural: zfsvolumes + shortNames: + - zfsvol + singular: zfsvolume + preserveUnknownFields: false + scope: Namespaced + subresources: {} + validation: + openAPIV3Schema: + description: ZFSVolume represents a ZFS based volume + 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/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/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: VolumeInfo contains the volume related info for all types of + volumes in ZFSVolume + properties: + capacity: + description: Capacity of the volume + minLength: 1 + type: string + compression: + description: Controls the compression algorithm used for this dataset. + Compression specifies if the it should enabled on the zvol. Setting + compression to on indicates that the current default compression algorithm + should be used. The current default compression algorithm is either + lzjb or, if the lz4_compress feature is enabled, lz4. Changing this + property affects only newly-written data. + pattern: ^(on|off|lzjb|gzip|gzip-[1-9]|zle|lz4)$ + type: string + dedup: + description: Deduplication is the process for removing redundant data + at the block level, reducing the total amount of data stored. If a + file system has the dedup property enabled, duplicate data blocks + are removed synchronously. The result is that only unique data is + stored and common components are shared among files. Deduplication + can consume significant processing power (CPU) and memory as well + as generate additional disk IO. Before creating a pool with deduplication + enabled, ensure that you have planned your hardware requirements appropriately + and implemented appropriate recovery practices, such as regular backups. + As an alternative to deduplication consider using compression=lz4, + as a less resource-intensive alternative. should be enabled on the + zvol + enum: + - "on" + - "off" + type: string + encryption: + description: Enabling the encryption feature allows for the creation + of encrypted filesystems and volumes. ZFS will encrypt file and zvol + data, file attributes, ACLs, permission bits, directory listings, + FUID mappings, and userused / groupused data. ZFS will not encrypt + metadata related to the pool structure, including dataset and snapshot + names, dataset hierarchy, properties, file size, file holes, and deduplication + tables (though the deduplicated data itself is encrypted). + pattern: ^(on|off|aes-128-[c,g]cm|aes-192-[c,g]cm|aes-256-[c,g]cm)$ + type: string + fsType: + description: FsType specifies filesystem type for the zfs volume/dataset + type: string + keyformat: + description: KeyFormat specifies format of the encryption key + type: string + keylocation: + description: KeyLocation is the location of key for the encryption + type: string + ownerNodeID: + minLength: 1 + type: string + poolName: + description: poolName specifies the name of the pool where this volume + should be created + minLength: 1 + type: string + recordsize: + description: RecordSize specifies the record size for the zfs dataset + minLength: 1 + type: string + snapname: + description: SnapName specifies the name of the snapshot where this + volume should be cloned + type: string + thinProvision: + description: Thinprovision specifies if we should thin provisioned the + volume or not + enum: + - "Yes" + - "no" + type: string + volblocksize: + description: VolBlockSize specifies the block size for the zvol + minLength: 1 + type: string + volumeType: + description: volumeType determines whether the volume is of type "DATASET" + or "ZVOL". if fsttype provided in the storageclass as "zfs", then + it will create a volume of type "DATASET". If "ext4", "ext3", "ext2" + or "xfs" in mentioned as fstype in the storageclass, it will create + a volume of type "ZVOL" so that it can be further formatted with the + fstype provided in the storageclass. + enum: + - ZVOL + - DATASET + type: string + required: + - capacity + - ownerNodeID + - poolName + - volumeType + type: object + required: + - spec + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/pkg/apis/openebs.io/zfs/v1alpha1/doc.go b/pkg/apis/openebs.io/zfs/v1alpha1/doc.go index c182efa32..20e8c9054 100644 --- a/pkg/apis/openebs.io/zfs/v1alpha1/doc.go +++ b/pkg/apis/openebs.io/zfs/v1alpha1/doc.go @@ -17,5 +17,5 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // Package v1alpha1 is the API version -// +groupName=openebs.io +// +groupName=zfs.openebs.io package v1alpha1 diff --git a/pkg/apis/openebs.io/zfs/v1alpha1/zfssnapshot.go b/pkg/apis/openebs.io/zfs/v1alpha1/zfssnapshot.go index 6393e737c..5e69738f9 100644 --- a/pkg/apis/openebs.io/zfs/v1alpha1/zfssnapshot.go +++ b/pkg/apis/openebs.io/zfs/v1alpha1/zfssnapshot.go @@ -25,6 +25,8 @@ import ( // +resource:path=zfssnapshot // ZFSSnapshot represents a ZFS Snapshot of the zfsvolume +// +kubebuilder:object:root=true +// +kubebuilder:resource:scope=Namespaced,shortName=zfssnap type ZFSSnapshot struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go b/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go index 4c66c44cd..f6c250983 100644 --- a/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go +++ b/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go @@ -25,6 +25,16 @@ import ( // +resource:path=zfsvolume // ZFSVolume represents a ZFS based volume +// +kubebuilder:object:root=true +// +kubebuilder:resource:scope=Namespaced,shortName=zfsvol +// +kubebuilder:printcolumn:name="ZPool",type=string,JSONPath=`.spec.poolName`,description="ZFS Pool where the volume is created" +// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=`.spec.ownerNodeID`,description="Node where the volume is created" +// +kubebuilder:printcolumn:name="Size",type=string,JSONPath=`.spec.capacity`,description="Size of the volume" +// +kubebuilder:printcolumn:name="volblocksize",type=string,JSONPath=`.spec.volblocksize`,description="volblocksize of volume" +// +kubebuilder:printcolumn:name="recordsize",type=string,JSONPath=`.spec.recordsize`,description="recordsize of created zfs dataset" +// +kubebuilder:printcolumn:name="Filesystem",type=string,JSONPath=`.spec.fsType`,description="filesystem created on the volume" +// +kubebuilder:printcolumn:name="CreationTime",type=date,JSONPath=`.status.creationTime`,description="Timestamp when the volume has been created." +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` type ZFSVolume struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -71,12 +81,18 @@ type ZFSVolumeList struct { // VolumeInfo contains the volume related info // for all types of volumes in ZFSVolume type VolumeInfo struct { + // OwnerNodeID is the Node ID which // is the owner of this Volume + + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:Required OwnerNodeID string `json:"ownerNodeID"` // poolName specifies the name of the // pool where this volume should be created + // +kubebuilder:validation:Required + // +kubebuilder:validation:MinLength=1 PoolName string `json:"poolName"` // SnapName specifies the name of the @@ -84,41 +100,67 @@ type VolumeInfo struct { SnapName string `json:"snapname,omitempty"` // Capacity of the volume + // +kubebuilder:validation:MinLength=1 Capacity string `json:"capacity"` // RecordSize specifies the record size // for the zfs dataset + // +kubebuilder:validation:MinLength=1 RecordSize string `json:"recordsize,omitempty"` // VolBlockSize specifies the block size for the zvol + // +kubebuilder:validation:MinLength=1 VolBlockSize string `json:"volblocksize,omitempty"` - // Compression specifies if the it should - // enabled on the zvol + // Controls the compression algorithm used for this dataset. Compression + // specifies if the it should enabled on the zvol. Setting compression to on + // indicates that the current default compression algorithm should be used. + // The current default compression algorithm is either lzjb or, if the lz4_compress + // feature is enabled, lz4. + // Changing this property affects only newly-written data. + // +kubebuilder:validation:Pattern="^(on|off|lzjb|gzip|gzip-[1-9]|zle|lz4)$" Compression string `json:"compression,omitempty"` - // Dedup specifies the deduplication + // Deduplication is the process for removing redundant data at the block level, + // reducing the total amount of data stored. If a file system has the dedup property + // enabled, duplicate data blocks are removed synchronously. + // The result is that only unique data is stored and common components are shared among files. + // Deduplication can consume significant processing power (CPU) and memory as well as generate additional disk IO. + // Before creating a pool with deduplication enabled, ensure that you have planned your hardware + // requirements appropriately and implemented appropriate recovery practices, such as regular backups. + // As an alternative to deduplication consider using compression=lz4, as a less resource-intensive alternative. // should be enabled on the zvol + // +kubebuilder:validation:Enum=on;off Dedup string `json:"dedup,omitempty"` - // Encryption specifies the encryption - // should be enabled on the zvol + // Enabling the encryption feature allows for the creation of + // encrypted filesystems and volumes. ZFS will encrypt file and zvol data, + // file attributes, ACLs, permission bits, directory listings, FUID mappings, + // and userused / groupused data. ZFS will not encrypt metadata related to the + // pool structure, including dataset and snapshot names, dataset hierarchy, + // properties, file size, file holes, and deduplication tables + // (though the deduplicated data itself is encrypted). + // +kubebuilder:validation:Pattern="^(on|off|aes-128-[c,g]cm|aes-192-[c,g]cm|aes-256-[c,g]cm)$" Encryption string `json:"encryption,omitempty"` - // KeyLocation is the location of key - // for the encryption + // KeyLocation is the location of key for the encryption KeyLocation string `json:"keylocation,omitempty"` - // KeyFormat specifies format of the - // encryption key + // KeyFormat specifies format of the encryption key KeyFormat string `json:"keyformat,omitempty"` // Thinprovision specifies if we should // thin provisioned the volume or not + // +kubebuilder:validation:Enum=Yes;no ThinProvision string `json:"thinProvision,omitempty"` - // VolumeType specifies whether the volume is - // zvol or a dataset + // volumeType determines whether the volume is of type "DATASET" or "ZVOL". + // if fsttype provided in the storageclass as "zfs", then it will create a + // volume of type "DATASET". If "ext4", "ext3", "ext2" or "xfs" in mentioned as fstype + // in the storageclass, it will create a volume of type "ZVOL" so that it can be + // further formatted with the fstype provided in the storageclass. + // +kubebuilder:validation:Required + // +kubebuilder:validation:Enum=ZVOL;DATASET VolumeType string `json:"volumeType"` // FsType specifies filesystem type for the