mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
StatefulSet: Remove pod.alpha.kubernetes.io/initialized
annotation.
This commit is contained in:
parent
48e8370674
commit
283211c1cf
@ -85,7 +85,6 @@ func TestStatefulSetControl(t *testing.T) {
|
||||
{ScalesDown, simpleSetFn},
|
||||
{ReplacesPods, largeSetFn},
|
||||
{RecreatesFailedPod, simpleSetFn},
|
||||
{SetsInitAnnotation, simpleSetFn},
|
||||
{CreatePodFailure, simpleSetFn},
|
||||
{UpdatePodFailure, simpleSetFn},
|
||||
{UpdateSetStatusFailure, simpleSetFn},
|
||||
@ -279,59 +278,6 @@ func RecreatesFailedPod(t *testing.T, set *apps.StatefulSet, invariants invarian
|
||||
}
|
||||
}
|
||||
|
||||
func SetsInitAnnotation(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) {
|
||||
client := fake.NewSimpleClientset(set)
|
||||
spc, _, ssc, stop := setupController(client)
|
||||
defer close(stop)
|
||||
|
||||
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
pods, err := spc.podsLister.Pods(set.Namespace).List(selector)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = ssc.UpdateStatefulSet(set, pods); err != nil {
|
||||
t.Errorf("Error updating StatefulSet %s", err)
|
||||
}
|
||||
if err = invariants(set, spc); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if pods, err = spc.setPodRunning(set, 0); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if pods, err = spc.setPodReady(set, 0); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if pods, err = spc.setPodInitStatus(set, 0, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
replicas := int(set.Status.Replicas)
|
||||
if err := ssc.UpdateStatefulSet(set, pods); err != nil {
|
||||
t.Errorf("Error updating StatefulSet %s", err)
|
||||
}
|
||||
if err := invariants(set, spc); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if replicas != int(set.Status.Replicas) {
|
||||
t.Errorf("StatefulSetControl does not block on %s=false", apps.StatefulSetInitAnnotation)
|
||||
}
|
||||
if pods, err = spc.setPodInitStatus(set, 0, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := scaleUpStatefulSetControl(set, ssc, spc, invariants); err != nil {
|
||||
t.Errorf("Failed to turn up StatefulSet : %s", err)
|
||||
}
|
||||
set, err = spc.setsLister.StatefulSets(set.Namespace).Get(set.Name)
|
||||
if err != nil {
|
||||
t.Fatalf("Error getting updated StatefulSet: %v", err)
|
||||
}
|
||||
if int(set.Status.Replicas) != 3 {
|
||||
t.Errorf("StatefulSetControl does not unblock on %s=true", apps.StatefulSetInitAnnotation)
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePodFailure(t *testing.T, set *apps.StatefulSet, invariants invariantFunc) {
|
||||
client := fake.NewSimpleClientset(set)
|
||||
spc, _, ssc, stop := setupController(client)
|
||||
@ -1673,30 +1619,6 @@ func (spc *fakeStatefulPodControl) setPodReady(set *apps.StatefulSet, ordinal in
|
||||
return spc.podsLister.Pods(set.Namespace).List(selector)
|
||||
}
|
||||
|
||||
func (spc *fakeStatefulPodControl) setPodInitStatus(set *apps.StatefulSet, ordinal int, init bool) ([]*v1.Pod, error) {
|
||||
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pods, err := spc.podsLister.Pods(set.Namespace).List(selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if 0 > ordinal || ordinal >= len(pods) {
|
||||
return nil, fmt.Errorf("ordinal %d out of range [0,%d)", ordinal, len(pods))
|
||||
}
|
||||
sort.Sort(ascendingOrdinal(pods))
|
||||
pod := copyPod(pods[ordinal])
|
||||
if init {
|
||||
pod.Annotations[apps.StatefulSetInitAnnotation] = "true"
|
||||
} else {
|
||||
pod.Annotations[apps.StatefulSetInitAnnotation] = "false"
|
||||
}
|
||||
fakeResourceVersion(pod)
|
||||
spc.podsIndexer.Update(pod)
|
||||
return spc.podsLister.Pods(set.Namespace).List(selector)
|
||||
}
|
||||
|
||||
func (spc *fakeStatefulPodControl) addTerminatingPod(set *apps.StatefulSet, ordinal int) ([]*v1.Pod, error) {
|
||||
pod := newStatefulSetPod(set, ordinal)
|
||||
pod.Status.Phase = v1.PodRunning
|
||||
|
@ -31,8 +31,6 @@ import (
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/controller/history"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// maxUpdateRetries is the maximum number of retries used for update conflict resolution prior to failure
|
||||
@ -191,26 +189,9 @@ func updateIdentity(set *apps.StatefulSet, pod *v1.Pod) {
|
||||
pod.Spec.Subdomain = set.Spec.ServiceName
|
||||
}
|
||||
|
||||
// isRunningAndReady returns true if pod is in the PodRunning Phase, if it has a condition of PodReady, and if the init
|
||||
// annotation has not explicitly disabled the Pod from being ready.
|
||||
// isRunningAndReady returns true if pod is in the PodRunning Phase, if it has a condition of PodReady.
|
||||
func isRunningAndReady(pod *v1.Pod) bool {
|
||||
if pod.Status.Phase != v1.PodRunning {
|
||||
return false
|
||||
}
|
||||
podReady := podutil.IsPodReady(pod)
|
||||
// User may have specified a pod readiness override through a debug annotation.
|
||||
initialized, ok := pod.Annotations[apps.StatefulSetInitAnnotation]
|
||||
if ok {
|
||||
if initAnnotation, err := strconv.ParseBool(initialized); err != nil {
|
||||
glog.V(4).Infof("Failed to parse %v annotation on pod %v: %v",
|
||||
apps.StatefulSetInitAnnotation, pod.Name, err)
|
||||
} else if !initAnnotation {
|
||||
glog.V(4).Infof("StatefulSet pod %v waiting on annotation %v", pod.Name,
|
||||
apps.StatefulSetInitAnnotation)
|
||||
podReady = initAnnotation
|
||||
}
|
||||
}
|
||||
return podReady
|
||||
return pod.Status.Phase == v1.PodRunning && podutil.IsPodReady(pod)
|
||||
}
|
||||
|
||||
// isCreated returns true if pod has been created and is maintained by the API server
|
||||
|
@ -213,18 +213,6 @@ func TestIsRunningAndReady(t *testing.T) {
|
||||
if !isRunningAndReady(pod) {
|
||||
t.Error("Pod should be running and ready")
|
||||
}
|
||||
pod.Annotations[apps.StatefulSetInitAnnotation] = "true"
|
||||
if !isRunningAndReady(pod) {
|
||||
t.Error("isRunningAndReady does not respected init annotation set to true")
|
||||
}
|
||||
pod.Annotations[apps.StatefulSetInitAnnotation] = "false"
|
||||
if isRunningAndReady(pod) {
|
||||
t.Error("isRunningAndReady does not respected init annotation set to false")
|
||||
}
|
||||
pod.Annotations[apps.StatefulSetInitAnnotation] = "blah"
|
||||
if !isRunningAndReady(pod) {
|
||||
t.Error("isRunningAndReady does not erroneous init annotation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAscendingOrdinal(t *testing.T) {
|
||||
|
@ -24,8 +24,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// StatefulSetInitAnnotation if present, and set to false, indicates that a Pod's readiness should be ignored.
|
||||
StatefulSetInitAnnotation = "pod.alpha.kubernetes.io/initialized"
|
||||
ControllerRevisionHashLabelKey = "controller-revision-hash"
|
||||
StatefulSetRevisionLabel = ControllerRevisionHashLabelKey
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user