Skip to content

Commit 5f40b65

Browse files
authored
Merge pull request kubernetes-sigs#2100 from saschagrunert/cleanup/dedup-pull-flags
crictl: deduplicate pull-related CLI flags
2 parents 929c478 + 4d8700e commit 5f40b65

2 files changed

Lines changed: 34 additions & 49 deletions

File tree

cmd/crictl/container.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,6 @@ type pullOptions struct {
8484
timeout time.Duration
8585
}
8686

87-
var pullFlags = []cli.Flag{
88-
&cli.StringFlag{
89-
Name: "creds",
90-
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
91-
},
92-
&cli.StringFlag{
93-
Name: "auth",
94-
Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'",
95-
},
96-
&cli.StringFlag{
97-
Name: "username",
98-
Usage: "Use `USERNAME` for accessing the registry. The password will be requested on the command line",
99-
},
100-
&cli.DurationFlag{
101-
Name: "cancel-timeout",
102-
Aliases: []string{"T"},
103-
Usage: "Seconds to wait for the request to complete before cancelling",
104-
},
105-
&cli.DurationFlag{
106-
Name: "pull-timeout",
107-
Aliases: []string{"pt"},
108-
Usage: "Maximum time to be used for pulling the image, disabled if set to 0s",
109-
EnvVars: []string{"CRICTL_PULL_TIMEOUT"},
110-
},
111-
}
112-
11387
var createPullFlags = append([]cli.Flag{
11488
&cli.BoolFlag{
11589
Name: "no-pull",
@@ -119,6 +93,7 @@ var createPullFlags = append([]cli.Flag{
11993
Name: "with-pull",
12094
Usage: "Pull the image on container creation (overrides pull-image-on-create=false in config)",
12195
},
96+
cancelTimeoutFlag,
12297
}, pullFlags...)
12398

12499
var runPullFlags = append([]cli.Flag{
@@ -135,6 +110,7 @@ var runPullFlags = append([]cli.Flag{
135110
Aliases: []string{"r"},
136111
Usage: "Runtime handler to use. Available options are defined by the container runtime.",
137112
},
113+
cancelTimeoutFlag,
138114
}, pullFlags...)
139115

140116
var subcommands = []*cli.Command{{

cmd/crictl/image.go

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,41 @@ import (
3636
pb "k8s.io/cri-api/pkg/apis/runtime/v1"
3737
)
3838

39+
var pullFlags = []cli.Flag{
40+
&cli.StringFlag{
41+
Name: "creds",
42+
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
43+
EnvVars: []string{"CRICTL_CREDS"},
44+
},
45+
&cli.StringFlag{
46+
Name: "auth",
47+
Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'",
48+
EnvVars: []string{"CRICTL_AUTH"},
49+
},
50+
&cli.StringFlag{
51+
Name: "username",
52+
Aliases: []string{"u"},
53+
Usage: "Use `USERNAME` for accessing the registry. The password will be requested on the command line",
54+
},
55+
&cli.DurationFlag{
56+
Name: "pull-timeout",
57+
Aliases: []string{"pt"},
58+
Usage: "Maximum time to be used for pulling the image, disabled if set to 0s",
59+
EnvVars: []string{"CRICTL_PULL_TIMEOUT"},
60+
},
61+
}
62+
63+
var cancelTimeoutFlag = &cli.DurationFlag{
64+
Name: "cancel-timeout",
65+
Aliases: []string{"T"},
66+
Usage: "Seconds to wait for the request to complete before cancelling",
67+
}
68+
3969
var pullImageCommand = &cli.Command{
4070
Name: "pull",
4171
Usage: "Pull an image from a registry",
4272
UseShortOptionHandling: true,
43-
Flags: []cli.Flag{
44-
&cli.StringFlag{
45-
Name: "creds",
46-
Usage: "Use `USERNAME[:PASSWORD]` for accessing the registry",
47-
EnvVars: []string{"CRICTL_CREDS"},
48-
},
49-
&cli.StringFlag{
50-
Name: "auth",
51-
Usage: "Use `AUTH_STRING` for accessing the registry. AUTH_STRING is a base64 encoded 'USERNAME[:PASSWORD]'",
52-
EnvVars: []string{"CRICTL_AUTH"},
53-
},
54-
&cli.StringFlag{
55-
Name: "username",
56-
Aliases: []string{"u"},
57-
Usage: "Use `USERNAME` for accessing the registry. The password will be requested on the command line",
58-
},
73+
Flags: append([]cli.Flag{
5974
&cli.StringFlag{
6075
Name: "pod-config",
6176
Usage: "Use `pod-config.[json|yaml]` to override the pull c",
@@ -66,13 +81,7 @@ var pullImageCommand = &cli.Command{
6681
Aliases: []string{"a"},
6782
Usage: "Annotation to be set on the pulled image",
6883
},
69-
&cli.DurationFlag{
70-
Name: "pull-timeout",
71-
Aliases: []string{"pt"},
72-
Usage: "Maximum time to be used for pulling the image, disabled if set to 0s",
73-
EnvVars: []string{"CRICTL_PULL_TIMEOUT"},
74-
},
75-
},
84+
}, pullFlags...),
7685
Subcommands: []*cli.Command{{
7786
Name: "jsonschema",
7887
Aliases: []string{"js"},

0 commit comments

Comments
 (0)