Skip to content

Commit 5397330

Browse files
authored
Move pkg/utils/ToLabelValues into pkg/apis/directpv.min.io/types (#975)
Signed-off-by: Bala.FA <bala@minio.io>
1 parent e0d9577 commit 5397330

17 files changed

+52
-65
lines changed

cmd/kubectl-directpv/discover.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
3333
"github.com/minio/directpv/pkg/consts"
3434
"github.com/minio/directpv/pkg/types"
35-
"github.com/minio/directpv/pkg/utils"
3635
"github.com/spf13/cobra"
3736
"k8s.io/apimachinery/pkg/watch"
3837
)
@@ -255,7 +254,7 @@ func discoverDevices(ctx context.Context, nodes, drives []string, teaProgram *te
255254
defer cancel()
256255

257256
eventCh, stop, err := adminClient.NewNodeLister().
258-
NodeSelector(utils.ToLabelValues(nodes)).
257+
NodeSelector(directpvtypes.ToLabelValues(nodes)).
259258
Watch(ctx)
260259
if err != nil {
261260
return nil, err

cmd/kubectl-directpv/init.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
3232
"github.com/minio/directpv/pkg/consts"
3333
"github.com/minio/directpv/pkg/types"
34-
"github.com/minio/directpv/pkg/utils"
3534
"github.com/spf13/cobra"
3635
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3736
"k8s.io/apimachinery/pkg/watch"
@@ -167,7 +166,7 @@ func initDevices(ctx context.Context, initRequests []types.InitRequest, requestI
167166
defer cancel()
168167

169168
eventCh, stop, err := adminClient.NewInitRequestLister().
170-
RequestIDSelector(utils.ToLabelValues([]string{requestID})).
169+
RequestIDSelector(directpvtypes.ToLabelValues([]string{requestID})).
171170
Watch(ctx)
172171
if err != nil {
173172
return nil, err
@@ -235,7 +234,7 @@ func initMain(ctx context.Context, inputFile string) {
235234
}
236235
defer func() {
237236
labelMap := map[directpvtypes.LabelKey][]directpvtypes.LabelValue{
238-
directpvtypes.RequestIDLabelKey: utils.ToLabelValues([]string{requestID}),
237+
directpvtypes.RequestIDLabelKey: directpvtypes.ToLabelValues([]string{requestID}),
239238
}
240239
adminClient.InitRequest().DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
241240
LabelSelector: directpvtypes.ToLabelSelector(labelMap),

cmd/kubectl-directpv/list_drives.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2727
"github.com/minio/directpv/pkg/consts"
2828
"github.com/minio/directpv/pkg/types"
29-
"github.com/minio/directpv/pkg/utils"
3029
"github.com/spf13/cobra"
3130
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3231
)
@@ -117,8 +116,8 @@ func validateListDrivesArgs() error {
117116

118117
func listDrivesMain(ctx context.Context) {
119118
drives, err := adminClient.NewDriveLister().
120-
NodeSelector(utils.ToLabelValues(nodesArgs)).
121-
DriveNameSelector(utils.ToLabelValues(drivesArgs)).
119+
NodeSelector(directpvtypes.ToLabelValues(nodesArgs)).
120+
DriveNameSelector(directpvtypes.ToLabelValues(drivesArgs)).
122121
StatusSelector(driveStatusSelectors).
123122
DriveIDSelector(driveIDSelectors).
124123
LabelSelector(labelSelectors).

cmd/kubectl-directpv/list_volumes.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2626
"github.com/minio/directpv/pkg/consts"
2727
"github.com/minio/directpv/pkg/types"
28-
"github.com/minio/directpv/pkg/utils"
2928
"github.com/spf13/cobra"
3029
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3130
)
@@ -154,11 +153,11 @@ func getPVCName(ctx context.Context, volume types.Volume) string {
154153

155154
func listVolumesMain(ctx context.Context) {
156155
volumes, err := adminClient.NewVolumeLister().
157-
NodeSelector(utils.ToLabelValues(nodesArgs)).
158-
DriveNameSelector(utils.ToLabelValues(drivesArgs)).
159-
DriveIDSelector(utils.ToLabelValues(driveIDArgs)).
160-
PodNameSelector(utils.ToLabelValues(podNameArgs)).
161-
PodNSSelector(utils.ToLabelValues(podNSArgs)).
156+
NodeSelector(directpvtypes.ToLabelValues(nodesArgs)).
157+
DriveNameSelector(directpvtypes.ToLabelValues(drivesArgs)).
158+
DriveIDSelector(directpvtypes.ToLabelValues(driveIDArgs)).
159+
PodNameSelector(directpvtypes.ToLabelValues(podNameArgs)).
160+
PodNSSelector(directpvtypes.ToLabelValues(podNSArgs)).
162161
StatusSelector(volumeStatusSelectors).
163162
VolumeNameSelector(volumeNameArgs).
164163
LabelSelector(labelSelectors).

pkg/admin/clean.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2424
"github.com/minio/directpv/pkg/types"
25-
"github.com/minio/directpv/pkg/utils"
2625
corev1 "k8s.io/api/core/v1"
2726
apierrors "k8s.io/apimachinery/pkg/api/errors"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -50,11 +49,11 @@ func (client *Client) Clean(ctx context.Context, args CleanArgs, log LogFunc) (r
5049
defer cancelFunc()
5150

5251
resultCh := client.NewVolumeLister().
53-
NodeSelector(utils.ToLabelValues(args.Nodes)).
54-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
55-
DriveIDSelector(utils.ToLabelValues(args.DriveIDs)).
56-
PodNameSelector(utils.ToLabelValues(args.PodNames)).
57-
PodNSSelector(utils.ToLabelValues(args.PodNamespaces)).
52+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
53+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
54+
DriveIDSelector(directpvtypes.ToLabelValues(args.DriveIDs)).
55+
PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)).
56+
PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)).
5857
StatusSelector(args.VolumeStatus).
5958
VolumeNameSelector(args.VolumeNames).
6059
List(ctx)

pkg/admin/cordon.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
24-
"github.com/minio/directpv/pkg/utils"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
)
2726

@@ -53,8 +52,8 @@ func (client *Client) Cordon(ctx context.Context, args CordonArgs, log LogFunc)
5352
defer cancelFunc()
5453

5554
resultCh := client.NewDriveLister().
56-
NodeSelector(utils.ToLabelValues(args.Nodes)).
57-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
55+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
56+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
5857
StatusSelector(args.Status).
5958
DriveIDSelector(args.DriveIDs).
6059
List(ctx)

pkg/admin/label_drives.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
24-
"github.com/minio/directpv/pkg/utils"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
"k8s.io/client-go/util/retry"
2726
)
@@ -79,8 +78,8 @@ func (client *Client) LabelDrives(ctx context.Context, args LabelDriveArgs, labe
7978
defer cancelFunc()
8079

8180
resultCh := client.NewDriveLister().
82-
NodeSelector(utils.ToLabelValues(args.Nodes)).
83-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
81+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
82+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
8483
StatusSelector(args.DriveStatus).
8584
DriveIDSelector(args.DriveIDs).
8685
LabelSelector(args.LabelSelectors).

pkg/admin/label_volumes.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
24-
"github.com/minio/directpv/pkg/utils"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
"k8s.io/client-go/util/retry"
2726
)
@@ -67,11 +66,11 @@ func (client *Client) LabelVolumes(ctx context.Context, args LabelVolumeArgs, la
6766

6867
var processed bool
6968
resultCh := client.NewVolumeLister().
70-
NodeSelector(utils.ToLabelValues(args.Nodes)).
71-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
72-
DriveIDSelector(utils.ToLabelValues(args.DriveIDs)).
73-
PodNameSelector(utils.ToLabelValues(args.PodNames)).
74-
PodNSSelector(utils.ToLabelValues(args.PodNamespaces)).
69+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
70+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
71+
DriveIDSelector(directpvtypes.ToLabelValues(args.DriveIDs)).
72+
PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)).
73+
PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)).
7574
StatusSelector(args.VolumeStatus).
7675
VolumeNameSelector(args.VolumeNames).
7776
LabelSelector(args.LabelSelectors).

