mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-11 22:10:11 +01:00
feat(zfspv): adding snapshot and clone support for ZFSPV (#39)
This commits support snapshot and clone commands via CSI driver. User can create snap and clone using the following steps.
Note:
- Snapshot is created via reconciliation CR
- Cloned volume will be on the same zpool where the snapshot is taken
- Cloned volume will have same properties as source volume.
-----------------------------------
Create a Snapshotclass
```
kind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1beta1
metadata:
name: zfspv-snapclass
annotations:
snapshot.storage.kubernetes.io/is-default-class: "true"
driver: zfs.csi.openebs.io
deletionPolicy: Delete
```
Once snapshotclass is created, we can use this class to create a Snapshot
```
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: zfspv-snap
spec:
volumeSnapshotClassName: zfspv-snapclass
source:
persistentVolumeClaimName: csi-zfspv
```
```
$ kubectl get volumesnapshot
NAME AGE
zfspv-snap 7m52s
```
```
$ kubectl get volumesnapshot -o yaml
apiVersion: v1
items:
- apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"snapshot.storage.k8s.io/v1beta1","kind":"VolumeSnapshot","metadata":{"annotations":{},"name":"zfspv-snap","namespace":"default"},"spec":{"source":{"persistentVolumeClaimName":"csi-zfspv"},"volumeSnapshotClassName":"zfspv-snapclass"}}
creationTimestamp: "2020-01-30T10:31:24Z"
finalizers:
- snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection
- snapshot.storage.kubernetes.io/volumesnapshot-bound-protection
generation: 1
name: zfspv-snap
namespace: default
resourceVersion: "30040"
selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/zfspv-snap
uid: 1a5cf166-c599-4f58-9f3c-f1148be47fca
spec:
source:
persistentVolumeClaimName: csi-zfspv
volumeSnapshotClassName: zfspv-snapclass
status:
boundVolumeSnapshotContentName: snapcontent-1a5cf166-c599-4f58-9f3c-f1148be47fca
creationTime: "2020-01-30T10:31:24Z"
readyToUse: true
restoreSize: "0"
kind: List
metadata:
resourceVersion: ""
selfLink: ""
```
Openebs resource for the created snapshot
```
$ kubectl get snap -n openebs -o yaml
apiVersion: v1
items:
- apiVersion: openebs.io/v1alpha1
kind: ZFSSnapshot
metadata:
creationTimestamp: "2020-01-30T10:31:24Z"
finalizers:
- zfs.openebs.io/finalizer
generation: 2
labels:
kubernetes.io/nodename: pawan-2
openebs.io/persistent-volume: pvc-18cab7c3-ec5e-4264-8507-e6f7df4c789a
name: snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca
namespace: openebs
resourceVersion: "30035"
selfLink: /apis/openebs.io/v1alpha1/namespaces/openebs/zfssnapshots/snapshot-1a5cf166-c599-4f58-9f3c-f1148be47fca
uid: e29d571c-42b5-4fb7-9110-e1cfc9b96641
spec:
capacity: "4294967296"
fsType: zfs
ownerNodeID: pawan-2
poolName: zfspv-pool
status: Ready
volumeType: DATASET
kind: List
metadata:
resourceVersion: ""
selfLink: ""
```
Create a clone volume
We can provide a datasource as snapshot name to create a clone volume
```yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: zfspv-clone
spec:
storageClassName: openebs-zfspv
dataSource:
name: zfspv-snap
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi
```
It will create a ZFS clone volume from the mentioned snapshot and create the PV on the same node where original volume is there.
Here, As resize is not supported yet, the clone PVC size should match the size of the snapshot.
Also, all the properties from the storageclass will not be considered for the clone case, it will take the properties from the snapshot and create the clone volume. One thing to note here is that, the storageclass in clone PVC should have the same poolname as that of the original volume as across the pool, clone is not supported.
Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
b0434bb537
commit
287606b78a
40 changed files with 2995 additions and 123 deletions
116
pkg/builder/snapbuilder/build.go
Normal file
116
pkg/builder/snapbuilder/build.go
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
Copyright 2020 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 snapbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
"github.com/openebs/zfs-localpv/pkg/common/errors"
|
||||
)
|
||||
|
||||
// Builder is the builder object for ZFSSnapshot
|
||||
type Builder struct {
|
||||
snap *ZFSSnapshot
|
||||
errs []error
|
||||
}
|
||||
|
||||
// NewBuilder returns new instance of Builder
|
||||
func NewBuilder() *Builder {
|
||||
return &Builder{
|
||||
snap: &ZFSSnapshot{
|
||||
Object: &apis.ZFSSnapshot{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// BuildFrom returns new instance of Builder
|
||||
// from the provided api instance
|
||||
func BuildFrom(snap *apis.ZFSSnapshot) *Builder {
|
||||
if snap == nil {
|
||||
b := NewBuilder()
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New("failed to build snap object: nil snap"),
|
||||
)
|
||||
return b
|
||||
}
|
||||
return &Builder{
|
||||
snap: &ZFSSnapshot{
|
||||
Object: snap,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// WithNamespace sets the namespace of ZFSSnapshot
|
||||
func (b *Builder) WithNamespace(namespace string) *Builder {
|
||||
if namespace == "" {
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi snap object: missing namespace",
|
||||
),
|
||||
)
|
||||
return b
|
||||
}
|
||||
b.snap.Object.Namespace = namespace
|
||||
return b
|
||||
}
|
||||
|
||||
// WithName sets the name of ZFSSnapshot
|
||||
func (b *Builder) WithName(name string) *Builder {
|
||||
if name == "" {
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi snap object: missing name",
|
||||
),
|
||||
)
|
||||
return b
|
||||
}
|
||||
b.snap.Object.Name = name
|
||||
return b
|
||||
}
|
||||
|
||||
// WithLabels merges existing labels if any
|
||||
// with the ones that are provided here
|
||||
func (b *Builder) WithLabels(labels map[string]string) *Builder {
|
||||
if len(labels) == 0 {
|
||||
return b
|
||||
}
|
||||
|
||||
if b.snap.Object.Labels == nil {
|
||||
b.snap.Object.Labels = map[string]string{}
|
||||
}
|
||||
|
||||
for key, value := range labels {
|
||||
b.snap.Object.Labels[key] = value
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *Builder) WithFinalizer(finalizer []string) *Builder {
|
||||
b.snap.Object.Finalizers = append(b.snap.Object.Finalizers, finalizer...)
|
||||
return b
|
||||
}
|
||||
|
||||
// Build returns ZFSSnapshot API object
|
||||
func (b *Builder) Build() (*apis.ZFSSnapshot, error) {
|
||||
if len(b.errs) > 0 {
|
||||
return nil, errors.Errorf("%+v", b.errs)
|
||||
}
|
||||
|
||||
return b.snap.Object, nil
|
||||
}
|
||||
72
pkg/builder/snapbuilder/buildlist.go
Normal file
72
pkg/builder/snapbuilder/buildlist.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Copyright 2020 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 snapbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
)
|
||||
|
||||
// ListBuilder enables building an instance of
|
||||
// ZFSSnapshotList
|
||||
type ListBuilder struct {
|
||||
list *apis.ZFSSnapshotList
|
||||
filters predicateList
|
||||
}
|
||||
|
||||
// NewListBuilder returns a new instance of ListBuilder
|
||||
func NewListBuilder() *ListBuilder {
|
||||
return &ListBuilder{
|
||||
list: &apis.ZFSSnapshotList{},
|
||||
}
|
||||
}
|
||||
|
||||
// ListBuilderFrom returns a new instance of
|
||||
// ListBuilder from API list instance
|
||||
func ListBuilderFrom(vols apis.ZFSSnapshotList) *ListBuilder {
|
||||
b := &ListBuilder{list: &apis.ZFSSnapshotList{}}
|
||||
if len(vols.Items) == 0 {
|
||||
return b
|
||||
}
|
||||
|
||||
b.list.Items = append(b.list.Items, vols.Items...)
|
||||
return b
|
||||
}
|
||||
|
||||
// List returns the list of pod
|
||||
// instances that was built by this
|
||||
// builder
|
||||
func (b *ListBuilder) List() *apis.ZFSSnapshotList {
|
||||
if b.filters == nil || len(b.filters) == 0 {
|
||||
return b.list
|
||||
}
|
||||
|
||||
filtered := &apis.ZFSSnapshotList{}
|
||||
for _, vol := range b.list.Items {
|
||||
vol := vol // pin it
|
||||
if b.filters.all(From(&vol)) {
|
||||
filtered.Items = append(filtered.Items, vol)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
// WithFilter add filters on which the pod
|
||||
// has to be filtered
|
||||
func (b *ListBuilder) WithFilter(pred ...Predicate) *ListBuilder {
|
||||
b.filters = append(b.filters, pred...)
|
||||
return b
|
||||
}
|
||||
427
pkg/builder/snapbuilder/kubernetes.go
Normal file
427
pkg/builder/snapbuilder/kubernetes.go
Normal file
|
|
@ -0,0 +1,427 @@
|
|||
// Copyright © 2020 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 snapbuilder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
client "github.com/openebs/zfs-localpv/pkg/common/kubernetes/client"
|
||||
clientset "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset"
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// getClientsetFn is a typed function that
|
||||
// abstracts fetching of internal clientset
|
||||
type getClientsetFn func() (clientset *clientset.Clientset, err error)
|
||||
|
||||
// getClientsetFromPathFn is a typed function that
|
||||
// abstracts fetching of clientset from kubeConfigPath
|
||||
type getClientsetForPathFn func(kubeConfigPath string) (
|
||||
clientset *clientset.Clientset,
|
||||
err error,
|
||||
)
|
||||
|
||||
// createFn is a typed function that abstracts
|
||||
// creating zfssnap volume instance
|
||||
type createFn func(
|
||||
cs *clientset.Clientset,
|
||||
upgradeResultObj *apis.ZFSSnapshot,
|
||||
namespace string,
|
||||
) (*apis.ZFSSnapshot, error)
|
||||
|
||||
// getFn is a typed function that abstracts
|
||||
// fetching a zfssnap volume instance
|
||||
type getFn func(
|
||||
cli *clientset.Clientset,
|
||||
name,
|
||||
namespace string,
|
||||
opts metav1.GetOptions,
|
||||
) (*apis.ZFSSnapshot, error)
|
||||
|
||||
// listFn is a typed function that abstracts
|
||||
// listing of zfssnap volume instances
|
||||
type listFn func(
|
||||
cli *clientset.Clientset,
|
||||
namespace string,
|
||||
opts metav1.ListOptions,
|
||||
) (*apis.ZFSSnapshotList, error)
|
||||
|
||||
// delFn is a typed function that abstracts
|
||||
// deleting a zfssnap volume instance
|
||||
type delFn func(
|
||||
cli *clientset.Clientset,
|
||||
name,
|
||||
namespace string,
|
||||
opts *metav1.DeleteOptions,
|
||||
) error
|
||||
|
||||
// updateFn is a typed function that abstracts
|
||||
// updating zfssnap volume instance
|
||||
type updateFn func(
|
||||
cs *clientset.Clientset,
|
||||
vol *apis.ZFSSnapshot,
|
||||
namespace string,
|
||||
) (*apis.ZFSSnapshot, error)
|
||||
|
||||
// Kubeclient enables kubernetes API operations
|
||||
// on zfssnap volume instance
|
||||
type Kubeclient struct {
|
||||
// clientset refers to zfssnap volume's
|
||||
// clientset that will be responsible to
|
||||
// make kubernetes API calls
|
||||
clientset *clientset.Clientset
|
||||
|
||||
kubeConfigPath string
|
||||
|
||||
// namespace holds the namespace on which
|
||||
// kubeclient has to operate
|
||||
namespace string
|
||||
|
||||
// functions useful during mocking
|
||||
getClientset getClientsetFn
|
||||
getClientsetForPath getClientsetForPathFn
|
||||
get getFn
|
||||
list listFn
|
||||
del delFn
|
||||
create createFn
|
||||
update updateFn
|
||||
}
|
||||
|
||||
// KubeclientBuildOption defines the abstraction
|
||||
// to build a kubeclient instance
|
||||
type KubeclientBuildOption func(*Kubeclient)
|
||||
|
||||
// defaultGetClientset is the default implementation to
|
||||
// get kubernetes clientset instance
|
||||
func defaultGetClientset() (clients *clientset.Clientset, err error) {
|
||||
|
||||
config, err := client.GetConfig(client.New())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return clientset.NewForConfig(config)
|
||||
|
||||
}
|
||||
|
||||
// defaultGetClientsetForPath is the default implementation to
|
||||
// get kubernetes clientset instance based on the given
|
||||
// kubeconfig path
|
||||
func defaultGetClientsetForPath(
|
||||
kubeConfigPath string,
|
||||
) (clients *clientset.Clientset, err error) {
|
||||
config, err := client.GetConfig(
|
||||
client.New(client.WithKubeConfigPath(kubeConfigPath)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return clientset.NewForConfig(config)
|
||||
}
|
||||
|
||||
// defaultGet is the default implementation to get
|
||||
// a zfssnap volume instance in kubernetes cluster
|
||||
func defaultGet(
|
||||
cli *clientset.Clientset,
|
||||
name, namespace string,
|
||||
opts metav1.GetOptions,
|
||||
) (*apis.ZFSSnapshot, error) {
|
||||
return cli.OpenebsV1alpha1().
|
||||
ZFSSnapshots(namespace).
|
||||
Get(name, opts)
|
||||
}
|
||||
|
||||
// defaultList is the default implementation to list
|
||||
// zfssnap volume instances in kubernetes cluster
|
||||
func defaultList(
|
||||
cli *clientset.Clientset,
|
||||
namespace string,
|
||||
opts metav1.ListOptions,
|
||||
) (*apis.ZFSSnapshotList, error) {
|
||||
return cli.OpenebsV1alpha1().
|
||||
ZFSSnapshots(namespace).
|
||||
List(opts)
|
||||
}
|
||||
|
||||
// defaultCreate is the default implementation to delete
|
||||
// a zfssnap volume instance in kubernetes cluster
|
||||
func defaultDel(
|
||||
cli *clientset.Clientset,
|
||||
name, namespace string,
|
||||
opts *metav1.DeleteOptions,
|
||||
) error {
|
||||
deletePropagation := metav1.DeletePropagationForeground
|
||||
opts.PropagationPolicy = &deletePropagation
|
||||
err := cli.OpenebsV1alpha1().
|
||||
ZFSSnapshots(namespace).
|
||||
Delete(name, opts)
|
||||
return err
|
||||
}
|
||||
|
||||
// defaultCreate is the default implementation to create
|
||||
// a zfssnap volume instance in kubernetes cluster
|
||||
func defaultCreate(
|
||||
cli *clientset.Clientset,
|
||||
vol *apis.ZFSSnapshot,
|
||||
namespace string,
|
||||
) (*apis.ZFSSnapshot, error) {
|
||||
return cli.OpenebsV1alpha1().
|
||||
ZFSSnapshots(namespace).
|
||||
Create(vol)
|
||||
}
|
||||
|
||||
// defaultUpdate is the default implementation to update
|
||||
// a zfssnap volume instance in kubernetes cluster
|
||||
func defaultUpdate(
|
||||
cli *clientset.Clientset,
|
||||
vol *apis.ZFSSnapshot,
|
||||
namespace string,
|
||||
) (*apis.ZFSSnapshot, error) {
|
||||
return cli.OpenebsV1alpha1().
|
||||
ZFSSnapshots(namespace).
|
||||
Update(vol)
|
||||
}
|
||||
|
||||
// withDefaults sets the default options
|
||||
// of kubeclient instance
|
||||
func (k *Kubeclient) withDefaults() {
|
||||
if k.getClientset == nil {
|
||||
k.getClientset = defaultGetClientset
|
||||
}
|
||||
if k.getClientsetForPath == nil {
|
||||
k.getClientsetForPath = defaultGetClientsetForPath
|
||||
}
|
||||
if k.get == nil {
|
||||
k.get = defaultGet
|
||||
}
|
||||
if k.list == nil {
|
||||
k.list = defaultList
|
||||
}
|
||||
if k.del == nil {
|
||||
k.del = defaultDel
|
||||
}
|
||||
if k.create == nil {
|
||||
k.create = defaultCreate
|
||||
}
|
||||
if k.update == nil {
|
||||
k.update = defaultUpdate
|
||||
}
|
||||
}
|
||||
|
||||
// WithClientSet sets the kubernetes client against
|
||||
// the kubeclient instance
|
||||
func WithClientSet(c *clientset.Clientset) KubeclientBuildOption {
|
||||
return func(k *Kubeclient) {
|
||||
k.clientset = c
|
||||
}
|
||||
}
|
||||
|
||||
// WithNamespace sets the kubernetes client against
|
||||
// the provided namespace
|
||||
func WithNamespace(namespace string) KubeclientBuildOption {
|
||||
return func(k *Kubeclient) {
|
||||
k.namespace = namespace
|
||||
}
|
||||
}
|
||||
|
||||
// WithNamespace sets the provided namespace
|
||||
// against this Kubeclient instance
|
||||
func (k *Kubeclient) WithNamespace(namespace string) *Kubeclient {
|
||||
k.namespace = namespace
|
||||
return k
|
||||
}
|
||||
|
||||
// WithKubeConfigPath sets the kubernetes client
|
||||
// against the provided path
|
||||
func WithKubeConfigPath(path string) KubeclientBuildOption {
|
||||
return func(k *Kubeclient) {
|
||||
k.kubeConfigPath = path
|
||||
}
|
||||
}
|
||||
|
||||
// NewKubeclient returns a new instance of
|
||||
// kubeclient meant for zfssnap volume operations
|
||||
func NewKubeclient(opts ...KubeclientBuildOption) *Kubeclient {
|
||||
k := &Kubeclient{}
|
||||
for _, o := range opts {
|
||||
o(k)
|
||||
}
|
||||
|
||||
k.withDefaults()
|
||||
return k
|
||||
}
|
||||
|
||||
func (k *Kubeclient) getClientsetForPathOrDirect() (
|
||||
*clientset.Clientset,
|
||||
error,
|
||||
) {
|
||||
if k.kubeConfigPath != "" {
|
||||
return k.getClientsetForPath(k.kubeConfigPath)
|
||||
}
|
||||
|
||||
return k.getClientset()
|
||||
}
|
||||
|
||||
// getClientOrCached returns either a new instance
|
||||
// of kubernetes client or its cached copy
|
||||
func (k *Kubeclient) getClientOrCached() (*clientset.Clientset, error) {
|
||||
if k.clientset != nil {
|
||||
return k.clientset, nil
|
||||
}
|
||||
|
||||
c, err := k.getClientsetForPathOrDirect()
|
||||
if err != nil {
|
||||
return nil,
|
||||
errors.Wrapf(
|
||||
err,
|
||||
"failed to get clientset",
|
||||
)
|
||||
}
|
||||
|
||||
k.clientset = c
|
||||
return k.clientset, nil
|
||||
}
|
||||
|
||||
// Create creates a zfssnap volume instance
|
||||
// in kubernetes cluster
|
||||
func (k *Kubeclient) Create(vol *apis.ZFSSnapshot) (*apis.ZFSSnapshot, error) {
|
||||
if vol == nil {
|
||||
return nil,
|
||||
errors.New(
|
||||
"failed to create csivolume: nil vol object",
|
||||
)
|
||||
}
|
||||
cs, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to create zfssnap volume {%s} in namespace {%s}",
|
||||
vol.Name,
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return k.create(cs, vol, k.namespace)
|
||||
}
|
||||
|
||||
// Get returns zfssnap volume object for given name
|
||||
func (k *Kubeclient) Get(
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
) (*apis.ZFSSnapshot, error) {
|
||||
if name == "" {
|
||||
return nil,
|
||||
errors.New(
|
||||
"failed to get zfssnap volume: missing zfssnap volume name",
|
||||
)
|
||||
}
|
||||
|
||||
cli, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to get zfssnap volume {%s} in namespace {%s}",
|
||||
name,
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return k.get(cli, name, k.namespace, opts)
|
||||
}
|
||||
|
||||
// GetRaw returns zfssnap volume instance
|
||||
// in bytes
|
||||
func (k *Kubeclient) GetRaw(
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
) ([]byte, error) {
|
||||
if name == "" {
|
||||
return nil, errors.New(
|
||||
"failed to get raw zfssnap volume: missing vol name",
|
||||
)
|
||||
}
|
||||
csiv, err := k.Get(name, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to get zfssnap volume {%s} in namespace {%s}",
|
||||
name,
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return json.Marshal(csiv)
|
||||
}
|
||||
|
||||
// List returns a list of zfssnap volume
|
||||
// instances present in kubernetes cluster
|
||||
func (k *Kubeclient) List(opts metav1.ListOptions) (*apis.ZFSSnapshotList, error) {
|
||||
cli, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to list zfssnap volumes in namespace {%s}",
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return k.list(cli, k.namespace, opts)
|
||||
}
|
||||
|
||||
// Delete deletes the zfssnap volume from
|
||||
// kubernetes
|
||||
func (k *Kubeclient) Delete(name string) error {
|
||||
if name == "" {
|
||||
return errors.New(
|
||||
"failed to delete csivolume: missing vol name",
|
||||
)
|
||||
}
|
||||
cli, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return errors.Wrapf(
|
||||
err,
|
||||
"failed to delete csivolume {%s} in namespace {%s}",
|
||||
name,
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return k.del(cli, name, k.namespace, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
// Update updates this zfssnap volume instance
|
||||
// against kubernetes cluster
|
||||
func (k *Kubeclient) Update(vol *apis.ZFSSnapshot) (*apis.ZFSSnapshot, error) {
|
||||
if vol == nil {
|
||||
return nil,
|
||||
errors.New(
|
||||
"failed to update csivolume: nil vol object",
|
||||
)
|
||||
}
|
||||
|
||||
cs, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to update csivolume {%s} in namespace {%s}",
|
||||
vol.Name,
|
||||
vol.Namespace,
|
||||
)
|
||||
}
|
||||
|
||||
return k.update(cs, vol, k.namespace)
|
||||
}
|
||||
117
pkg/builder/snapbuilder/snapshot.go
Normal file
117
pkg/builder/snapbuilder/snapshot.go
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
// Copyright © 2020 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 snapbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
)
|
||||
|
||||
// ZFSSnapshot is a wrapper over
|
||||
// ZFSSnapshot API instance
|
||||
type ZFSSnapshot struct {
|
||||
// ZFSSnap object
|
||||
Object *apis.ZFSSnapshot
|
||||
}
|
||||
|
||||
// From returns a new instance of
|
||||
// zfssnap volume
|
||||
func From(snap *apis.ZFSSnapshot) *ZFSSnapshot {
|
||||
return &ZFSSnapshot{
|
||||
Object: snap,
|
||||
}
|
||||
}
|
||||
|
||||
// Predicate defines an abstraction
|
||||
// to determine conditional checks
|
||||
// against the provided pod instance
|
||||
type Predicate func(*ZFSSnapshot) bool
|
||||
|
||||
// PredicateList holds a list of predicate
|
||||
type predicateList []Predicate
|
||||
|
||||
// ZFSSnapshotList holds the list
|
||||
// of zfs snapshot instances
|
||||
type ZFSSnapshotList struct {
|
||||
// List contains list of snapshots
|
||||
List apis.ZFSSnapshotList
|
||||
}
|
||||
|
||||
// Len returns the number of items present
|
||||
// in the ZFSSnapshotList
|
||||
func (snapList *ZFSSnapshotList) Len() int {
|
||||
return len(snapList.List.Items)
|
||||
}
|
||||
|
||||
// all returns true if all the predicates
|
||||
// succeed against the provided ZFSSnapshot
|
||||
// instance
|
||||
func (l predicateList) all(snap *ZFSSnapshot) bool {
|
||||
for _, pred := range l {
|
||||
if !pred(snap) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// HasLabels returns true if provided labels
|
||||
// are present in the provided ZFSSnapshot instance
|
||||
func HasLabels(keyValuePair map[string]string) Predicate {
|
||||
return func(snap *ZFSSnapshot) bool {
|
||||
for key, value := range keyValuePair {
|
||||
if !snap.HasLabel(key, value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasLabel returns true if provided label
|
||||
// is present in the provided ZFSSnapshot instance
|
||||
func (snap *ZFSSnapshot) HasLabel(key, value string) bool {
|
||||
val, ok := snap.Object.GetLabels()[key]
|
||||
if ok {
|
||||
return val == value
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasLabel returns true if provided label
|
||||
// is present in the provided ZFSSnapshot instance
|
||||
func HasLabel(key, value string) Predicate {
|
||||
return func(snap *ZFSSnapshot) bool {
|
||||
return snap.HasLabel(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// IsNil returns true if the zfssnap volume instance
|
||||
// is nil
|
||||
func (snap *ZFSSnapshot) IsNil() bool {
|
||||
return snap.Object == nil
|
||||
}
|
||||
|
||||
// IsNil is predicate to filter out nil zfssnap volume
|
||||
// instances
|
||||
func IsNil() Predicate {
|
||||
return func(snap *ZFSSnapshot) bool {
|
||||
return snap.IsNil()
|
||||
}
|
||||
}
|
||||
|
||||
// GetAPIObject returns zfssnap volume's API instance
|
||||
func (snap *ZFSSnapshot) GetAPIObject() *apis.ZFSSnapshot {
|
||||
return snap.Object
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package builder
|
||||
package volbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
|
|
@ -60,7 +60,7 @@ func (b *Builder) WithNamespace(namespace string) *Builder {
|
|||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi volume object: missing namespace",
|
||||
"failed to build zfs volume object: missing namespace",
|
||||
),
|
||||
)
|
||||
return b
|
||||
|
|
@ -75,7 +75,7 @@ func (b *Builder) WithName(name string) *Builder {
|
|||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi volume object: missing name",
|
||||
"failed to build zfs volume object: missing name",
|
||||
),
|
||||
)
|
||||
return b
|
||||
|
|
@ -84,14 +84,14 @@ func (b *Builder) WithName(name string) *Builder {
|
|||
return b
|
||||
}
|
||||
|
||||
// WithCapacity sets the Capacity of csi volume by converting string
|
||||
// WithCapacity sets the Capacity of zfs volume by converting string
|
||||
// capacity into Quantity
|
||||
func (b *Builder) WithCapacity(capacity string) *Builder {
|
||||
if capacity == "" {
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi volume object: missing capacity",
|
||||
"failed to build zfs volume object: missing capacity",
|
||||
),
|
||||
)
|
||||
return b
|
||||
|
|
@ -166,12 +166,18 @@ func (b *Builder) WithFsType(fstype string) *Builder {
|
|||
return b
|
||||
}
|
||||
|
||||
// WithSnapshot sets Snapshot name for creating clone volume
|
||||
func (b *Builder) WithSnapshot(snap string) *Builder {
|
||||
b.volume.Object.Spec.SnapName = snap
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *Builder) WithPoolName(pool string) *Builder {
|
||||
if pool == "" {
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi volume object: missing pool name",
|
||||
"failed to build zfs volume object: missing pool name",
|
||||
),
|
||||
)
|
||||
return b
|
||||
|
|
@ -185,7 +191,7 @@ func (b *Builder) WithNodename(name string) *Builder {
|
|||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New(
|
||||
"failed to build csi volume object: missing node name",
|
||||
"failed to build zfs volume object: missing node name",
|
||||
),
|
||||
)
|
||||
return b
|
||||
|
|
@ -198,10 +204,6 @@ func (b *Builder) WithNodename(name string) *Builder {
|
|||
// with the ones that are provided here
|
||||
func (b *Builder) WithLabels(labels map[string]string) *Builder {
|
||||
if len(labels) == 0 {
|
||||
b.errs = append(
|
||||
b.errs,
|
||||
errors.New("failed to build zfs volume object: missing labels"),
|
||||
)
|
||||
return b
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +222,7 @@ func (b *Builder) WithFinalizer(finalizer []string) *Builder {
|
|||
return b
|
||||
}
|
||||
|
||||
// Build returns csi volume API object
|
||||
// Build returns ZFSVolume API object
|
||||
func (b *Builder) Build() (*apis.ZFSVolume, error) {
|
||||
if len(b.errs) > 0 {
|
||||
return nil, errors.Errorf("%+v", b.errs)
|
||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package builder
|
||||
package volbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builder
|
||||
package volbuilder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
@ -36,7 +36,7 @@ type getClientsetForPathFn func(kubeConfigPath string) (
|
|||
)
|
||||
|
||||
// createFn is a typed function that abstracts
|
||||
// creating csi volume instance
|
||||
// creating zfs volume instance
|
||||
type createFn func(
|
||||
cs *clientset.Clientset,
|
||||
upgradeResultObj *apis.ZFSVolume,
|
||||
|
|
@ -44,7 +44,7 @@ type createFn func(
|
|||
) (*apis.ZFSVolume, error)
|
||||
|
||||
// getFn is a typed function that abstracts
|
||||
// fetching a csi volume instance
|
||||
// fetching a zfs volume instance
|
||||
type getFn func(
|
||||
cli *clientset.Clientset,
|
||||
name,
|
||||
|
|
@ -53,7 +53,7 @@ type getFn func(
|
|||
) (*apis.ZFSVolume, error)
|
||||
|
||||
// listFn is a typed function that abstracts
|
||||
// listing of csi volume instances
|
||||
// listing of zfs volume instances
|
||||
type listFn func(
|
||||
cli *clientset.Clientset,
|
||||
namespace string,
|
||||
|
|
@ -61,7 +61,7 @@ type listFn func(
|
|||
) (*apis.ZFSVolumeList, error)
|
||||
|
||||
// delFn is a typed function that abstracts
|
||||
// deleting a csi volume instance
|
||||
// deleting a zfs volume instance
|
||||
type delFn func(
|
||||
cli *clientset.Clientset,
|
||||
name,
|
||||
|
|
@ -70,7 +70,7 @@ type delFn func(
|
|||
) error
|
||||
|
||||
// updateFn is a typed function that abstracts
|
||||
// updating csi volume instance
|
||||
// updating zfs volume instance
|
||||
type updateFn func(
|
||||
cs *clientset.Clientset,
|
||||
vol *apis.ZFSVolume,
|
||||
|
|
@ -78,9 +78,9 @@ type updateFn func(
|
|||
) (*apis.ZFSVolume, error)
|
||||
|
||||
// Kubeclient enables kubernetes API operations
|
||||
// on csi volume instance
|
||||
// on zfs volume instance
|
||||
type Kubeclient struct {
|
||||
// clientset refers to csi volume's
|
||||
// clientset refers to zfs volume's
|
||||
// clientset that will be responsible to
|
||||
// make kubernetes API calls
|
||||
clientset *clientset.Clientset
|
||||
|
|
@ -134,7 +134,7 @@ func defaultGetClientsetForPath(
|
|||
}
|
||||
|
||||
// defaultGet is the default implementation to get
|
||||
// a csi volume instance in kubernetes cluster
|
||||
// a zfs volume instance in kubernetes cluster
|
||||
func defaultGet(
|
||||
cli *clientset.Clientset,
|
||||
name, namespace string,
|
||||
|
|
@ -146,7 +146,7 @@ func defaultGet(
|
|||
}
|
||||
|
||||
// defaultList is the default implementation to list
|
||||
// csi volume instances in kubernetes cluster
|
||||
// zfs volume instances in kubernetes cluster
|
||||
func defaultList(
|
||||
cli *clientset.Clientset,
|
||||
namespace string,
|
||||
|
|
@ -158,7 +158,7 @@ func defaultList(
|
|||
}
|
||||
|
||||
// defaultCreate is the default implementation to delete
|
||||
// a csi volume instance in kubernetes cluster
|
||||
// a zfs volume instance in kubernetes cluster
|
||||
func defaultDel(
|
||||
cli *clientset.Clientset,
|
||||
name, namespace string,
|
||||
|
|
@ -173,7 +173,7 @@ func defaultDel(
|
|||
}
|
||||
|
||||
// defaultCreate is the default implementation to create
|
||||
// a csi volume instance in kubernetes cluster
|
||||
// a zfs volume instance in kubernetes cluster
|
||||
func defaultCreate(
|
||||
cli *clientset.Clientset,
|
||||
vol *apis.ZFSVolume,
|
||||
|
|
@ -185,7 +185,7 @@ func defaultCreate(
|
|||
}
|
||||
|
||||
// defaultUpdate is the default implementation to update
|
||||
// a csi volume instance in kubernetes cluster
|
||||
// a zfs volume instance in kubernetes cluster
|
||||
func defaultUpdate(
|
||||
cli *clientset.Clientset,
|
||||
vol *apis.ZFSVolume,
|
||||
|
|
@ -254,7 +254,7 @@ func WithKubeConfigPath(path string) KubeclientBuildOption {
|
|||
}
|
||||
|
||||
// NewKubeclient returns a new instance of
|
||||
// kubeclient meant for csi volume operations
|
||||
// kubeclient meant for zfs volume operations
|
||||
func NewKubeclient(opts ...KubeclientBuildOption) *Kubeclient {
|
||||
k := &Kubeclient{}
|
||||
for _, o := range opts {
|
||||
|
|
@ -296,7 +296,7 @@ func (k *Kubeclient) getClientOrCached() (*clientset.Clientset, error) {
|
|||
return k.clientset, nil
|
||||
}
|
||||
|
||||
// Create creates a csi volume instance
|
||||
// Create creates a zfs volume instance
|
||||
// in kubernetes cluster
|
||||
func (k *Kubeclient) Create(vol *apis.ZFSVolume) (*apis.ZFSVolume, error) {
|
||||
if vol == nil {
|
||||
|
|
@ -309,7 +309,7 @@ func (k *Kubeclient) Create(vol *apis.ZFSVolume) (*apis.ZFSVolume, error) {
|
|||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to create csi volume {%s} in namespace {%s}",
|
||||
"failed to create zfs volume {%s} in namespace {%s}",
|
||||
vol.Name,
|
||||
k.namespace,
|
||||
)
|
||||
|
|
@ -318,7 +318,7 @@ func (k *Kubeclient) Create(vol *apis.ZFSVolume) (*apis.ZFSVolume, error) {
|
|||
return k.create(cs, vol, k.namespace)
|
||||
}
|
||||
|
||||
// Get returns csi volume object for given name
|
||||
// Get returns zfs volume object for given name
|
||||
func (k *Kubeclient) Get(
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
|
|
@ -326,7 +326,7 @@ func (k *Kubeclient) Get(
|
|||
if name == "" {
|
||||
return nil,
|
||||
errors.New(
|
||||
"failed to get csi volume: missing csi volume name",
|
||||
"failed to get zfs volume: missing zfs volume name",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ func (k *Kubeclient) Get(
|
|||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to get csi volume {%s} in namespace {%s}",
|
||||
"failed to get zfs volume {%s} in namespace {%s}",
|
||||
name,
|
||||
k.namespace,
|
||||
)
|
||||
|
|
@ -343,7 +343,7 @@ func (k *Kubeclient) Get(
|
|||
return k.get(cli, name, k.namespace, opts)
|
||||
}
|
||||
|
||||
// GetRaw returns csi volume instance
|
||||
// GetRaw returns zfs volume instance
|
||||
// in bytes
|
||||
func (k *Kubeclient) GetRaw(
|
||||
name string,
|
||||
|
|
@ -351,14 +351,14 @@ func (k *Kubeclient) GetRaw(
|
|||
) ([]byte, error) {
|
||||
if name == "" {
|
||||
return nil, errors.New(
|
||||
"failed to get raw csi volume: missing vol name",
|
||||
"failed to get raw zfs volume: missing vol name",
|
||||
)
|
||||
}
|
||||
csiv, err := k.Get(name, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to get csi volume {%s} in namespace {%s}",
|
||||
"failed to get zfs volume {%s} in namespace {%s}",
|
||||
name,
|
||||
k.namespace,
|
||||
)
|
||||
|
|
@ -367,14 +367,14 @@ func (k *Kubeclient) GetRaw(
|
|||
return json.Marshal(csiv)
|
||||
}
|
||||
|
||||
// List returns a list of csi volume
|
||||
// List returns a list of zfs volume
|
||||
// instances present in kubernetes cluster
|
||||
func (k *Kubeclient) List(opts metav1.ListOptions) (*apis.ZFSVolumeList, error) {
|
||||
cli, err := k.getClientOrCached()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err,
|
||||
"failed to list csi volumes in namespace {%s}",
|
||||
"failed to list zfs volumes in namespace {%s}",
|
||||
k.namespace,
|
||||
)
|
||||
}
|
||||
|
|
@ -382,7 +382,7 @@ func (k *Kubeclient) List(opts metav1.ListOptions) (*apis.ZFSVolumeList, error)
|
|||
return k.list(cli, k.namespace, opts)
|
||||
}
|
||||
|
||||
// Delete deletes the csi volume from
|
||||
// Delete deletes the zfs volume from
|
||||
// kubernetes
|
||||
func (k *Kubeclient) Delete(name string) error {
|
||||
if name == "" {
|
||||
|
|
@ -403,7 +403,7 @@ func (k *Kubeclient) Delete(name string) error {
|
|||
return k.del(cli, name, k.namespace, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
// Update updates this csi volume instance
|
||||
// Update updates this zfs volume instance
|
||||
// against kubernetes cluster
|
||||
func (k *Kubeclient) Update(vol *apis.ZFSVolume) (*apis.ZFSVolume, error) {
|
||||
if vol == nil {
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builder
|
||||
package volbuilder
|
||||
|
||||
import (
|
||||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/core/v1alpha1"
|
||||
|
|
@ -21,11 +21,12 @@ import (
|
|||
// ZFSVolume is a wrapper over
|
||||
// ZFSVolume API instance
|
||||
type ZFSVolume struct {
|
||||
// ZFSVolume object
|
||||
Object *apis.ZFSVolume
|
||||
}
|
||||
|
||||
// From returns a new instance of
|
||||
// csi volume
|
||||
// zfs volume
|
||||
func From(vol *apis.ZFSVolume) *ZFSVolume {
|
||||
return &ZFSVolume{
|
||||
Object: vol,
|
||||
|
|
@ -41,23 +42,24 @@ type Predicate func(*ZFSVolume) bool
|
|||
type predicateList []Predicate
|
||||
|
||||
// ZFSVolumeList holds the list
|
||||
// of csi volume instances
|
||||
// of zfs volume instances
|
||||
type ZFSVolumeList struct {
|
||||
// List conatils list of volumes
|
||||
List apis.ZFSVolumeList
|
||||
}
|
||||
|
||||
// Len returns the number of items present
|
||||
// in the ZFSVolumeList
|
||||
func (p *ZFSVolumeList) Len() int {
|
||||
return len(p.List.Items)
|
||||
func (volList *ZFSVolumeList) Len() int {
|
||||
return len(volList.List.Items)
|
||||
}
|
||||
|
||||
// all returns true if all the predicates
|
||||
// succeed against the provided ZFSVolume
|
||||
// instance
|
||||
func (l predicateList) all(p *ZFSVolume) bool {
|
||||
func (l predicateList) all(vol *ZFSVolume) bool {
|
||||
for _, pred := range l {
|
||||
if !pred(p) {
|
||||
if !pred(vol) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -67,9 +69,9 @@ func (l predicateList) all(p *ZFSVolume) bool {
|
|||
// HasLabels returns true if provided labels
|
||||
// are present in the provided ZFSVolume instance
|
||||
func HasLabels(keyValuePair map[string]string) Predicate {
|
||||
return func(p *ZFSVolume) bool {
|
||||
return func(vol *ZFSVolume) bool {
|
||||
for key, value := range keyValuePair {
|
||||
if !p.HasLabel(key, value) {
|
||||
if !vol.HasLabel(key, value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -79,8 +81,8 @@ func HasLabels(keyValuePair map[string]string) Predicate {
|
|||
|
||||
// HasLabel returns true if provided label
|
||||
// is present in the provided ZFSVolume instance
|
||||
func (p *ZFSVolume) HasLabel(key, value string) bool {
|
||||
val, ok := p.Object.GetLabels()[key]
|
||||
func (vol *ZFSVolume) HasLabel(key, value string) bool {
|
||||
val, ok := vol.Object.GetLabels()[key]
|
||||
if ok {
|
||||
return val == value
|
||||
}
|
||||
|
|
@ -90,26 +92,26 @@ func (p *ZFSVolume) HasLabel(key, value string) bool {
|
|||
// HasLabel returns true if provided label
|
||||
// is present in the provided ZFSVolume instance
|
||||
func HasLabel(key, value string) Predicate {
|
||||
return func(p *ZFSVolume) bool {
|
||||
return p.HasLabel(key, value)
|
||||
return func(vol *ZFSVolume) bool {
|
||||
return vol.HasLabel(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// IsNil returns true if the csi volume instance
|
||||
// IsNil returns true if the zfs volume instance
|
||||
// is nil
|
||||
func (p *ZFSVolume) IsNil() bool {
|
||||
return p.Object == nil
|
||||
func (vol *ZFSVolume) IsNil() bool {
|
||||
return vol.Object == nil
|
||||
}
|
||||
|
||||
// IsNil is predicate to filter out nil csi volume
|
||||
// IsNil is predicate to filter out nil zfs volume
|
||||
// instances
|
||||
func IsNil() Predicate {
|
||||
return func(p *ZFSVolume) bool {
|
||||
return p.IsNil()
|
||||
return func(vol *ZFSVolume) bool {
|
||||
return vol.IsNil()
|
||||
}
|
||||
}
|
||||
|
||||
// GetAPIObject returns csi volume's API instance
|
||||
func (p *ZFSVolume) GetAPIObject() *apis.ZFSVolume {
|
||||
return p.Object
|
||||
// GetAPIObject returns zfs volume's API instance
|
||||
func (vol *ZFSVolume) GetAPIObject() *apis.ZFSVolume {
|
||||
return vol.Object
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue