(ctx context.Context, name string, credentials func(string) (string, string, error), sandboxConfig *runtime.PodSandboxConfig, runtimeHandler string)
| 121 | } |
| 122 | |
| 123 | func (c *CRIImageService) PullImage(ctx context.Context, name string, credentials func(string) (string, string, error), sandboxConfig *runtime.PodSandboxConfig, runtimeHandler string) (_ string, err error) { |
| 124 | span := tracing.SpanFromContext(ctx) |
| 125 | defer func() { |
| 126 | // TODO: add domain label for imagePulls metrics, and we may need to provide a mechanism |
| 127 | // for the user to configure the set of registries that they are interested in. |
| 128 | if err != nil { |
| 129 | imagePulls.WithValues("failure").Inc() |
| 130 | } else { |
| 131 | imagePulls.WithValues("success").Inc() |
| 132 | } |
| 133 | }() |
| 134 | |
| 135 | inProgressImagePulls.Inc() |
| 136 | defer inProgressImagePulls.Dec() |
| 137 | startTime := time.Now() |
| 138 | |
| 139 | if credentials == nil { |
| 140 | credentials = func(host string) (string, string, error) { |
| 141 | var hostauth *runtime.AuthConfig |
| 142 | |
| 143 | config := c.config.Registry.Configs[host] |
| 144 | if config.Auth != nil { |
| 145 | hostauth = toRuntimeAuthConfig(*config.Auth) |
| 146 | |
| 147 | } |
| 148 | |
| 149 | return ParseAuth(hostauth, host) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | namedRef, err := distribution.ParseDockerRef(name) |
| 154 | if err != nil { |
| 155 | return "", fmt.Errorf("failed to parse image reference %q: %w", name, err) |
| 156 | } |
| 157 | |
| 158 | ref := namedRef.String() |
| 159 | if ref != name { |
| 160 | log.G(ctx).Debugf("PullImage using normalized image ref: %q", ref) |
| 161 | } |
| 162 | |
| 163 | imagePullProgressTimeout, err := time.ParseDuration(c.config.ImagePullProgressTimeout) |
| 164 | if err != nil { |
| 165 | return "", fmt.Errorf("failed to parse image_pull_progress_timeout %q: %w", c.config.ImagePullProgressTimeout, err) |
| 166 | } |
| 167 | |
| 168 | snapshotter, err := c.snapshotterFromPodSandboxConfig(ctx, ref, sandboxConfig, runtimeHandler) |
| 169 | if err != nil { |
| 170 | return "", err |
| 171 | } |
| 172 | |
| 173 | span.SetAttributes( |
| 174 | tracing.Attribute("image.ref", ref), |
| 175 | tracing.Attribute("snapshotter.name", snapshotter), |
| 176 | ) |
| 177 | labels := c.getLabels(ctx, ref) |
| 178 | |
| 179 | // If UseLocalImagePull is true, use client.Pull to pull the image, else use transfer service by default. |
| 180 | // |
nothing calls this directly
no test coverage detected