Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
evol262 authored Apr 19, 2023
2 parents daf22d5 + 2791d75 commit 815ec48
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func RunCriDockerd(f *options.DockerCRIFlags, stopCh <-chan struct{}) error {
if err != nil {
addr, err := netip.ParseAddr(r.StreamingBindAddr)
if err != nil {
logrus.Fatalf("Could not parse the given streaming bind address: %s", r.StreamingBindAddr, err)
logrus.Fatalf("Could not parse the given streaming bind address: %s", r.StreamingBindAddr)
}
resolvedAddr = net.JoinHostPort(addr.String(), "0")
} else {
Expand Down
20 changes: 19 additions & 1 deletion core/docker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package core

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -395,7 +396,24 @@ func (ds *dockerService) Status(
networkReady.Message = fmt.Sprintf("docker: network plugin is not ready: %v", err)
}
status := &runtimeapi.RuntimeStatus{Conditions: conditions}
return &runtimeapi.StatusResponse{Status: status}, nil
resp := &runtimeapi.StatusResponse{Status: status}
if r.Verbose {
image := defaultSandboxImage
podSandboxImage := ds.podSandboxImage
if len(podSandboxImage) != 0 {
image = podSandboxImage
}
config := map[string]interface{}{
"sandboxImage": image,
}
configByt, err := json.Marshal(config)
if err != nil {
return nil, err
}
resp.Info = make(map[string]string)
resp.Info["config"] = string(configByt)
}
return resp, nil
}

func (ds *dockerService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down
5 changes: 5 additions & 0 deletions core/docker_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func TestStatus(t *testing.T) {
runtimeapi.NetworkReady: true,
}, statusResp.Status)

// Should report info if verbose.
statusResp, err = ds.Status(getTestCTX(), &runtimeapi.StatusRequest{Verbose: true})
require.NoError(t, err)
assert.NotNil(t, statusResp.Info)

// Should not report ready status is network plugin returns error.
mockPlugin := newTestNetworkPlugin(t)
ds.network = network.NewPluginManager(mockPlugin)
Expand Down
2 changes: 1 addition & 1 deletion core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func TestGenerateMountBindings(t *testing.T) {
"/mnt/7:/var/lib/mysql/7",
"/mnt/8:/var/lib/mysql/8:ro,Z,rshared",
}
result := libdocker.GenerateMountBindings(mounts)
result := libdocker.GenerateMountBindings(mounts, "")

assert.Equal(t, expectedResult, result)
}
Expand Down
14 changes: 6 additions & 8 deletions core/sandbox_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package core
import (
"context"
"fmt"

v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)

Expand All @@ -42,6 +41,12 @@ func (ds *dockerService) PodSandboxStatus(
}
ct := createdAt.UnixNano()

// Translate container to sandbox state.
state := v1.PodSandboxState_SANDBOX_NOTREADY
if r.State.Running {
state = v1.PodSandboxState_SANDBOX_READY
}

var ips []string
// This is a workaround for windows, where sandbox is not in use, and pod IP is determined through containers belonging to the Pod.
if ips = ds.determinePodIPBySandboxID(podSandboxID); len(ips) == 0 {
Expand All @@ -56,13 +61,6 @@ func (ds *dockerService) PodSandboxStatus(
ips = ips[1:]
}

// Translate container to sandbox state.
// For a sandbox to be in the Ready state, the container needs to be in the Running state and it also needs to have an IP address.
state := v1.PodSandboxState_SANDBOX_NOTREADY
if r.State.Running && len(ips) > 0 {
state = v1.PodSandboxState_SANDBOX_READY
}

labels, annotations := extractLabels(r.Config.Labels)
status := &v1.PodSandboxStatus{
Id: r.ID,
Expand Down
2 changes: 1 addition & 1 deletion vendor/k8s.io/kubernetes/pkg/kubelet/container/helpers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 815ec48

Please sign in to comment.