Skip to content

Commit

Permalink
Flipping behavior when annotation is absent.
Browse files Browse the repository at this point in the history
  • Loading branch information
foxish committed Oct 31, 2016
1 parent e6b2517 commit 5c3792a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pkg/controller/petset/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,25 @@ type petHealthChecker interface {
// It doesn't update, probe or get the pod.
type defaultPetHealthChecker struct{}

// isHealthy returns true if the pod is running and has the
// "pod.alpha.kubernetes.io/initialized" set to "true".
// isHealthy returns true if the pod is ready & running. If the pod has the
// "pod.alpha.kubernetes.io/initialized" annotation set to "false", pod state is ignored.
func (d *defaultPetHealthChecker) isHealthy(pod *api.Pod) bool {
if pod == nil || pod.Status.Phase != api.PodRunning {
return false
}
podReady := api.IsPodReady(pod)

// User may have specified a pod readiness override through a debug annotation.
initialized, ok := pod.Annotations[StatefulSetInitAnnotation]
if !ok {
glog.Infof("StatefulSet pod %v in %v, waiting on annotation %v", api.PodRunning, pod.Name, StatefulSetInitAnnotation)
return false
}
b, err := strconv.ParseBool(initialized)
if err != nil {
return false
if ok {
if initAnnotation, err := strconv.ParseBool(initialized); err != nil {
glog.Infof("Failed to parse %v annotation on pod %v: %v", StatefulSetInitAnnotation, pod.Name, err)
} else if !initAnnotation {
glog.Infof("StatefulSet pod %v waiting on annotation %v", pod.Name, StatefulSetInitAnnotation)
podReady = initAnnotation
}
}
return b && api.IsPodReady(pod)
return podReady
}

// isDying returns true if the pod has a non-nil deletion timestamp. Since the
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/petset.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ func newStatefulSet(name, ns, governingSvcName string, replicas int32, petMounts
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
Annotations: map[string]string{
"pod.alpha.kubernetes.io/initialized": "false",
},
},
Spec: apps.StatefulSetSpec{
Selector: &unversioned.LabelSelector{
Expand Down

0 comments on commit 5c3792a

Please sign in to comment.