@@ -85,6 +85,9 @@ type pullOptions struct {
85
85
// Username to use for accessing the registry
86
86
// password will be requested on the command line
87
87
username string
88
+
89
+ // timeout is the maximum time used for the image pull
90
+ timeout time.Duration
88
91
}
89
92
90
93
var createPullFlags = []cli.Flag {
@@ -111,6 +114,17 @@ var createPullFlags = []cli.Flag{
111
114
Value : "" ,
112
115
Usage : "Use `USERNAME` for accessing the registry. The password will be requested on the command line" ,
113
116
},
117
+ & cli.DurationFlag {
118
+ Name : "cancel-timeout" ,
119
+ Aliases : []string {"T" },
120
+ Usage : "Seconds to wait for a container create request to complete before cancelling the request" ,
121
+ },
122
+ & cli.DurationFlag {
123
+ Name : "pull-timeout" ,
124
+ Aliases : []string {"pt" },
125
+ Usage : "Maximum time to be used for pulling the image, disabled if set to 0s" ,
126
+ EnvVars : []string {"CRICTL_PULL_TIMEOUT" },
127
+ },
114
128
}
115
129
116
130
var runPullFlags = []cli.Flag {
@@ -137,17 +151,28 @@ var runPullFlags = []cli.Flag{
137
151
Value : "" ,
138
152
Usage : "Use `USERNAME` for accessing the registry. password will be requested" ,
139
153
},
154
+ & cli.StringFlag {
155
+ Name : "runtime" ,
156
+ Aliases : []string {"r" },
157
+ Usage : "Runtime handler to use. Available options are defined by the container runtime." ,
158
+ }, & cli.DurationFlag {
159
+ Name : "timeout" ,
160
+ Aliases : []string {"t" },
161
+ Usage : "Seconds to wait for a container create request before cancelling the request" ,
162
+ },
163
+ & cli.DurationFlag {
164
+ Name : "pull-timeout" ,
165
+ Aliases : []string {"pt" },
166
+ Usage : "Maximum time to be used for pulling the image, disabled if set to 0s" ,
167
+ EnvVars : []string {"CRICTL_PULL_TIMEOUT" },
168
+ },
140
169
}
141
170
142
171
var createContainerCommand = & cli.Command {
143
172
Name : "create" ,
144
173
Usage : "Create a new container" ,
145
174
ArgsUsage : "POD container-config.[json|yaml] pod-config.[json|yaml]" ,
146
- Flags : append (createPullFlags , & cli.DurationFlag {
147
- Name : "cancel-timeout" ,
148
- Aliases : []string {"T" },
149
- Usage : "Seconds to wait for a container create request to complete before cancelling the request" ,
150
- }),
175
+ Flags : createPullFlags ,
151
176
152
177
Action : func (c * cli.Context ) (err error ) {
153
178
if c .Args ().Len () != 3 {
@@ -177,6 +202,7 @@ var createContainerCommand = &cli.Command{
177
202
creds : c .String ("creds" ),
178
203
auth : c .String ("auth" ),
179
204
username : c .String ("username" ),
205
+ timeout : c .Duration ("pull-timeout" ),
180
206
},
181
207
timeout : c .Duration ("cancel-timeout" ),
182
208
},
@@ -581,15 +607,7 @@ var runContainerCommand = &cli.Command{
581
607
Name : "run" ,
582
608
Usage : "Run a new container inside a sandbox" ,
583
609
ArgsUsage : "container-config.[json|yaml] pod-config.[json|yaml]" ,
584
- Flags : append (runPullFlags , & cli.StringFlag {
585
- Name : "runtime" ,
586
- Aliases : []string {"r" },
587
- Usage : "Runtime handler to use. Available options are defined by the container runtime." ,
588
- }, & cli.DurationFlag {
589
- Name : "timeout" ,
590
- Aliases : []string {"t" },
591
- Usage : "Seconds to wait for a container create request before cancelling the request" ,
592
- }),
610
+ Flags : runPullFlags ,
593
611
594
612
Action : func (c * cli.Context ) (err error ) {
595
613
if c .Args ().Len () != 2 {
@@ -617,6 +635,7 @@ var runContainerCommand = &cli.Command{
617
635
creds : c .String ("creds" ),
618
636
auth : c .String ("auth" ),
619
637
username : c .String ("username" ),
638
+ timeout : c .Duration ("pull-timeout" ),
620
639
},
621
640
timeout : c .Duration ("timeout" ),
622
641
}
@@ -747,7 +766,7 @@ func CreateContainer(
747
766
748
767
// Try to pull the image before container creation
749
768
ann := config .GetImage ().GetAnnotations ()
750
- if _ , err := PullImageWithSandbox (iClient , image , auth , podConfig , ann ); err != nil {
769
+ if _ , err := PullImageWithSandbox (iClient , image , auth , podConfig , ann , opts . pullOptions . timeout ); err != nil {
751
770
return "" , err
752
771
}
753
772
}
0 commit comments