(&self, sandbox_id: &str, image: &str)
| 1309 | } |
| 1310 | |
| 1311 | async fn ensure_image_available(&self, sandbox_id: &str, image: &str) -> Result<(), Status> { |
| 1312 | let policy = self.config.image_pull_policy.trim().to_ascii_lowercase(); |
| 1313 | match policy.as_str() { |
| 1314 | "" | "ifnotpresent" => { |
| 1315 | if self.docker.inspect_image(image).await.is_ok() { |
| 1316 | self.publish_docker_progress( |
| 1317 | sandbox_id, |
| 1318 | "ImagePresent", |
| 1319 | format!("Docker image \"{image}\" is already present"), |
| 1320 | HashMap::from([("image_ref".to_string(), image.to_string())]), |
| 1321 | ); |
| 1322 | return Ok(()); |
| 1323 | } |
| 1324 | self.pull_image(sandbox_id, image).await |
| 1325 | } |
| 1326 | "always" => self.pull_image(sandbox_id, image).await, |
| 1327 | "never" => match self.docker.inspect_image(image).await { |
| 1328 | Ok(_) => { |
| 1329 | self.publish_docker_progress( |
| 1330 | sandbox_id, |
| 1331 | "ImagePresent", |
| 1332 | format!("Docker image \"{image}\" is already present"), |
| 1333 | HashMap::from([("image_ref".to_string(), image.to_string())]), |
| 1334 | ); |
| 1335 | Ok(()) |
| 1336 | } |
| 1337 | Err(err) if is_not_found_error(&err) => Err(Status::failed_precondition(format!( |
| 1338 | "docker image '{image}' is not present locally and image_pull_policy=Never" |
| 1339 | ))), |
| 1340 | Err(err) => Err(internal_status("inspect Docker image", err)), |
| 1341 | }, |
| 1342 | other => Err(Status::failed_precondition(format!( |
| 1343 | "unsupported docker image_pull_policy '{other}'; expected Always, IfNotPresent, or Never", |
| 1344 | ))), |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | async fn pull_image(&self, sandbox_id: &str, image: &str) -> Result<(), Status> { |
| 1349 | self.publish_docker_progress( |
no test coverage detected