Merge pull request #33055 from dchen1107/test1

Automatic merge from submit-queue

Fix backward compatibility issue caused by promoting initcontainers f…

#31026 moves init-container feature from alpha to beta, but only took care the backward compatibility for pod specification, not deal with status. For status, it simply moved from `pods.beta.kubernetes.io/init-container-statuses` to
`pods.beta.kubernetes.io/init-container-statuses` instead of introducing one more pods.beta.kubernetes.io/init-container-statuses. This breaks when the cluster is running with 1.4, but the user is still running with kubectl 1.3.x. 

Fixed #32711
This commit is contained in:
Kubernetes Submit Queue 2016-09-20 17:09:20 -07:00 committed by GitHub
commit aa5372c5ef
2 changed files with 24 additions and 2 deletions

View File

@ -414,14 +414,22 @@ func Convert_api_PodStatusResult_To_v1_PodStatusResult(in *api.PodStatusResult,
return err return err
} }
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value) out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
out.Annotations[PodInitContainerStatusesBetaAnnotationKey] = string(value)
} else { } else {
delete(out.Annotations, PodInitContainerStatusesAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
} }
return nil return nil
} }
func Convert_v1_PodStatusResult_To_api_PodStatusResult(in *PodStatusResult, out *api.PodStatusResult, s conversion.Scope) error { func Convert_v1_PodStatusResult_To_api_PodStatusResult(in *PodStatusResult, out *api.PodStatusResult, s conversion.Scope) error {
// TODO: sometime after we move init container to stable, remove these conversions // TODO: sometime after we move init container to stable, remove these conversions
// If there is a beta annotation, copy to alpha key.
// See commit log for PR #31026 for why we do this.
if valueBeta, okBeta := in.Annotations[PodInitContainerStatusesBetaAnnotationKey]; okBeta {
in.Annotations[PodInitContainerStatusesAnnotationKey] = valueBeta
}
// Move the annotation to the internal repr. field
if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok { if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok {
var values []ContainerStatus var values []ContainerStatus
if err := json.Unmarshal([]byte(value), &values); err != nil { if err := json.Unmarshal([]byte(value), &values); err != nil {
@ -446,6 +454,7 @@ func Convert_v1_PodStatusResult_To_api_PodStatusResult(in *PodStatusResult, out
out.Annotations[k] = v out.Annotations[k] = v
} }
delete(out.Annotations, PodInitContainerStatusesAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
} }
return nil return nil
} }
@ -575,6 +584,7 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error
delete(out.Annotations, PodInitContainersAnnotationKey) delete(out.Annotations, PodInitContainersAnnotationKey)
delete(out.Annotations, PodInitContainersBetaAnnotationKey) delete(out.Annotations, PodInitContainersBetaAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
} }
if len(out.Spec.InitContainers) > 0 { if len(out.Spec.InitContainers) > 0 {
value, err := json.Marshal(out.Spec.InitContainers) value, err := json.Marshal(out.Spec.InitContainers)
@ -590,6 +600,7 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error
return err return err
} }
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value) out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
out.Annotations[PodInitContainerStatusesBetaAnnotationKey] = string(value)
} }
// We need to reset certain fields for mirror pods from pre-v1.1 kubelet // We need to reset certain fields for mirror pods from pre-v1.1 kubelet
@ -627,6 +638,11 @@ func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error
// back to the caller. // back to the caller.
in.Spec.InitContainers = values in.Spec.InitContainers = values
} }
// If there is a beta annotation, copy to alpha key.
// See commit log for PR #31026 for why we do this.
if valueBeta, okBeta := in.Annotations[PodInitContainerStatusesBetaAnnotationKey]; okBeta {
in.Annotations[PodInitContainerStatusesAnnotationKey] = valueBeta
}
if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok { if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok {
var values []ContainerStatus var values []ContainerStatus
if err := json.Unmarshal([]byte(value), &values); err != nil { if err := json.Unmarshal([]byte(value), &values); err != nil {
@ -653,6 +669,7 @@ func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error
delete(out.Annotations, PodInitContainersAnnotationKey) delete(out.Annotations, PodInitContainersAnnotationKey)
delete(out.Annotations, PodInitContainersBetaAnnotationKey) delete(out.Annotations, PodInitContainersBetaAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
} }
return nil return nil
} }

View File

@ -1749,8 +1749,13 @@ const (
PodInitContainersAnnotationKey = "pod.alpha.kubernetes.io/init-containers" PodInitContainersAnnotationKey = "pod.alpha.kubernetes.io/init-containers"
// This annotation key will be used to contain an array of v1 JSON encoded // This annotation key will be used to contain an array of v1 JSON encoded
// ContainerStatuses for init containers. The annotation will be placed into the internal // ContainerStatuses for init containers. The annotation will be placed into the internal
// type and cleared. // type and cleared. This key is only recognized by version >= 1.4.
PodInitContainerStatusesAnnotationKey = "pod.beta.kubernetes.io/init-container-statuses" PodInitContainerStatusesBetaAnnotationKey = "pod.beta.kubernetes.io/init-container-statuses"
// This annotation key will be used to contain an array of v1 JSON encoded
// ContainerStatuses for init containers. The annotation will be placed into the internal
// type and cleared. This key is recognized by version >= 1.3. For version 1.4 code,
// this key will have its value copied to the beta key.
PodInitContainerStatusesAnnotationKey = "pod.alpha.kubernetes.io/init-container-statuses"
) )
// PodSpec is a description of a pod. // PodSpec is a description of a pod.