...

Source file src/k8s.io/kubernetes/pkg/kubelet/pleg/pleg.go

Documentation: k8s.io/kubernetes/pkg/kubelet/pleg

     1  /*
     2  Copyright 2015 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package pleg
    18  
    19  import (
    20  	"time"
    21  
    22  	"k8s.io/apimachinery/pkg/types"
    23  	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
    24  )
    25  
    26  // PodLifeCycleEventType define the event type of pod life cycle events.
    27  type PodLifeCycleEventType string
    28  
    29  type RelistDuration struct {
    30  	// The period for relisting.
    31  	RelistPeriod time.Duration
    32  	// The relisting threshold needs to be greater than the relisting period +
    33  	// the relisting time, which can vary significantly. Set a conservative
    34  	// threshold to avoid flipping between healthy and unhealthy.
    35  	RelistThreshold time.Duration
    36  }
    37  
    38  const (
    39  	// ContainerStarted - event type when the new state of container is running.
    40  	ContainerStarted PodLifeCycleEventType = "ContainerStarted"
    41  	// ContainerDied - event type when the new state of container is exited.
    42  	ContainerDied PodLifeCycleEventType = "ContainerDied"
    43  	// ContainerRemoved - event type when the old state of container is exited.
    44  	ContainerRemoved PodLifeCycleEventType = "ContainerRemoved"
    45  	// PodSync is used to trigger syncing of a pod when the observed change of
    46  	// the state of the pod cannot be captured by any single event above.
    47  	PodSync PodLifeCycleEventType = "PodSync"
    48  	// ContainerChanged - event type when the new state of container is unknown.
    49  	ContainerChanged PodLifeCycleEventType = "ContainerChanged"
    50  )
    51  
    52  // PodLifecycleEvent is an event that reflects the change of the pod state.
    53  type PodLifecycleEvent struct {
    54  	// The pod ID.
    55  	ID types.UID
    56  	// The type of the event.
    57  	Type PodLifeCycleEventType
    58  	// The accompanied data which varies based on the event type.
    59  	//   - ContainerStarted/ContainerStopped: the container name (string).
    60  	//   - All other event types: unused.
    61  	Data interface{}
    62  }
    63  
    64  // PodLifecycleEventGenerator contains functions for generating pod life cycle events.
    65  type PodLifecycleEventGenerator interface {
    66  	Start()
    67  	Watch() chan *PodLifecycleEvent
    68  	Healthy() (bool, error)
    69  	UpdateCache(*kubecontainer.Pod, types.UID) (error, bool)
    70  }
    71  
    72  // podLifecycleEventGeneratorHandler contains functions that are useful for different PLEGs
    73  // and need not be exposed to rest of the kubelet
    74  type podLifecycleEventGeneratorHandler interface {
    75  	PodLifecycleEventGenerator
    76  	Stop()
    77  	Update(relistDuration *RelistDuration)
    78  	Relist()
    79  }
    80  

View as plain text