@@ -110,7 +110,9 @@ func getNodeProblemDetectorImage() string {
110
110
// puller represents a generic image puller
111
111
type puller interface {
112
112
// Pull pulls an image by name
113
- Pull (image string ) ([]byte , error )
113
+ Pull (ctx context.Context , image string ) ([]byte , error )
114
+ // Remove removes an image by name
115
+ Remove (ctx context.Context , image string ) error
114
116
// Name returns the name of the specific puller implementation
115
117
Name () string
116
118
}
@@ -123,15 +125,19 @@ func (rp *remotePuller) Name() string {
123
125
return "CRI"
124
126
}
125
127
126
- func (rp * remotePuller ) Pull (image string ) ([]byte , error ) {
127
- resp , err := rp .imageService .ImageStatus (context . Background () , & runtimeapi.ImageSpec {Image : image }, false )
128
+ func (rp * remotePuller ) Pull (ctx context. Context , image string ) ([]byte , error ) {
129
+ resp , err := rp .imageService .ImageStatus (ctx , & runtimeapi.ImageSpec {Image : image }, false )
128
130
if err == nil && resp .GetImage () != nil {
129
131
return nil , nil
130
132
}
131
- _ , err = rp .imageService .PullImage (context . Background () , & runtimeapi.ImageSpec {Image : image }, nil , nil )
133
+ _ , err = rp .imageService .PullImage (ctx , & runtimeapi.ImageSpec {Image : image }, nil , nil )
132
134
return nil , err
133
135
}
134
136
137
+ func (rp * remotePuller ) Remove (ctx context.Context , image string ) error {
138
+ return rp .imageService .RemoveImage (ctx , & runtimeapi.ImageSpec {Image : image })
139
+ }
140
+
135
141
func getPuller () (puller , error ) {
136
142
_ , is , err := getCRIClient ()
137
143
if err != nil {
@@ -143,7 +149,7 @@ func getPuller() (puller, error) {
143
149
}
144
150
145
151
// PrePullAllImages pre-fetches all images tests depend on so that we don't fail in an actual test.
146
- func PrePullAllImages () error {
152
+ func PrePullAllImages (ctx context. Context ) error {
147
153
puller , err := getPuller ()
148
154
if err != nil {
149
155
return err
@@ -191,7 +197,7 @@ func PrePullAllImages() error {
191
197
if retryCount > 0 {
192
198
time .Sleep (imagePullRetryDelay )
193
199
}
194
- if output , pullErr = puller .Pull (images [i ]); pullErr == nil {
200
+ if output , pullErr = puller .Pull (ctx , images [i ]); pullErr == nil {
195
201
break
196
202
}
197
203
klog .Warningf ("Failed to pull %s as user %q, retrying in %s (%d of %d): %v" ,
@@ -211,6 +217,14 @@ func PrePullAllImages() error {
211
217
return utilerrors .NewAggregate (pullErrs )
212
218
}
213
219
220
+ func RemoveImage (ctx context.Context , image string ) error {
221
+ puller , err := getPuller ()
222
+ if err != nil {
223
+ return err
224
+ }
225
+ return puller .Remove (ctx , image )
226
+ }
227
+
214
228
func getContainerImageFromE2ETestDaemonset (dsYamlPath string ) (string , error ) {
215
229
data , err := e2etestfiles .Read (dsYamlPath )
216
230
if err != nil {
0 commit comments