Skip to content

Commit be4311f

Browse files
committed
chore: migrating to urfave v3
Signed-off-by: Arturo Fernandez <134515+bsnux@users.noreply.github.com>
1 parent dc835ef commit be4311f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+82
-11533
lines changed

cmd/gpuop-cfg/main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package main
1818

1919
import (
20+
"context"
2021
"os"
2122

2223
log "github.com/sirupsen/logrus"
23-
cli "github.com/urfave/cli/v2"
24+
cli "github.com/urfave/cli/v3"
2425

2526
"github.com/NVIDIA/gpu-operator/cmd/gpuop-cfg/validate"
2627
)
@@ -35,7 +36,7 @@ func main() {
3536
config := config{}
3637

3738
// Create the top-level CLI
38-
c := cli.NewApp()
39+
c := cli.Command{}
3940
c.Name = "gpuop-cfg"
4041
c.Usage = "Tools for managing and verifying configuration files for NVIDIA GPU Operator"
4142
c.Version = "0.1.0"
@@ -47,26 +48,27 @@ func main() {
4748
Aliases: []string{"d"},
4849
Usage: "Enable debug-level logging",
4950
Destination: &config.Debug,
50-
EnvVars: []string{"DEBUG"},
51+
Sources: cli.EnvVars("DEBUG"),
5152
},
5253
}
5354

