diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index abe22aee838..6b2a2dc4765 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -158,7 +158,8 @@ type ExecProbe struct { // Command is the command line to execute inside the container, the working directory for the // command is root ('/') in the container's filesystem. The command is simply exec'd, it is // not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use - // a shell, you need to explicitly call out to that shell + // a shell, you need to explicitly call out to that shell. + // A return code of zero is treated as 'Healthy', non-zero is 'Unhealthy' Command []string `yaml:"command,omitempty" json:"command,omitempty"` } diff --git a/pkg/health/health.go b/pkg/health/health.go index 5922f562a4a..637250157d8 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -17,6 +17,8 @@ limitations under the License. package health import ( + "sync" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/golang/glog" ) @@ -36,16 +38,32 @@ type HealthChecker interface { HealthCheck(podFullName string, currentState api.PodState, container api.Container) (Status, error) } +// protects checkers +var checkerLock = sync.Mutex{} var checkers = map[string]HealthChecker{} +// Add a health checker to the list of known HealthChecker objects. Any subsequent call to +// NewHealthChecker will know about this HealthChecker. +// panics if 'key' is already present. func AddHealthChecker(key string, checker HealthChecker) { + checkerLock.Lock() + defer checkerLock.Unlock() + if _, found := checkers[key]; found { + glog.Fatalf("HealthChecker already defined for key %s.", key) + } checkers[key] = checker } // NewHealthChecker creates a new HealthChecker which supports multiple types of liveness probes. func NewHealthChecker() HealthChecker { + checkerLock.Lock() + defer checkerLock.Unlock() + input := map[string]HealthChecker{} + for key, value := range checkers { + input[key] = value + } return &muxHealthChecker{ - checkers: checkers, + checkers: input, } }