diff --git a/pkg/api/v1/conversion.go b/pkg/api/v1/conversion.go index d2cb2dc7acb..e2a462cf000 100644 --- a/pkg/api/v1/conversion.go +++ b/pkg/api/v1/conversion.go @@ -419,7 +419,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 { @@ -453,7 +453,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 { @@ -469,14 +469,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 { @@ -501,6 +509,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 } @@ -554,7 +563,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)) @@ -562,6 +571,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 { @@ -570,6 +580,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) @@ -594,7 +605,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 { @@ -632,6 +649,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 2292bbc3c56..5dac82b1e9a 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -1655,11 +1655,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.