Unverified Commit ad437c2c authored by Medya Ghazizadeh's avatar Medya Ghazizadeh Committed by GitHub

Merge pull request #8229 from afbjorklund/docker-inspect

kic: explicitly provide the type in inspect commands
parents f26ea0fc 14937e46
Pipeline #148483433 passed with stage
in 3 minutes and 14 seconds
......@@ -572,7 +572,7 @@ out/docker-machine-driver-kvm2-aarch64: out/docker-machine-driver-kvm2-arm64
out/docker-machine-driver-kvm2-%:
ifeq ($(MINIKUBE_BUILD_IN_DOCKER),y)
docker inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image
docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image
$(call DOCKER,$(KVM_BUILD_IMAGE),/usr/bin/make [email protected] COMMIT=$(COMMIT))
# make extra sure that we are linking with the older version of libvirt (1.3.1)
test "`strings [email protected] | grep '^LIBVIRT_[0-9]' | sort | tail -n 1`" = "LIBVIRT_1.2.9"
......@@ -619,7 +619,7 @@ kvm-image: installers/linux/kvm/Dockerfile ## Convenient alias to build the doc
@echo "$(@) successfully built"
kvm_in_docker:
docker inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image
docker image inspect -f '{{.Id}} {{.RepoTags}}' $(KVM_BUILD_IMAGE) || $(MAKE) kvm-image
rm -f out/docker-machine-driver-kvm2
$(call DOCKER,$(KVM_BUILD_IMAGE),/usr/bin/make out/docker-machine-driver-kvm2 COMMIT=$(COMMIT))
......
......@@ -67,7 +67,7 @@ func dockerGatewayIP() (net.IP, error) {
}
bridgeID := strings.TrimSpace(rr.Stdout.String())
rr, err = runCmd(exec.Command(Docker, "inspect",
rr, err = runCmd(exec.Command(Docker, "network", "inspect",
"--format", "{{(index .IPAM.Config 0).Gateway}}", bridgeID))
if err != nil {
return nil, errors.Wrapf(err, "inspect IP bridge network %q.", bridgeID)
......@@ -80,7 +80,7 @@ func dockerGatewayIP() (net.IP, error) {
// containerGatewayIP gets the default gateway ip for the container
func containerGatewayIP(ociBin, containerName string) (net.IP, error) {
rr, err := runCmd(exec.Command(ociBin, "inspect", "--format", "{{.NetworkSettings.Gateway}}", containerName))
rr, err := runCmd(exec.Command(ociBin, "container", "inspect", "--format", "{{.NetworkSettings.Gateway}}", containerName))
if err != nil {
return nil, errors.Wrapf(err, "inspect gateway")
}
......@@ -98,13 +98,12 @@ func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
var err error
if ociBin == Podman {
//podman inspect -f "{{range .NetworkSettings.Ports}}{{if eq .ContainerPort "80"}}{{.HostPort}}{{end}}{{end}}"
rr, err = runCmd(exec.Command(ociBin, "inspect", "-f", fmt.Sprintf("{{range .NetworkSettings.Ports}}{{if eq .ContainerPort %s}}{{.HostPort}}{{end}}{{end}}", fmt.Sprint(contPort)), ociID))
rr, err = runCmd(exec.Command(ociBin, "container", "inspect", "-f", fmt.Sprintf("{{range .NetworkSettings.Ports}}{{if eq .ContainerPort %s}}{{.HostPort}}{{end}}{{end}}", fmt.Sprint(contPort)), ociID))
if err != nil {
return 0, errors.Wrapf(err, "get port %d for %q", contPort, ociID)
}
} else {
rr, err = runCmd(exec.Command(ociBin, "inspect", "-f", fmt.Sprintf("'{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}'", contPort), ociID))
rr, err = runCmd(exec.Command(ociBin, "container", "inspect", "-f", fmt.Sprintf("'{{(index (index .NetworkSettings.Ports \"%d/tcp\") 0).HostPort}}'", contPort), ociID))
if err != nil {
return 0, errors.Wrapf(err, "get port %d for %q", contPort, ociID)
}
......@@ -124,14 +123,14 @@ func ForwardedPort(ociBin string, ociID string, contPort int) (int, error) {
// ContainerIPs returns ipv4,ipv6, error of a container by their name
func ContainerIPs(ociBin string, name string) (string, string, error) {
if ociBin == Podman {
return podmanConttainerIP(name)
return podmanContainerIP(name)
}
return dockerContainerIP(name)
}
// podmanConttainerIP returns ipv4, ipv6 of container or error
func podmanConttainerIP(name string) (string, string, error) {
rr, err := runCmd(exec.Command(Podman, "inspect",
// podmanContainerIP returns ipv4, ipv6 of container or error
func podmanContainerIP(name string) (string, string, error) {
rr, err := runCmd(exec.Command(Podman, "container", "inspect",
"-f", "{{.NetworkSettings.IPAddress}}",
name))
if err != nil {
......
......@@ -277,7 +277,7 @@ func StartContainer(ociBin string, container string) error {
// ContainerID returns id of a container name
func ContainerID(ociBin string, nameOrID string) (string, error) {
rr, err := runCmd(exec.Command(ociBin, "inspect", "-f", "{{.Id}}", nameOrID))
rr, err := runCmd(exec.Command(ociBin, "container", "inspect", "-f", "{{.Id}}", nameOrID))
if err != nil { // don't return error if not found, only return empty string
if strings.Contains(rr.Stdout.String(), "Error: No such object:") || strings.Contains(rr.Stdout.String(), "unable to find") {
err = nil
......@@ -307,7 +307,7 @@ func ContainerExists(ociBin string, name string, warnSlow ...bool) (bool, error)
// IsCreatedByMinikube returns true if the container was created by minikube
// with default assumption that it is not created by minikube when we don't know for sure
func IsCreatedByMinikube(ociBin string, nameOrID string) bool {
rr, err := runCmd(exec.Command(ociBin, "inspect", nameOrID, "--format", "{{.Config.Labels}}"))
rr, err := runCmd(exec.Command(ociBin, "container", "inspect", nameOrID, "--format", "{{.Config.Labels}}"))
if err != nil {
return false
}
......@@ -326,7 +326,7 @@ func ListOwnedContainers(ociBin string) ([]string, error) {
// inspect return low-level information on containers
func inspect(ociBin string, containerNameOrID, format string) ([]string, error) {
cmd := exec.Command(ociBin, "inspect",
cmd := exec.Command(ociBin, "container", "inspect",
"-f", format,
containerNameOrID) // ... against the "node" container
var buff bytes.Buffer
......@@ -506,7 +506,7 @@ func PointToHostPodman() error {
// ContainerRunning returns running state of a container
func ContainerRunning(ociBin string, name string, warnSlow ...bool) (bool, error) {
rr, err := runCmd(exec.Command(ociBin, "inspect", name, "--format={{.State.Running}}"), warnSlow...)
rr, err := runCmd(exec.Command(ociBin, "container", "inspect", name, "--format={{.State.Running}}"), warnSlow...)
if err != nil {
return false, err
}
......@@ -515,7 +515,7 @@ func ContainerRunning(ociBin string, name string, warnSlow ...bool) (bool, error
// ContainerStatus returns status of a container running,exited,...
func ContainerStatus(ociBin string, name string, warnSlow ...bool) (state.State, error) {
cmd := exec.Command(ociBin, "inspect", name, "--format={{.State.Status}}")
cmd := exec.Command(ociBin, "container", "inspect", name, "--format={{.State.Status}}")
rr, err := runCmd(cmd, warnSlow...)
o := strings.TrimSpace(rr.Stdout.String())
switch o {
......
......@@ -136,7 +136,7 @@ func (r *CRIO) Disable() error {
// ImageExists checks if an image exists
func (r *CRIO) ImageExists(name string, sha string) bool {
// expected output looks like [[email protected]:SHA]
c := exec.Command("sudo", "podman", "inspect", "--format", "{{.Id}}", name)
c := exec.Command("sudo", "podman", "image", "inspect", "--format", "{{.Id}}", name)
rr, err := r.Runner.RunCmd(c)
if err != nil {
return false
......
......@@ -267,6 +267,16 @@ func (f *FakeRunner) dockerRm(args []string) (string, error) {
return "", nil
}
func (f *FakeRunner) dockerInspect(args []string) (string, error) {
if args[1] == "--format" && args[2] == "{{.Id}}" {
if args[3] == "missing" {
return "", &exec.ExitError{Stderr: []byte("Error: No such object: missing")}
}
return "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", nil
}
return "", nil
}
// docker is a fake implementation of docker
func (f *FakeRunner) docker(args []string, _ bool) (string, error) {
switch cmd := args[0]; cmd {
......@@ -285,15 +295,14 @@ func (f *FakeRunner) docker(args []string, _ bool) (string, error) {
return "18.06.2-ce", nil
}
case "inspect":
if args[1] == "--format" && args[2] == "{{.Id}}" {
if args[3] == "missing" {
return "", &exec.ExitError{Stderr: []byte("Error: No such object: missing")}
}
return "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", nil
case "image":
if args[1] == "inspect" {
return f.dockerInspect(args[1:])
}
case "inspect":
return f.dockerInspect(args)
case "info":
if args[1] == "--format" && args[2] == "{{.CgroupDriver}}" {
......@@ -309,9 +318,9 @@ func (f *FakeRunner) podman(args []string, _ bool) (string, error) {
case "--version":
return "podman version 1.6.4", nil
case "inspect":
case "image":
if args[1] == "--format" && args[2] == "{{.Id}}" {
if args[1] == "inspect" && args[2] == "--format" && args[3] == "{{.Id}}" {
if args[3] == "missing" {
return "", &exec.ExitError{Stderr: []byte("Error: error getting image \"missing\": unable to find a name and tag match for missing in repotags: no such image")}
}
......
......@@ -133,7 +133,7 @@ func (r *Docker) Disable() error {
// ImageExists checks if an image exists
func (r *Docker) ImageExists(name string, sha string) bool {
// expected output looks like [SHA_ALGO:SHA]
c := exec.Command("docker", "inspect", "--format", "{{.Id}}", name)
c := exec.Command("docker", "image", "inspect", "--format", "{{.Id}}", name)
rr, err := r.Runner.RunCmd(c)
if err != nil {
return false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment