mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
Kubelet: Use RepoDigest for ImageID when available
Previously, we used the docker config digest (also called "image ID" by Docker) for the value of the `ImageID` field in the container status. This was not particularly useful, since the config manifest is not what's used to identify the image in a registry, which uses the manifest digest instead. Docker 1.12+ always populates the RepoDigests field with the manifest digests, and Docker 1.10 and 1.11 populate it when images are pulled by digest. This commit changes `ImageID` to point to the the manifest digest when available, using the prefix `docker-pullable://` (instead of `docker://`)
This commit is contained in:
@@ -397,11 +397,26 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
parseTimestampError("FinishedAt", iResult.State.FinishedAt)
|
||||
}
|
||||
|
||||
// default to the image ID, but try and inspect for the RepoDigests
|
||||
imageID := DockerPrefix + iResult.Image
|
||||
imgInspectResult, err := dm.client.InspectImageByID(iResult.Image)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("unable to inspect docker image %q while inspecting docker container %q: %v", containerName, iResult.Image, err))
|
||||
} else {
|
||||
if len(imgInspectResult.RepoDigests) > 1 {
|
||||
glog.V(4).Infof("Container %q had more than one associated RepoDigest (%v), only using the first", containerName, imgInspectResult.RepoDigests)
|
||||
}
|
||||
|
||||
if len(imgInspectResult.RepoDigests) > 0 {
|
||||
imageID = DockerPullablePrefix + imgInspectResult.RepoDigests[0]
|
||||
}
|
||||
}
|
||||
|
||||
status := kubecontainer.ContainerStatus{
|
||||
Name: containerName,
|
||||
RestartCount: containerInfo.RestartCount,
|
||||
Image: iResult.Config.Image,
|
||||
ImageID: DockerPrefix + iResult.Image,
|
||||
ImageID: imageID,
|
||||
ID: kubecontainer.DockerID(id).ContainerID(),
|
||||
ExitCode: iResult.State.ExitCode,
|
||||
CreatedAt: createdAt,
|
||||
|
||||
Reference in New Issue
Block a user