@@ -27,13 +27,12 @@ import (
2727 "github.com/openebs/api/v2/pkg/apis/openebs.io/v1alpha1"
2828 lvmclient "github.com/openebs/lvm-localpv/pkg/generated/clientset/internalclientset"
2929 "github.com/openebs/openebsctl/pkg/util"
30+ zfsclient "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset"
3031 "github.com/pkg/errors"
3132
3233 cstorv1 "github.com/openebs/api/v2/pkg/apis/cstor/v1"
3334 openebsclientset "github.com/openebs/api/v2/pkg/client/clientset/versioned"
3435 jiva "github.com/openebs/jiva-operator/pkg/apis/openebs/v1alpha1"
35- zfs "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
36- zfsBuilder "github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
3736
3837 appsv1 "k8s.io/api/apps/v1"
3938 corev1 "k8s.io/api/core/v1"
@@ -65,6 +64,8 @@ type K8sClient struct {
6564 OpenebsCS openebsclientset.Interface
6665 // LVMCS is the client for accessing OpenEBS LVM components
6766 LVMCS lvmclient.Interface
67+ // ZFCS is the client for accessing OpenEBS ZFS components
68+ ZFCS zfsclient.Interface
6869}
6970
7071/*
@@ -88,11 +89,13 @@ func NewK8sClient(ns string) (*K8sClient, error) {
8889 return nil , errors .Wrap (err , "failed to build OpenEBS clientset" )
8990 }
9091 lv , _ := getLVMclient (config )
92+ zf , _ := getZFSclient (config )
9193 return & K8sClient {
9294 Ns : ns ,
9395 K8sCS : k8sCS ,
9496 OpenebsCS : openebsCS ,
9597 LVMCS : lv ,
98+ ZFCS : zf ,
9699 }, nil
97100}
98101
@@ -641,60 +644,6 @@ func (k K8sClient) GetJVTargetPod(volumeName string) (*corev1.PodList, error) {
641644 return pods , nil
642645}
643646
644- // GetZFSVols returns a list or a map of ZFSVolume depending upon rType & options
645- func (k K8sClient ) GetZFSVols (volNames []string , rType util.ReturnType , labelSelector string , options util.MapOptions ) (* zfs.ZFSVolumeList , map [string ]zfs.ZFSVolume , error ) {
646- config := os .Getenv ("KUBECONFIG" )
647- zvols , err := zfsBuilder .NewKubeclient (zfsBuilder .WithKubeConfigPath (config )).
648- WithNamespace ("" ).
649- List (metav1.ListOptions {
650- LabelSelector : labelSelector ,
651- })
652- if err != nil {
653- return nil , nil , err
654- }
655- var list []zfs.ZFSVolume
656- if len (volNames ) == 0 {
657- list = zvols .Items
658- } else {
659- zvsMap := make (map [string ]zfs.ZFSVolume )
660- for _ , zv := range zvols .Items {
661- zvsMap [zv .Name ] = zv
662- }
663- for _ , name := range volNames {
664- if zv , ok := zvsMap [name ]; ok {
665- list = append (list , zv )
666- } else {
667- fmt .Printf ("Error from server (NotFound): zfsVolume %s not found\n " , name )
668- }
669- }
670- }
671- if rType == util .List {
672- return & zfs.ZFSVolumeList {
673- Items : list ,
674- }, nil , nil
675- }
676- if rType == util .Map {
677- zvMap := make (map [string ]zfs.ZFSVolume )
678- switch options .Key {
679- case util .Label :
680- for _ , zv := range list {
681- if vol , ok := zv .Labels [options .LabelKey ]; ok {
682- zvMap [vol ] = zv
683- }
684- }
685- return nil , zvMap , nil
686- case util .Name :
687- for _ , zv := range list {
688- zvMap [zv .Name ] = zv
689- }
690- return nil , zvMap , nil
691- default :
692- return nil , nil , errors .New ("invalid map options" )
693- }
694- }
695- return nil , nil , errors .New ("invalid return type" )
696- }
697-
698647// GetCSIControllerSTS returns the CSI controller sts with a specific
699648// openebs-component-name label key
700649func (k K8sClient ) GetCSIControllerSTS (name string ) (* appsv1.StatefulSet , error ) {
0 commit comments