diff --git a/cmd/kubectl-directpv/discover.go b/cmd/kubectl-directpv/discover.go index cf1081f8..64749812 100644 --- a/cmd/kubectl-directpv/discover.go +++ b/cmd/kubectl-directpv/discover.go @@ -32,7 +32,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/consts" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/watch" ) @@ -255,7 +254,7 @@ func discoverDevices(ctx context.Context, nodes, drives []string, teaProgram *te defer cancel() eventCh, stop, err := adminClient.NewNodeLister(). - NodeSelector(utils.ToLabelValues(nodes)). + NodeSelector(directpvtypes.ToLabelValues(nodes)). Watch(ctx) if err != nil { return nil, err diff --git a/cmd/kubectl-directpv/init.go b/cmd/kubectl-directpv/init.go index e0441541..8ac3d255 100644 --- a/cmd/kubectl-directpv/init.go +++ b/cmd/kubectl-directpv/init.go @@ -31,7 +31,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/consts" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" @@ -167,7 +166,7 @@ func initDevices(ctx context.Context, initRequests []types.InitRequest, requestI defer cancel() eventCh, stop, err := adminClient.NewInitRequestLister(). - RequestIDSelector(utils.ToLabelValues([]string{requestID})). + RequestIDSelector(directpvtypes.ToLabelValues([]string{requestID})). Watch(ctx) if err != nil { return nil, err @@ -235,7 +234,7 @@ func initMain(ctx context.Context, inputFile string) { } defer func() { labelMap := map[directpvtypes.LabelKey][]directpvtypes.LabelValue{ - directpvtypes.RequestIDLabelKey: utils.ToLabelValues([]string{requestID}), + directpvtypes.RequestIDLabelKey: directpvtypes.ToLabelValues([]string{requestID}), } adminClient.InitRequest().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{ LabelSelector: directpvtypes.ToLabelSelector(labelMap), diff --git a/cmd/kubectl-directpv/list_drives.go b/cmd/kubectl-directpv/list_drives.go index 7556d53b..47b8edbc 100644 --- a/cmd/kubectl-directpv/list_drives.go +++ b/cmd/kubectl-directpv/list_drives.go @@ -26,7 +26,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/consts" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -117,8 +116,8 @@ func validateListDrivesArgs() error { func listDrivesMain(ctx context.Context) { drives, err := adminClient.NewDriveLister(). - NodeSelector(utils.ToLabelValues(nodesArgs)). - DriveNameSelector(utils.ToLabelValues(drivesArgs)). + NodeSelector(directpvtypes.ToLabelValues(nodesArgs)). + DriveNameSelector(directpvtypes.ToLabelValues(drivesArgs)). StatusSelector(driveStatusSelectors). DriveIDSelector(driveIDSelectors). LabelSelector(labelSelectors). diff --git a/cmd/kubectl-directpv/list_volumes.go b/cmd/kubectl-directpv/list_volumes.go index 8ab6a2a3..b6c45975 100644 --- a/cmd/kubectl-directpv/list_volumes.go +++ b/cmd/kubectl-directpv/list_volumes.go @@ -25,7 +25,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/consts" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -154,11 +153,11 @@ func getPVCName(ctx context.Context, volume types.Volume) string { func listVolumesMain(ctx context.Context) { volumes, err := adminClient.NewVolumeLister(). - NodeSelector(utils.ToLabelValues(nodesArgs)). - DriveNameSelector(utils.ToLabelValues(drivesArgs)). - DriveIDSelector(utils.ToLabelValues(driveIDArgs)). - PodNameSelector(utils.ToLabelValues(podNameArgs)). - PodNSSelector(utils.ToLabelValues(podNSArgs)). + NodeSelector(directpvtypes.ToLabelValues(nodesArgs)). + DriveNameSelector(directpvtypes.ToLabelValues(drivesArgs)). + DriveIDSelector(directpvtypes.ToLabelValues(driveIDArgs)). + PodNameSelector(directpvtypes.ToLabelValues(podNameArgs)). + PodNSSelector(directpvtypes.ToLabelValues(podNSArgs)). StatusSelector(volumeStatusSelectors). VolumeNameSelector(volumeNameArgs). LabelSelector(labelSelectors). diff --git a/pkg/admin/clean.go b/pkg/admin/clean.go index 08a9fb84..053d8c16 100644 --- a/pkg/admin/clean.go +++ b/pkg/admin/clean.go @@ -22,7 +22,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -50,11 +49,11 @@ func (client *Client) Clean(ctx context.Context, args CleanArgs, log LogFunc) (r defer cancelFunc() resultCh := client.NewVolumeLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). - DriveIDSelector(utils.ToLabelValues(args.DriveIDs)). - PodNameSelector(utils.ToLabelValues(args.PodNames)). - PodNSSelector(utils.ToLabelValues(args.PodNamespaces)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). + DriveIDSelector(directpvtypes.ToLabelValues(args.DriveIDs)). + PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)). + PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)). StatusSelector(args.VolumeStatus). VolumeNameSelector(args.VolumeNames). List(ctx) diff --git a/pkg/admin/cordon.go b/pkg/admin/cordon.go index 1db313fe..533ad598 100644 --- a/pkg/admin/cordon.go +++ b/pkg/admin/cordon.go @@ -21,7 +21,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -52,8 +51,8 @@ func (client *Client) Cordon(ctx context.Context, args CordonArgs, log LogFunc) defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). StatusSelector(args.Status). DriveIDSelector(args.DriveIDs). List(ctx) diff --git a/pkg/admin/label_drives.go b/pkg/admin/label_drives.go index 8a3ab7dd..98a91fe1 100644 --- a/pkg/admin/label_drives.go +++ b/pkg/admin/label_drives.go @@ -21,7 +21,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -78,8 +77,8 @@ func (client *Client) LabelDrives(ctx context.Context, args LabelDriveArgs, labe defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). StatusSelector(args.DriveStatus). DriveIDSelector(args.DriveIDs). LabelSelector(args.LabelSelectors). diff --git a/pkg/admin/label_volumes.go b/pkg/admin/label_volumes.go index ab74010d..5b19483a 100644 --- a/pkg/admin/label_volumes.go +++ b/pkg/admin/label_volumes.go @@ -21,7 +21,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -67,11 +66,11 @@ func (client *Client) LabelVolumes(ctx context.Context, args LabelVolumeArgs, la var processed bool resultCh := client.NewVolumeLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). - DriveIDSelector(utils.ToLabelValues(args.DriveIDs)). - PodNameSelector(utils.ToLabelValues(args.PodNames)). - PodNSSelector(utils.ToLabelValues(args.PodNamespaces)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). + DriveIDSelector(directpvtypes.ToLabelValues(args.DriveIDs)). + PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)). + PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)). StatusSelector(args.VolumeStatus). VolumeNameSelector(args.VolumeNames). LabelSelector(args.LabelSelectors). diff --git a/pkg/admin/refresh.go b/pkg/admin/refresh.go index 9e53c176..0aff397a 100644 --- a/pkg/admin/refresh.go +++ b/pkg/admin/refresh.go @@ -23,7 +23,6 @@ import ( directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "github.com/minio/directpv/pkg/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -35,7 +34,7 @@ func (client *Client) RefreshNodes(ctx context.Context, selectedNodes []string) } nodes, err := client.NewNodeLister(). - NodeSelector(utils.ToLabelValues(selectedNodes)). + NodeSelector(directpvtypes.ToLabelValues(selectedNodes)). Get(ctx) if err != nil { return nil, nil, err diff --git a/pkg/admin/remove.go b/pkg/admin/remove.go index 314cb236..a08b4dc6 100644 --- a/pkg/admin/remove.go +++ b/pkg/admin/remove.go @@ -22,7 +22,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -54,8 +53,8 @@ func (client *Client) Remove(ctx context.Context, args RemoveArgs, log LogFunc) defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). StatusSelector(args.DriveStatus). DriveIDSelector(args.DriveIDs). IgnoreNotFound(true). diff --git a/pkg/admin/resume_drives.go b/pkg/admin/resume_drives.go index d26acff1..afd00b82 100644 --- a/pkg/admin/resume_drives.go +++ b/pkg/admin/resume_drives.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/minio/directpv/pkg/utils" + directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -43,8 +43,8 @@ func (client *Client) ResumeDrives(ctx context.Context, args ResumeDriveArgs, lo defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). DriveIDSelector(args.DriveIDSelectors). List(ctx) for result := range resultCh { diff --git a/pkg/admin/resume_volumes.go b/pkg/admin/resume_volumes.go index c425758c..93a994b6 100644 --- a/pkg/admin/resume_volumes.go +++ b/pkg/admin/resume_volumes.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/minio/directpv/pkg/utils" + directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -43,10 +43,10 @@ func (client *Client) ResumeVolumes(ctx context.Context, args ResumeVolumeArgs, defer cancelFunc() resultCh := client.NewVolumeLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). - PodNameSelector(utils.ToLabelValues(args.PodNames)). - PodNSSelector(utils.ToLabelValues(args.PodNamespaces)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). + PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)). + PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)). VolumeNameSelector(args.VolumeNames). List(ctx) for result := range resultCh { diff --git a/pkg/admin/suspend_drives.go b/pkg/admin/suspend_drives.go index f2a6b9f5..88595555 100644 --- a/pkg/admin/suspend_drives.go +++ b/pkg/admin/suspend_drives.go @@ -22,7 +22,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -56,8 +55,8 @@ func (client *Client) SuspendDrives(ctx context.Context, args SuspendDriveArgs, defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). DriveIDSelector(args.DriveIDSelectors). List(ctx) for result := range resultCh { diff --git a/pkg/admin/suspend_volumes.go b/pkg/admin/suspend_volumes.go index 13a6a113..bb25ba30 100644 --- a/pkg/admin/suspend_volumes.go +++ b/pkg/admin/suspend_volumes.go @@ -21,7 +21,6 @@ import ( "fmt" directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" - "github.com/minio/directpv/pkg/utils" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/util/retry" ) @@ -54,10 +53,10 @@ func (client *Client) SuspendVolumes(ctx context.Context, args SuspendVolumeArgs defer cancelFunc() resultCh := client.NewVolumeLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). - PodNameSelector(utils.ToLabelValues(args.PodNames)). - PodNSSelector(utils.ToLabelValues(args.PodNamespaces)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). + PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)). + PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)). VolumeNameSelector(args.VolumeNames). List(ctx) for result := range resultCh { diff --git a/pkg/admin/uncordon.go b/pkg/admin/uncordon.go index 2341b7b7..3237a5c3 100644 --- a/pkg/admin/uncordon.go +++ b/pkg/admin/uncordon.go @@ -20,7 +20,7 @@ import ( "context" "fmt" - "github.com/minio/directpv/pkg/utils" + directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -42,8 +42,8 @@ func (client *Client) Uncordon(ctx context.Context, args UncordonArgs, log LogFu defer cancelFunc() resultCh := client.NewDriveLister(). - NodeSelector(utils.ToLabelValues(args.Nodes)). - DriveNameSelector(utils.ToLabelValues(args.Drives)). + NodeSelector(directpvtypes.ToLabelValues(args.Nodes)). + DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)). StatusSelector(args.Status). DriveIDSelector(args.DriveIDs). List(ctx) diff --git a/pkg/apis/directpv.min.io/types/label.go b/pkg/apis/directpv.min.io/types/label.go index 72425b63..dab7b387 100644 --- a/pkg/apis/directpv.min.io/types/label.go +++ b/pkg/apis/directpv.min.io/types/label.go @@ -164,6 +164,14 @@ func ToLabelValue(value string) LabelValue { return result } +// ToLabelValues converts a string list to label values +func ToLabelValues(slice []string) (values []LabelValue) { + for _, s := range slice { + values = append(values, ToLabelValue(s)) + } + return +} + // ToLabelSelector converts a map of label key and label value to selector string func ToLabelSelector(labels map[LabelKey][]LabelValue) string { selectors := []string{} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 0800a784..850f4ed3 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -25,7 +25,6 @@ import ( "strings" "github.com/fatih/color" - directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" "sigs.k8s.io/yaml" ) @@ -158,14 +157,6 @@ func Eprintf(quiet, asErr bool, format string, a ...any) { fmt.Fprintf(os.Stderr, format, a...) } -// ToLabelValues converts a string list to label values -func ToLabelValues(slice []string) (values []directpvtypes.LabelValue) { - for _, s := range slice { - values = append(values, directpvtypes.ToLabelValue(s)) - } - return -} - // IBytes produces a human readable representation of an IEC size rounding to two decimal places. func IBytes(ui64 uint64) string { value := ui64