pkg/admin/refresh.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2525
"github.com/minio/directpv/pkg/types"
26-
"github.com/minio/directpv/pkg/utils"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
"k8s.io/client-go/util/retry"
2928
)
@@ -35,7 +34,7 @@ func (client *Client) RefreshNodes(ctx context.Context, selectedNodes []string)
3534
}
3635

3736
nodes, err := client.NewNodeLister().
38-
NodeSelector(utils.ToLabelValues(selectedNodes)).
37+
NodeSelector(directpvtypes.ToLabelValues(selectedNodes)).
3938
Get(ctx)
4039
if err != nil {
4140
return nil, nil, err

pkg/admin/remove.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323

2424
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
25-
"github.com/minio/directpv/pkg/utils"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
)
2827

@@ -55,8 +54,8 @@ func (client *Client) Remove(ctx context.Context, args RemoveArgs, log LogFunc)
5554
defer cancelFunc()
5655

5756
resultCh := client.NewDriveLister().
58-
NodeSelector(utils.ToLabelValues(args.Nodes)).
59-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
57+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
58+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
6059
StatusSelector(args.DriveStatus).
6160
DriveIDSelector(args.DriveIDs).
6261
IgnoreNotFound(true).

pkg/admin/resume_drives.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23-
"github.com/minio/directpv/pkg/utils"
23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/client-go/util/retry"
2626
)
@@ -43,8 +43,8 @@ func (client *Client) ResumeDrives(ctx context.Context, args ResumeDriveArgs, lo
4343
defer cancelFunc()
4444

4545
resultCh := client.NewDriveLister().
46-
NodeSelector(utils.ToLabelValues(args.Nodes)).
47-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
46+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
47+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
4848
DriveIDSelector(args.DriveIDSelectors).
4949
List(ctx)
5050
for result := range resultCh {

pkg/admin/resume_volumes.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23-
"github.com/minio/directpv/pkg/utils"
23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/client-go/util/retry"
2626
)
@@ -43,10 +43,10 @@ func (client *Client) ResumeVolumes(ctx context.Context, args ResumeVolumeArgs,
4343
defer cancelFunc()
4444

4545
resultCh := client.NewVolumeLister().
46-
NodeSelector(utils.ToLabelValues(args.Nodes)).
47-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
48-
PodNameSelector(utils.ToLabelValues(args.PodNames)).
49-
PodNSSelector(utils.ToLabelValues(args.PodNamespaces)).
46+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
47+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
48+
PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)).
49+
PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)).
5050
VolumeNameSelector(args.VolumeNames).
5151
List(ctx)
5252
for result := range resultCh {

pkg/admin/suspend_drives.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323

2424
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
25-
"github.com/minio/directpv/pkg/utils"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/client-go/util/retry"
2827
)
@@ -58,8 +57,8 @@ func (client *Client) SuspendDrives(ctx context.Context, args SuspendDriveArgs,
5857
defer cancelFunc()
5958

6059
resultCh := client.NewDriveLister().
61-
NodeSelector(utils.ToLabelValues(args.Nodes)).
62-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
60+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
61+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
6362
DriveIDSelector(args.DriveIDSelectors).
6463
List(ctx)
6564
for result := range resultCh {

pkg/admin/suspend_volumes.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
24-
"github.com/minio/directpv/pkg/utils"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625
"k8s.io/client-go/util/retry"
2726
)
@@ -58,10 +57,10 @@ func (client *Client) SuspendVolumes(ctx context.Context, args SuspendVolumeArgs
5857
defer cancelFunc()
5958

6059
resultCh := client.NewVolumeLister().
61-
NodeSelector(utils.ToLabelValues(args.Nodes)).
62-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
63-
PodNameSelector(utils.ToLabelValues(args.PodNames)).
64-
PodNSSelector(utils.ToLabelValues(args.PodNamespaces)).
60+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
61+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
62+
PodNameSelector(directpvtypes.ToLabelValues(args.PodNames)).
63+
PodNSSelector(directpvtypes.ToLabelValues(args.PodNamespaces)).
6564
VolumeNameSelector(args.VolumeNames).
6665
List(ctx)
6766
for result := range resultCh {

pkg/admin/uncordon.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23-
"github.com/minio/directpv/pkg/utils"
23+
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
)
2626

@@ -42,8 +42,8 @@ func (client *Client) Uncordon(ctx context.Context, args UncordonArgs, log LogFu
4242
defer cancelFunc()
4343

4444
resultCh := client.NewDriveLister().
45-
NodeSelector(utils.ToLabelValues(args.Nodes)).
46-
DriveNameSelector(utils.ToLabelValues(args.Drives)).
45+
NodeSelector(directpvtypes.ToLabelValues(args.Nodes)).
46+
DriveNameSelector(directpvtypes.ToLabelValues(args.Drives)).
4747
StatusSelector(args.Status).
4848
DriveIDSelector(args.DriveIDs).
4949
List(ctx)

pkg/apis/directpv.min.io/types/label.go

+8
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ func ToLabelValue(value string) LabelValue {
160160
return result
161161
}
162162

163+
// ToLabelValues converts a string list to label values
164+
func ToLabelValues(slice []string) (values []LabelValue) {
165+
for _, s := range slice {
166+
values = append(values, ToLabelValue(s))
167+
}
168+
return
169+
}
170+
163171
// ToLabelSelector converts a map of label key and label value to selector string
164172
func ToLabelSelector(labels map[LabelKey][]LabelValue) string {
165173
selectors := []string{}

pkg/utils/utils.go

-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strings"
2626

2727
"github.com/fatih/color"
28-
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types"
2928
"sigs.k8s.io/yaml"
3029
)
3130

@@ -158,14 +157,6 @@ func Eprintf(quiet, asErr bool, format string, a ...any) {
158157
fmt.Fprintf(os.Stderr, format, a...)
159158
}
160159

161-
// ToLabelValues converts a string list to label values
162-
func ToLabelValues(slice []string) (values []directpvtypes.LabelValue) {
163-
for _, s := range slice {
164-
values = append(values, directpvtypes.ToLabelValue(s))
165-
}
166-
return
167-
}
168-
169160
// IBytes produces a human readable representation of an IEC size rounding to two decimal places.
170161
func IBytes(ui64 uint64) string {
171162
value := ui64

0 commit comments

Comments
 (0)