5455
// Set log-level for all subcommands
55-
c.Before = func(c *cli.Context) error {
56+
c.Before = func(ctx context.Context, cli *cli.Command) (context.Context, error) {
5657
logLevel := log.InfoLevel
5758
if config.Debug {
5859
logLevel = log.DebugLevel
5960
}
6061
logger.SetLevel(logLevel)
61-
return nil
62+
63+
return ctx, nil
6264
}
6365

6466
// Define the subcommands
6567
c.Commands = []*cli.Command{
6668
validate.NewCommand(logger),
6769
}
6870

69-
err := c.Run(os.Args)
71+
err := c.Run(context.Background(), os.Args)
7072
if err != nil {
7173
log.Errorf("%v", err)
7274
log.Exit(1)

cmd/gpuop-cfg/validate/clusterpolicy/clusterpolicy.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
package clusterpolicy
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"io"
2223
"os"
2324

2425
"github.com/sirupsen/logrus"
25-
"github.com/urfave/cli/v2"
26+
"github.com/urfave/cli/v3"
2627
"sigs.k8s.io/yaml"
2728

2829
v1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
@@ -52,10 +53,10 @@ func (m command) build() *cli.Command {
5253
c := cli.Command{
5354
Name: "clusterpolicy",
5455
Usage: "Validate clusterpolicy",
55-
Before: func(c *cli.Context) error {
56-
return m.validateFlags(c, &opts)
56+
Before: func(c context.Context, cli *cli.Command) (context.Context, error) {
57+
return c, m.validateFlags(c, &opts)
5758
},
58-
Action: func(c *cli.Context) error {
59+
Action: func(c context.Context, cli *cli.Command) error {
5960
return m.run(c, &opts)
6061
},
6162
}
@@ -72,17 +73,17 @@ func (m command) build() *cli.Command {
7273
return &c
7374
}
7475

75-
func (m command) validateFlags(c *cli.Context, opts *options) error {
76+
func (m command) validateFlags(ctx context.Context, opts *options) error {
7677
return nil
7778
}
7879

79-
func (m command) run(c *cli.Context, opts *options) error {
80+
func (m command) run(ctx context.Context, opts *options) error {
8081
cp, err := opts.load()
8182
if err != nil {
8283
return fmt.Errorf("failed to load clusterpolicy spec: %v", err)
8384
}
8485

85-
err = validateImages(c.Context, &cp.Spec)
86+
err = validateImages(ctx, &cp.Spec)
8687
if err != nil {
8788
return fmt.Errorf("failed to validate images: %v", err)
8889
}

cmd/gpuop-cfg/validate/csv/csv.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package csv
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"io"
2223
"os"
2324

2425
"github.com/operator-framework/api/pkg/operators/v1alpha1"
2526
"github.com/sirupsen/logrus"
26-
"github.com/urfave/cli/v2"
27+
"github.com/urfave/cli/v3"
2728
"sigs.k8s.io/yaml"
2829
)
2930

@@ -51,10 +52,10 @@ func (m command) build() *cli.Command {
5152
c := cli.Command{
5253
Name: "csv",
5354
Usage: "Validate csv",
54-
Before: func(c *cli.Context) error {
55-
return m.validateFlags(c, &opts)
55+
Before: func(c context.Context, cli *cli.Command) (context.Context, error) {
56+
return c, m.validateFlags(c, &opts)
5657
},
57-
Action: func(c *cli.Context) error {
58+
Action: func(c context.Context, cli *cli.Command) error {
5859
return m.run(c, &opts)
5960
},
6061
}
@@ -71,17 +72,17 @@ func (m command) build() *cli.Command {
7172
return &c
7273
}
7374

74-
func (m command) validateFlags(c *cli.Context, opts *options) error {
75+
func (m command) validateFlags(ctx context.Context, opts *options) error {
7576
return nil
7677
}
7778

78-
func (m command) run(c *cli.Context, opts *options) error {
79+
func (m command) run(ctx context.Context, opts *options) error {
7980
csv, err := opts.load()
8081
if err != nil {
8182
return fmt.Errorf("failed to load csv yaml: %v", err)
8283
}
8384

84-
err = validateImages(c.Context, csv)
85+
err = validateImages(ctx, csv)
8586
if err != nil {
8687
return fmt.Errorf("failed to validate images: %v", err)
8788
}

cmd/gpuop-cfg/validate/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package validate
1818

1919
import (
2020
"github.com/sirupsen/logrus"
21-
cli "github.com/urfave/cli/v2"
21+
cli "github.com/urfave/cli/v3"
2222

2323
"github.com/NVIDIA/gpu-operator/cmd/gpuop-cfg/validate/clusterpolicy"
2424
"github.com/NVIDIA/gpu-operator/cmd/gpuop-cfg/validate/csv"
@@ -43,7 +43,7 @@ func (m command) build() *cli.Command {
4343
Usage: "Perform various validations for GPU Operator configuration files",
4444
}
4545

46-
validate.Subcommands = []*cli.Command{
46+
validate.Commands = []*cli.Command{
4747
csv.NewCommand(m.logger),
4848
clusterpolicy.NewCommand(m.logger),
4949
}

cmd/manage-crds/main.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
"github.com/NVIDIA/k8s-operator-libs/pkg/crdutil"
2525
log "github.com/sirupsen/logrus"
26-
"github.com/urfave/cli/v2"
26+
"github.com/urfave/cli/v3"
2727

2828
"github.com/NVIDIA/gpu-operator/internal/info"
2929
)
@@ -32,16 +32,14 @@ var logger = log.New()
3232

3333
type config struct {
3434
Debug bool
35-
crdsPaths *cli.StringSlice
35+
crdsPaths []string
3636
}
3737

3838
func main() {
39-
config := config{
40-
crdsPaths: cli.NewStringSlice(),
41-
}
39+
config := config{}
4240

4341
// Create the top-level CLI
44-
c := cli.NewApp()
42+
c := cli.Command{}
4543
c.Name = "manage-crds"
4644
c.Usage = "Tools for managing Custom Resource Definitions (CRDs) for NVIDIA GPU Operator"
4745
c.Version = info.GetVersionString()
@@ -53,18 +51,18 @@ func main() {
5351
Aliases: []string{"d"},
5452
Usage: "Enable debug-level logging",
5553
Destination: &config.Debug,
56-
EnvVars: []string{"DEBUG"},
54+
Sources: cli.EnvVars("DEBUG"),
5755
},
5856
}
5957

6058
// Set log-level for all subcommands
61-
c.Before = func(c *cli.Context) error {
59+
c.Before = func(ctx context.Context, cli *cli.Command) (context.Context, error) {
6260
logLevel := log.InfoLevel
6361
if config.Debug {
6462
logLevel = log.DebugLevel
6563
}
6664
logger.SetLevel(logLevel)
67-
return nil
65+
return ctx, nil
6866
}
6967

7068
// Common flags for both apply and delete subcommands
@@ -74,7 +72,7 @@ func main() {
7472
Aliases: []string{"f"},
7573
Usage: "Path to CRD manifest file or directory (can be specified multiple times, directories are searched recursively)",
7674
Required: true,
77-
Destination: config.crdsPaths,
75+
Destination: &config.crdsPaths,
7876
},
7977
}
8078

@@ -84,29 +82,29 @@ func main() {
8482
Name: "apply",
8583
Usage: "Apply CRDs from the specified path",
8684
Flags: commonFlags,
87-
Action: func(c *cli.Context) error {
88-
return runApply(c.Context, config)
85+
Action: func(ctx context.Context, cli *cli.Command) error {
86+
return runApply(ctx, config)
8987
},
9088
},
9189
{
9290
Name: "delete",
9391
Usage: "Delete CRDs from the specified path",
9492
Flags: commonFlags,
95-
Action: func(c *cli.Context) error {
96-
return runDelete(c.Context, config)
93+
Action: func(ctx context.Context, cli *cli.Command) error {
94+
return runDelete(ctx, config)
9795
},
9896
},
9997
}
10098

101-
err := c.Run(os.Args)
99+
err := c.Run(context.Background(), os.Args)
102100
if err != nil {
103101
log.Errorf("%v", err)
104102
log.Exit(1)
105103
}
106104
}
107105

108106
func runApply(ctx context.Context, cfg config) error {
109-
paths := cfg.crdsPaths.Value()
107+
paths := cfg.crdsPaths
110108
logger.Infof("Applying CRDs from %d path(s): %v", len(paths), paths)
111109

112110
if err := crdutil.ProcessCRDs(ctx, crdutil.CRDOperationApply, paths...); err != nil {
@@ -118,7 +116,7 @@ func runApply(ctx context.Context, cfg config) error {
118116
}
119117

120118
func runDelete(ctx context.Context, cfg config) error {
121-
paths := cfg.crdsPaths.Value()
119+
paths := cfg.crdsPaths
122120
logger.Infof("Deleting CRDs from %d path(s): %v", len(paths), paths)
123121

124122
if err := crdutil.ProcessCRDs(ctx, crdutil.CRDOperationDelete, paths...); err != nil {

0 commit comments

Comments
 (0)