@@ -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,29 @@ 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
+ },
159
+ & cli.DurationFlag {
160
+ Name : "timeout" ,
161
+ Aliases : []string {"t" },
162
+ Usage : "Seconds to wait for a container create request before cancelling the request" ,
163
+ },
164
+ & cli.DurationFlag {
165
+ Name : "pull-timeout" ,
166
+ Aliases : []string {"pt" },
167
+ Usage : "Maximum time to be used for pulling the image, disabled if set to 0s" ,
168
+ EnvVars : []string {"CRICTL_PULL_TIMEOUT" },
169
+ },
140
170
}
141
171
142
172
var createContainerCommand = & cli.Command {
143
173
Name : "create" ,
144
174
Usage : "Create a new container" ,
145
175
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
- }),
176
+ Flags : createPullFlags ,
151
177
152
178
Action : func (c * cli.Context ) (err error ) {
153
179
if c .Args ().Len () != 3 {
@@ -177,6 +203,7 @@ var createContainerCommand = &cli.Command{
177
203
creds : c .String ("creds" ),
178
204
auth : c .String ("auth" ),
179
205
username : c .String ("username" ),
206
+ timeout : c .Duration ("pull-timeout" ),
180
207
},
181
208
timeout : c .Duration ("cancel-timeout" ),
182
209
},
@@ -581,15 +608,7 @@ var runContainerCommand = &cli.Command{
581
608
Name : "run" ,
582
609
Usage : "Run a new container inside a sandbox" ,
583
610
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
- }),
611
+ Flags : runPullFlags ,
593
612
594
613
Action : func (c * cli.Context ) (err error ) {
595
614
if c .Args ().Len () != 2 {
@@ -617,6 +636,7 @@ var runContainerCommand = &cli.Command{
617
636
creds : c .String ("creds" ),
618
637
auth : c .String ("auth" ),
619
638
username : c .String ("username" ),
639
+ timeout : c .Duration ("pull-timeout" ),
620
640
},
621
641
timeout : c .Duration ("timeout" ),
622
642
}
@@ -747,7 +767,7 @@ func CreateContainer(
747
767
748
768
// Try to pull the image before container creation
749
769
ann := config .GetImage ().GetAnnotations ()
750
- if _ , err := PullImageWithSandbox (iClient , image , auth , podConfig , ann ); err != nil {
770
+ if _ , err := PullImageWithSandbox (iClient , image , auth , podConfig , ann , opts . pullOptions . timeout ); err != nil {
751
771
return "" , err
752
772
}
753
773
}
0 commit comments