Merge pull request #822 from mrunalp/label_infra_ctr

sandbox: Add special label to infra container
This commit is contained in:
Antonio Murdaca 2017-09-01 22:10:54 +02:00 committed by GitHub
commit 11fbcd235c
12 changed files with 404 additions and 8 deletions

View file

@ -48,8 +48,11 @@ func (s *Server) GetInfoMux() *bone.Mux {
containerID := bone.GetValue(req, "id")
ctr := s.GetContainer(containerID)
if ctr == nil {
http.Error(w, fmt.Sprintf("container with id: %s not found", containerID), http.StatusNotFound)
return
ctr = s.getInfraContainer(containerID)
if ctr == nil {
http.Error(w, fmt.Sprintf("container with id: %s not found", containerID), http.StatusNotFound)
return
}
}
ctrState := ctr.State()
if ctrState == nil {

View file

@ -10,7 +10,7 @@ import (
const (
kubePrefix = "k8s"
infraName = "infra"
infraName = "POD"
nameDelimiter = "_"
)

View file

@ -71,7 +71,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
}
}
s.removeContainer(podInfraContainer)
s.removeInfraContainer(podInfraContainer)
// Remove the files related to the sandbox
if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && errors.Cause(err) != storage.ErrContainerUnknown {

View file

@ -24,7 +24,9 @@ import (
"golang.org/x/sys/unix"
"k8s.io/kubernetes/pkg/api/v1"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/leaky"
"k8s.io/kubernetes/pkg/kubelet/network/hostport"
"k8s.io/kubernetes/pkg/kubelet/types"
)
const (
@ -217,6 +219,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
// add labels
labels := req.GetConfig().GetLabels()
// Add special container name label for the infra container
labels[types.KubernetesContainerNameLabel] = leaky.PodInfraContainerName
labelsJSON, err := json.Marshal(labels)
if err != nil {
return nil, err
@ -493,6 +498,8 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
return nil, err
}
s.addInfraContainer(container)
s.ContainerStateToDisk(container)
resp = &pb.RunPodSandboxResponse{PodSandboxId: id}

View file

@ -277,10 +277,18 @@ func (s *Server) addContainer(c *oci.Container) {
s.ContainerServer.AddContainer(c)
}
func (s *Server) addInfraContainer(c *oci.Container) {
s.ContainerServer.AddInfraContainer(c)
}
func (s *Server) getContainer(id string) *oci.Container {
return s.ContainerServer.GetContainer(id)
}
func (s *Server) getInfraContainer(id string) *oci.Container {
return s.ContainerServer.GetInfraContainer(id)
}
// GetSandboxContainer returns the infra container for a given sandbox
func (s *Server) GetSandboxContainer(id string) *oci.Container {
return s.ContainerServer.GetSandboxContainer(id)
@ -295,6 +303,10 @@ func (s *Server) removeContainer(c *oci.Container) {
s.ContainerServer.RemoveContainer(c)
}
func (s *Server) removeInfraContainer(c *oci.Container) {
s.ContainerServer.RemoveInfraContainer(c)
}
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox.Sandbox, error) {
if podSandboxID == "" {
return nil, sandbox.ErrIDEmpty