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 1a6f0a96..9ccd2c43 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" ) @@ -53,8 +52,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 ab09e943..a5097d7d 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" ) @@ -79,8 +78,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 67e3c154..50015d94 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 e32404b8..940a4548 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" ) @@ -55,8 +54,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 1cce60bb..7e1346f7 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 c3e2e390..6e55d8bc 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 471ce2b2..dddc2150 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" ) @@ -58,8 +57,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 1f636754..a60f89c7 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" ) @@ -58,10 +57,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 00797ba7..74bd9d25 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 c94ca57c..058c00c4 100644 --- a/pkg/apis/directpv.min.io/types/label.go +++ b/pkg/apis/directpv.min.io/types/label.go @@ -160,6 +160,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