mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
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:
commit
aa5372c5ef
@ -414,14 +414,22 @@ func Convert_api_PodStatusResult_To_v1_PodStatusResult(in *api.PodStatusResult,
|
||||
return err
|
||||
}
|
||||
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
|
||||
out.Annotations[PodInitContainerStatusesBetaAnnotationKey] = string(value)
|
||||
} else {
|
||||
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
// 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 {
|
||||
var values []ContainerStatus
|
||||
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
|
||||
}
|
||||
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
|
||||
}
|
||||
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, PodInitContainersBetaAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
|
||||
}
|
||||
if len(out.Spec.InitContainers) > 0 {
|
||||
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
|
||||
}
|
||||
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
|
||||
out.Annotations[PodInitContainerStatusesBetaAnnotationKey] = string(value)
|
||||
}
|
||||
|
||||
// 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.
|
||||
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 {
|
||||
var values []ContainerStatus
|
||||
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, PodInitContainersBetaAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
||||
delete(out.Annotations, PodInitContainerStatusesBetaAnnotationKey)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1749,8 +1749,13 @@ const (
|
||||
PodInitContainersAnnotationKey = "pod.alpha.kubernetes.io/init-containers"
|
||||
// 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.
|
||||
PodInitContainerStatusesAnnotationKey = "pod.beta.kubernetes.io/init-container-statuses"
|
||||
// type and cleared. This key is only recognized by version >= 1.4.
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user