diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index 7e5a7cff6bf..cdfccfe090b 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -420,7 +420,7 @@ func Convert_api_PodStatusResult_To_v1_PodStatusResult(in *api.PodStatusResult, } func Convert_v1_PodStatusResult_To_api_PodStatusResult(in *PodStatusResult, out *api.PodStatusResult, s conversion.Scope) error { - // TODO: when we move init container to beta, remove these conversions + // TODO: sometime after we move init container to stable, remove these conversions if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok { var values []ContainerStatus if err := json.Unmarshal([]byte(value), &values); err != nil { @@ -454,7 +454,7 @@ func Convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in *api.PodTemplateSpec, return err } - // TODO: when we move init container to beta, remove these conversions + // TODO: sometime after we move init container to stable, remove these conversions. if old := out.Annotations; old != nil { out.Annotations = make(map[string]string, len(old)) for k, v := range old { @@ -470,14 +470,22 @@ func Convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in *api.PodTemplateSpec, return err } out.Annotations[PodInitContainersAnnotationKey] = string(value) + out.Annotations[PodInitContainersBetaAnnotationKey] = string(value) } else { delete(out.Annotations, PodInitContainersAnnotationKey) + delete(out.Annotations, PodInitContainersBetaAnnotationKey) } return nil } func Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in *PodTemplateSpec, out *api.PodTemplateSpec, s conversion.Scope) error { - // TODO: when we move init container to beta, 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[PodInitContainersBetaAnnotationKey]; okBeta { + in.Annotations[PodInitContainersAnnotationKey] = valueBeta + } + // Move the annotation to the internal repr. field if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok { var values []Container if err := json.Unmarshal([]byte(value), &values); err != nil { @@ -502,6 +510,7 @@ func Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in *PodTemplateSpec, out out.Annotations[k] = v } delete(out.Annotations, PodInitContainersAnnotationKey) + delete(out.Annotations, PodInitContainersBetaAnnotationKey) } return nil } @@ -555,7 +564,7 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error return err } - // TODO: when we move init container to beta, remove these conversions + // TODO: sometime after we move init container to stable, remove these conversions if len(out.Spec.InitContainers) > 0 || len(out.Status.InitContainerStatuses) > 0 { old := out.Annotations out.Annotations = make(map[string]string, len(old)) @@ -563,6 +572,7 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error out.Annotations[k] = v } delete(out.Annotations, PodInitContainersAnnotationKey) + delete(out.Annotations, PodInitContainersBetaAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey) } if len(out.Spec.InitContainers) > 0 { @@ -571,6 +581,7 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error return err } out.Annotations[PodInitContainersAnnotationKey] = string(value) + out.Annotations[PodInitContainersBetaAnnotationKey] = string(value) } if len(out.Status.InitContainerStatuses) > 0 { value, err := json.Marshal(out.Status.InitContainerStatuses) @@ -595,7 +606,13 @@ func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error } func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error { - // TODO: when we move init container to beta, 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[PodInitContainersBetaAnnotationKey]; okBeta { + in.Annotations[PodInitContainersAnnotationKey] = valueBeta + } + // TODO: sometime after we move init container to stable, remove these conversions + // Move the annotation to the internal repr. field if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok { var values []Container if err := json.Unmarshal([]byte(value), &values); err != nil { @@ -633,6 +650,7 @@ func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error out.Annotations[k] = v } delete(out.Annotations, PodInitContainersAnnotationKey) + delete(out.Annotations, PodInitContainersBetaAnnotationKey) delete(out.Annotations, PodInitContainerStatusesAnnotationKey) } return nil diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index 6d5de4c5f74..19f3459966f 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -1705,11 +1705,17 @@ const ( const ( // This annotation key will be used to contain an array of v1 JSON encoded Containers // for init containers. The annotation will be placed into the internal type and cleared. + // This key is only recognized by version >= 1.4. + PodInitContainersBetaAnnotationKey = "pod.beta.kubernetes.io/init-containers" + // This annotation key will be used to contain an array of v1 JSON encoded Containers + // 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. 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.alpha.kubernetes.io/init-container-statuses" + PodInitContainerStatusesAnnotationKey = "pod.beta.kubernetes.io/init-container-statuses" ) // PodSpec is a description of a pod.