Merge pull request #822 from mrunalp/label_infra_ctr
sandbox: Add special label to infra container
This commit is contained in:
commit
11fbcd235c
12 changed files with 404 additions and 8 deletions
|
@ -144,6 +144,7 @@ func New(config *Config) (*ContainerServer, error) {
|
||||||
stateLock: lock,
|
stateLock: lock,
|
||||||
state: &containerServerState{
|
state: &containerServerState{
|
||||||
containers: oci.NewMemoryStore(),
|
containers: oci.NewMemoryStore(),
|
||||||
|
infraContainers: oci.NewMemoryStore(),
|
||||||
sandboxes: make(map[string]*sandbox.Sandbox),
|
sandboxes: make(map[string]*sandbox.Sandbox),
|
||||||
},
|
},
|
||||||
config: config,
|
config: config,
|
||||||
|
@ -580,6 +581,7 @@ func (c *ContainerServer) Shutdown() error {
|
||||||
|
|
||||||
type containerServerState struct {
|
type containerServerState struct {
|
||||||
containers oci.ContainerStorer
|
containers oci.ContainerStorer
|
||||||
|
infraContainers oci.ContainerStorer
|
||||||
sandboxes map[string]*sandbox.Sandbox
|
sandboxes map[string]*sandbox.Sandbox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,6 +594,13 @@ func (c *ContainerServer) AddContainer(ctr *oci.Container) {
|
||||||
c.state.containers.Add(ctr.ID(), ctr)
|
c.state.containers.Add(ctr.ID(), ctr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddInfraContainer adds a container to the container state store
|
||||||
|
func (c *ContainerServer) AddInfraContainer(ctr *oci.Container) {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
c.state.infraContainers.Add(ctr.ID(), ctr)
|
||||||
|
}
|
||||||
|
|
||||||
// GetContainer returns a container by its ID
|
// GetContainer returns a container by its ID
|
||||||
func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
@ -599,6 +608,13 @@ func (c *ContainerServer) GetContainer(id string) *oci.Container {
|
||||||
return c.state.containers.Get(id)
|
return c.state.containers.Get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInfraContainer returns a container by its ID
|
||||||
|
func (c *ContainerServer) GetInfraContainer(id string) *oci.Container {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
return c.state.infraContainers.Get(id)
|
||||||
|
}
|
||||||
|
|
||||||
// HasContainer checks if a container exists in the state
|
// HasContainer checks if a container exists in the state
|
||||||
func (c *ContainerServer) HasContainer(id string) bool {
|
func (c *ContainerServer) HasContainer(id string) bool {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
@ -617,6 +633,13 @@ func (c *ContainerServer) RemoveContainer(ctr *oci.Container) {
|
||||||
c.state.containers.Delete(ctr.ID())
|
c.state.containers.Delete(ctr.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveInfraContainer removes a container from the container state store
|
||||||
|
func (c *ContainerServer) RemoveInfraContainer(ctr *oci.Container) {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
|
c.state.infraContainers.Delete(ctr.ID())
|
||||||
|
}
|
||||||
|
|
||||||
// listContainers returns a list of all containers stored by the server state
|
// listContainers returns a list of all containers stored by the server state
|
||||||
func (c *ContainerServer) listContainers() []*oci.Container {
|
func (c *ContainerServer) listContainers() []*oci.Container {
|
||||||
c.stateLock.Lock()
|
c.stateLock.Lock()
|
||||||
|
|
|
@ -47,10 +47,13 @@ func (s *Server) GetInfoMux() *bone.Mux {
|
||||||
mux.Get("/containers/:id", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
mux.Get("/containers/:id", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
containerID := bone.GetValue(req, "id")
|
containerID := bone.GetValue(req, "id")
|
||||||
ctr := s.GetContainer(containerID)
|
ctr := s.GetContainer(containerID)
|
||||||
|
if ctr == nil {
|
||||||
|
ctr = s.getInfraContainer(containerID)
|
||||||
if ctr == nil {
|
if ctr == nil {
|
||||||
http.Error(w, fmt.Sprintf("container with id: %s not found", containerID), http.StatusNotFound)
|
http.Error(w, fmt.Sprintf("container with id: %s not found", containerID), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctrState := ctr.State()
|
ctrState := ctr.State()
|
||||||
if ctrState == nil {
|
if ctrState == nil {
|
||||||
http.Error(w, fmt.Sprintf("container %s state is nil", containerID), http.StatusNotFound)
|
http.Error(w, fmt.Sprintf("container %s state is nil", containerID), http.StatusNotFound)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kubePrefix = "k8s"
|
kubePrefix = "k8s"
|
||||||
infraName = "infra"
|
infraName = "POD"
|
||||||
nameDelimiter = "_"
|
nameDelimiter = "_"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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
|
// Remove the files related to the sandbox
|
||||||
if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && errors.Cause(err) != storage.ErrContainerUnknown {
|
if err := s.StorageRuntimeServer().StopContainer(sb.ID()); err != nil && errors.Cause(err) != storage.ErrContainerUnknown {
|
||||||
|
|
|
@ -24,7 +24,9 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
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/network/hostport"
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -217,6 +219,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
|
|
||||||
// add labels
|
// add labels
|
||||||
labels := req.GetConfig().GetLabels()
|
labels := req.GetConfig().GetLabels()
|
||||||
|
|
||||||
|
// Add special container name label for the infra container
|
||||||
|
labels[types.KubernetesContainerNameLabel] = leaky.PodInfraContainerName
|
||||||
labelsJSON, err := json.Marshal(labels)
|
labelsJSON, err := json.Marshal(labels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -493,6 +498,8 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.addInfraContainer(container)
|
||||||
|
|
||||||
s.ContainerStateToDisk(container)
|
s.ContainerStateToDisk(container)
|
||||||
|
|
||||||
resp = &pb.RunPodSandboxResponse{PodSandboxId: id}
|
resp = &pb.RunPodSandboxResponse{PodSandboxId: id}
|
||||||
|
|
|
@ -277,10 +277,18 @@ func (s *Server) addContainer(c *oci.Container) {
|
||||||
s.ContainerServer.AddContainer(c)
|
s.ContainerServer.AddContainer(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) addInfraContainer(c *oci.Container) {
|
||||||
|
s.ContainerServer.AddInfraContainer(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getContainer(id string) *oci.Container {
|
func (s *Server) getContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetContainer(id)
|
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
|
// GetSandboxContainer returns the infra container for a given sandbox
|
||||||
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetSandboxContainer(id)
|
return s.ContainerServer.GetSandboxContainer(id)
|
||||||
|
@ -295,6 +303,10 @@ func (s *Server) removeContainer(c *oci.Container) {
|
||||||
s.ContainerServer.RemoveContainer(c)
|
s.ContainerServer.RemoveContainer(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) removeInfraContainer(c *oci.Container) {
|
||||||
|
s.ContainerServer.RemoveInfraContainer(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox.Sandbox, error) {
|
func (s *Server) getPodSandboxFromRequest(podSandboxID string) (*sandbox.Sandbox, error) {
|
||||||
if podSandboxID == "" {
|
if podSandboxID == "" {
|
||||||
return nil, sandbox.ErrIDEmpty
|
return nil, sandbox.ErrIDEmpty
|
||||||
|
|
25
vendor/k8s.io/kubernetes/pkg/kubelet/leaky/leaky.go
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/pkg/kubelet/leaky/leaky.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package leaky holds bits of kubelet that should be internal but have leaked
|
||||||
|
// out through bad abstractions. TODO: delete all of this.
|
||||||
|
package leaky
|
||||||
|
|
||||||
|
const (
|
||||||
|
// This is used in a few places outside of Kubelet, such as indexing
|
||||||
|
// into the container info.
|
||||||
|
PodInfraContainerName = "POD"
|
||||||
|
)
|
22
vendor/k8s.io/kubernetes/pkg/kubelet/types/constants.go
generated
vendored
Normal file
22
vendor/k8s.io/kubernetes/pkg/kubelet/types/constants.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
const (
|
||||||
|
// system default DNS resolver configuration
|
||||||
|
ResolvConfDefault = "/etc/resolv.conf"
|
||||||
|
)
|
18
vendor/k8s.io/kubernetes/pkg/kubelet/types/doc.go
generated
vendored
Normal file
18
vendor/k8s.io/kubernetes/pkg/kubelet/types/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Common types in the Kubelet.
|
||||||
|
package types // import "k8s.io/kubernetes/pkg/kubelet/types"
|
40
vendor/k8s.io/kubernetes/pkg/kubelet/types/labels.go
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubelet/types/labels.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
const (
|
||||||
|
KubernetesPodNameLabel = "io.kubernetes.pod.name"
|
||||||
|
KubernetesPodNamespaceLabel = "io.kubernetes.pod.namespace"
|
||||||
|
KubernetesPodUIDLabel = "io.kubernetes.pod.uid"
|
||||||
|
KubernetesContainerNameLabel = "io.kubernetes.container.name"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetContainerName(labels map[string]string) string {
|
||||||
|
return labels[KubernetesContainerNameLabel]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPodName(labels map[string]string) string {
|
||||||
|
return labels[KubernetesPodNameLabel]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPodUID(labels map[string]string) string {
|
||||||
|
return labels[KubernetesPodUIDLabel]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPodNamespace(labels map[string]string) string {
|
||||||
|
return labels[KubernetesPodNamespaceLabel]
|
||||||
|
}
|
153
vendor/k8s.io/kubernetes/pkg/kubelet/types/pod_update.go
generated
vendored
Normal file
153
vendor/k8s.io/kubernetes/pkg/kubelet/types/pod_update.go
generated
vendored
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
Copyright 2014 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
kubeapi "k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ConfigSourceAnnotationKey = "kubernetes.io/config.source"
|
||||||
|
ConfigMirrorAnnotationKey = v1.MirrorPodAnnotationKey
|
||||||
|
ConfigFirstSeenAnnotationKey = "kubernetes.io/config.seen"
|
||||||
|
ConfigHashAnnotationKey = "kubernetes.io/config.hash"
|
||||||
|
CriticalPodAnnotationKey = "scheduler.alpha.kubernetes.io/critical-pod"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PodOperation defines what changes will be made on a pod configuration.
|
||||||
|
type PodOperation int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// This is the current pod configuration
|
||||||
|
SET PodOperation = iota
|
||||||
|
// Pods with the given ids are new to this source
|
||||||
|
ADD
|
||||||
|
// Pods with the given ids are gracefully deleted from this source
|
||||||
|
DELETE
|
||||||
|
// Pods with the given ids have been removed from this source
|
||||||
|
REMOVE
|
||||||
|
// Pods with the given ids have been updated in this source
|
||||||
|
UPDATE
|
||||||
|
// Pods with the given ids have unexpected status in this source,
|
||||||
|
// kubelet should reconcile status with this source
|
||||||
|
RECONCILE
|
||||||
|
|
||||||
|
// These constants identify the sources of pods
|
||||||
|
// Updates from a file
|
||||||
|
FileSource = "file"
|
||||||
|
// Updates from querying a web page
|
||||||
|
HTTPSource = "http"
|
||||||
|
// Updates from Kubernetes API Server
|
||||||
|
ApiserverSource = "api"
|
||||||
|
// Updates from all sources
|
||||||
|
AllSource = "*"
|
||||||
|
|
||||||
|
NamespaceDefault = metav1.NamespaceDefault
|
||||||
|
)
|
||||||
|
|
||||||
|
// PodUpdate defines an operation sent on the channel. You can add or remove single services by
|
||||||
|
// sending an array of size one and Op == ADD|REMOVE (with REMOVE, only the ID is required).
|
||||||
|
// For setting the state of the system to a given state for this source configuration, set
|
||||||
|
// Pods as desired and Op to SET, which will reset the system state to that specified in this
|
||||||
|
// operation for this source channel. To remove all pods, set Pods to empty object and Op to SET.
|
||||||
|
//
|
||||||
|
// Additionally, Pods should never be nil - it should always point to an empty slice. While
|
||||||
|
// functionally similar, this helps our unit tests properly check that the correct PodUpdates
|
||||||
|
// are generated.
|
||||||
|
type PodUpdate struct {
|
||||||
|
Pods []*v1.Pod
|
||||||
|
Op PodOperation
|
||||||
|
Source string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets all validated sources from the specified sources.
|
||||||
|
func GetValidatedSources(sources []string) ([]string, error) {
|
||||||
|
validated := make([]string, 0, len(sources))
|
||||||
|
for _, source := range sources {
|
||||||
|
switch source {
|
||||||
|
case AllSource:
|
||||||
|
return []string{FileSource, HTTPSource, ApiserverSource}, nil
|
||||||
|
case FileSource, HTTPSource, ApiserverSource:
|
||||||
|
validated = append(validated, source)
|
||||||
|
break
|
||||||
|
case "":
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return []string{}, fmt.Errorf("unknown pod source %q", source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validated, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPodSource returns the source of the pod based on the annotation.
|
||||||
|
func GetPodSource(pod *v1.Pod) (string, error) {
|
||||||
|
if pod.Annotations != nil {
|
||||||
|
if source, ok := pod.Annotations[ConfigSourceAnnotationKey]; ok {
|
||||||
|
return source, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("cannot get source of pod %q", pod.UID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyncPodType classifies pod updates, eg: create, update.
|
||||||
|
type SyncPodType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// SyncPodSync is when the pod is synced to ensure desired state
|
||||||
|
SyncPodSync SyncPodType = iota
|
||||||
|
// SyncPodUpdate is when the pod is updated from source
|
||||||
|
SyncPodUpdate
|
||||||
|
// SyncPodCreate is when the pod is created from source
|
||||||
|
SyncPodCreate
|
||||||
|
// SyncPodKill is when the pod is killed based on a trigger internal to the kubelet for eviction.
|
||||||
|
// If a SyncPodKill request is made to pod workers, the request is never dropped, and will always be processed.
|
||||||
|
SyncPodKill
|
||||||
|
)
|
||||||
|
|
||||||
|
func (sp SyncPodType) String() string {
|
||||||
|
switch sp {
|
||||||
|
case SyncPodCreate:
|
||||||
|
return "create"
|
||||||
|
case SyncPodUpdate:
|
||||||
|
return "update"
|
||||||
|
case SyncPodSync:
|
||||||
|
return "sync"
|
||||||
|
case SyncPodKill:
|
||||||
|
return "kill"
|
||||||
|
default:
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCriticalPod returns true if the pod bears the critical pod annotation
|
||||||
|
// key. Both the rescheduler and the kubelet use this key to make admission
|
||||||
|
// and scheduling decisions.
|
||||||
|
func IsCriticalPod(pod *v1.Pod) bool {
|
||||||
|
// Critical pods are restricted to "kube-system" namespace as of now.
|
||||||
|
if pod.Namespace != kubeapi.NamespaceSystem {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val, ok := pod.Annotations[CriticalPodAnnotationKey]
|
||||||
|
if ok && val == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
93
vendor/k8s.io/kubernetes/pkg/kubelet/types/types.go
generated
vendored
Normal file
93
vendor/k8s.io/kubernetes/pkg/kubelet/types/types.go
generated
vendored
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Reconcile custom types in kubelet/types and this subpackage
|
||||||
|
|
||||||
|
type HttpGetter interface {
|
||||||
|
Get(url string) (*http.Response, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timestamp wraps around time.Time and offers utilities to format and parse
|
||||||
|
// the time using RFC3339Nano
|
||||||
|
type Timestamp struct {
|
||||||
|
time time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTimestamp returns a Timestamp object using the current time.
|
||||||
|
func NewTimestamp() *Timestamp {
|
||||||
|
return &Timestamp{time.Now()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConvertToTimestamp takes a string, parses it using the RFC3339Nano layout,
|
||||||
|
// and converts it to a Timestamp object.
|
||||||
|
func ConvertToTimestamp(timeString string) *Timestamp {
|
||||||
|
parsed, _ := time.Parse(time.RFC3339Nano, timeString)
|
||||||
|
return &Timestamp{parsed}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the time as time.Time.
|
||||||
|
func (t *Timestamp) Get() time.Time {
|
||||||
|
return t.time
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetString returns the time in the string format using the RFC3339Nano
|
||||||
|
// layout.
|
||||||
|
func (t *Timestamp) GetString() string {
|
||||||
|
return t.time.Format(time.RFC3339Nano)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A type to help sort container statuses based on container names.
|
||||||
|
type SortedContainerStatuses []v1.ContainerStatus
|
||||||
|
|
||||||
|
func (s SortedContainerStatuses) Len() int { return len(s) }
|
||||||
|
func (s SortedContainerStatuses) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
|
|
||||||
|
func (s SortedContainerStatuses) Less(i, j int) bool {
|
||||||
|
return s[i].Name < s[j].Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortInitContainerStatuses ensures that statuses are in the order that their
|
||||||
|
// init container appears in the pod spec
|
||||||
|
func SortInitContainerStatuses(p *v1.Pod, statuses []v1.ContainerStatus) {
|
||||||
|
containers := p.Spec.InitContainers
|
||||||
|
current := 0
|
||||||
|
for _, container := range containers {
|
||||||
|
for j := current; j < len(statuses); j++ {
|
||||||
|
if container.Name == statuses[j].Name {
|
||||||
|
statuses[current], statuses[j] = statuses[j], statuses[current]
|
||||||
|
current++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reservation represents reserved resources for non-pod components.
|
||||||
|
type Reservation struct {
|
||||||
|
// System represents resources reserved for non-kubernetes components.
|
||||||
|
System v1.ResourceList
|
||||||
|
// Kubernetes represents resources reserved for kubernetes system components.
|
||||||
|
Kubernetes v1.ResourceList
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue