2015-04-28 19:23:13 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors.
|
2015-04-28 19:23:13 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2016-03-29 02:13:16 +00:00
|
|
|
"encoding/json"
|
2015-04-28 19:23:13 +00:00
|
|
|
"fmt"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/conversion"
|
2015-12-24 06:55:06 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-04-28 19:23:13 +00:00
|
|
|
)
|
|
|
|
|
2015-10-21 21:11:32 +00:00
|
|
|
const (
|
|
|
|
// Annotation key used to identify mirror pods.
|
|
|
|
mirrorAnnotationKey = "kubernetes.io/config.mirror"
|
|
|
|
|
|
|
|
// Value used to identify mirror pods from pre-v1.1 kubelet.
|
|
|
|
mirrorAnnotationValue_1_0 = "mirror"
|
|
|
|
)
|
|
|
|
|
2015-12-24 06:55:06 +00:00
|
|
|
func addConversionFuncs(scheme *runtime.Scheme) {
|
2015-05-20 06:23:16 +00:00
|
|
|
// Add non-generated conversion functions
|
2015-12-24 06:55:06 +00:00
|
|
|
err := scheme.AddConversionFuncs(
|
2015-12-23 07:07:10 +00:00
|
|
|
Convert_api_Pod_To_v1_Pod,
|
|
|
|
Convert_api_PodSpec_To_v1_PodSpec,
|
|
|
|
Convert_api_ReplicationControllerSpec_To_v1_ReplicationControllerSpec,
|
|
|
|
Convert_api_ServiceSpec_To_v1_ServiceSpec,
|
|
|
|
Convert_v1_Pod_To_api_Pod,
|
|
|
|
Convert_v1_PodSpec_To_api_PodSpec,
|
|
|
|
Convert_v1_ReplicationControllerSpec_To_api_ReplicationControllerSpec,
|
|
|
|
Convert_v1_ServiceSpec_To_api_ServiceSpec,
|
2016-01-07 22:55:19 +00:00
|
|
|
Convert_v1_ResourceList_To_api_ResourceList,
|
2015-05-18 20:19:43 +00:00
|
|
|
)
|
2015-05-11 15:03:38 +00:00
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-04-28 19:23:13 +00:00
|
|
|
|
2015-10-29 16:34:59 +00:00
|
|
|
// Add field label conversions for kinds having selectable nothing but ObjectMeta fields.
|
|
|
|
for _, kind := range []string{
|
|
|
|
"Endpoints",
|
|
|
|
"ResourceQuota",
|
|
|
|
"PersistentVolumeClaim",
|
|
|
|
"Service",
|
|
|
|
"ServiceAccount",
|
2016-01-15 16:48:36 +00:00
|
|
|
"ConfigMap",
|
2015-10-29 16:34:59 +00:00
|
|
|
} {
|
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", kind,
|
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
|
|
|
case "metadata.namespace",
|
|
|
|
"metadata.name":
|
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label %q not supported for %q", label, kind)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 19:23:13 +00:00
|
|
|
// Add field conversion funcs.
|
2015-05-15 00:38:08 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Pod",
|
2015-04-28 19:23:13 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
|
|
|
case "metadata.name",
|
|
|
|
"metadata.namespace",
|
2015-02-20 05:36:23 +00:00
|
|
|
"metadata.labels",
|
|
|
|
"metadata.annotations",
|
2015-04-28 19:23:13 +00:00
|
|
|
"status.phase",
|
2015-08-12 18:14:49 +00:00
|
|
|
"status.podIP",
|
2016-01-17 19:59:56 +00:00
|
|
|
"spec.nodeName",
|
|
|
|
"spec.restartPolicy":
|
2015-04-28 19:23:13 +00:00
|
|
|
return label, value, nil
|
2015-08-08 21:29:57 +00:00
|
|
|
// This is for backwards compatibility with old v1 clients which send spec.host
|
2015-07-10 22:13:43 +00:00
|
|
|
case "spec.host":
|
|
|
|
return "spec.nodeName", value, nil
|
2015-04-28 19:23:13 +00:00
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-05-15 00:38:08 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Node",
|
2015-04-28 19:23:13 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
|
|
|
case "metadata.name":
|
|
|
|
return label, value, nil
|
|
|
|
case "spec.unschedulable":
|
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-05-15 00:38:08 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "ReplicationController",
|
2015-04-28 19:23:13 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
|
|
|
case "metadata.name",
|
2015-11-30 21:31:40 +00:00
|
|
|
"metadata.namespace",
|
2015-04-28 19:23:13 +00:00
|
|
|
"status.replicas":
|
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-05-15 00:38:08 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Event",
|
2015-04-28 19:23:13 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
|
|
|
case "involvedObject.kind",
|
|
|
|
"involvedObject.namespace",
|
|
|
|
"involvedObject.name",
|
|
|
|
"involvedObject.uid",
|
|
|
|
"involvedObject.apiVersion",
|
|
|
|
"involvedObject.resourceVersion",
|
|
|
|
"involvedObject.fieldPath",
|
|
|
|
"reason",
|
2015-11-26 07:32:54 +00:00
|
|
|
"source",
|
2015-11-30 21:31:40 +00:00
|
|
|
"type",
|
|
|
|
"metadata.namespace",
|
|
|
|
"metadata.name":
|
2015-04-28 19:23:13 +00:00
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-05-15 00:38:08 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Namespace",
|
2015-04-28 19:23:13 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
2015-11-30 21:31:40 +00:00
|
|
|
case "status.phase",
|
|
|
|
"metadata.name":
|
2015-04-28 19:23:13 +00:00
|
|
|
return label, value, nil
|
2015-06-02 17:22:10 +00:00
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-10-29 16:34:59 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "PersistentVolume",
|
2015-06-02 17:22:10 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
2015-10-29 16:34:59 +00:00
|
|
|
case "metadata.name":
|
2015-11-30 21:31:40 +00:00
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-10-29 16:34:59 +00:00
|
|
|
err = api.Scheme.AddFieldLabelConversionFunc("v1", "Secret",
|
2015-11-30 21:31:40 +00:00
|
|
|
func(label, value string) (string, string, error) {
|
|
|
|
switch label {
|
2015-10-29 16:34:59 +00:00
|
|
|
case "type",
|
|
|
|
"metadata.namespace",
|
2015-11-30 21:31:40 +00:00
|
|
|
"metadata.name":
|
2015-06-10 16:47:21 +00:00
|
|
|
return label, value, nil
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
// If one of the conversion functions is malformed, detect it immediately.
|
2015-04-28 19:23:13 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2015-05-18 20:19:43 +00:00
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_api_ReplicationControllerSpec_To_v1_ReplicationControllerSpec(in *api.ReplicationControllerSpec, out *ReplicationControllerSpec, s conversion.Scope) error {
|
2016-05-20 19:02:33 +00:00
|
|
|
out.Replicas = &in.Replicas
|
|
|
|
out.Selector = in.Selector
|
2015-05-28 23:29:06 +00:00
|
|
|
//if in.TemplateRef != nil {
|
|
|
|
// out.TemplateRef = new(ObjectReference)
|
2015-12-23 07:07:10 +00:00
|
|
|
// if err := Convert_api_ObjectReference_To_v1_ObjectReference(in.TemplateRef, out.TemplateRef, s); err != nil {
|
2015-05-28 23:29:06 +00:00
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
//} else {
|
|
|
|
// out.TemplateRef = nil
|
|
|
|
//}
|
2015-05-20 06:23:16 +00:00
|
|
|
if in.Template != nil {
|
|
|
|
out.Template = new(PodTemplateSpec)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
2015-05-20 06:23:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Template = nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_v1_ReplicationControllerSpec_To_api_ReplicationControllerSpec(in *ReplicationControllerSpec, out *api.ReplicationControllerSpec, s conversion.Scope) error {
|
2016-04-27 04:35:14 +00:00
|
|
|
out.Replicas = *in.Replicas
|
2016-05-20 19:02:33 +00:00
|
|
|
out.Selector = in.Selector
|
|
|
|
|
2015-05-28 23:29:06 +00:00
|
|
|
//if in.TemplateRef != nil {
|
|
|
|
// out.TemplateRef = new(api.ObjectReference)
|
2015-12-23 07:07:10 +00:00
|
|
|
// if err := Convert_v1_ObjectReference_To_api_ObjectReference(in.TemplateRef, out.TemplateRef, s); err != nil {
|
2015-05-28 23:29:06 +00:00
|
|
|
// return err
|
|
|
|
// }
|
|
|
|
//} else {
|
|
|
|
// out.TemplateRef = nil
|
|
|
|
//}
|
2015-05-20 06:23:16 +00:00
|
|
|
if in.Template != nil {
|
|
|
|
out.Template = new(api.PodTemplateSpec)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
2015-05-20 06:23:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Template = nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-07-16 19:02:12 +00:00
|
|
|
|
2016-03-29 02:13:16 +00:00
|
|
|
func Convert_api_PodStatusResult_To_v1_PodStatusResult(in *api.PodStatusResult, out *PodStatusResult, s conversion.Scope) error {
|
|
|
|
if err := autoConvert_api_PodStatusResult_To_v1_PodStatusResult(in, out, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:02:33 +00:00
|
|
|
if old := out.Annotations; old != nil {
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 02:13:16 +00:00
|
|
|
if len(out.Status.InitContainerStatuses) > 0 {
|
|
|
|
if out.Annotations == nil {
|
|
|
|
out.Annotations = make(map[string]string)
|
|
|
|
}
|
|
|
|
value, err := json.Marshal(out.Status.InitContainerStatuses)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
|
|
|
|
} else {
|
2016-05-19 21:53:59 +00:00
|
|
|
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
2016-03-29 02:13:16 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-05-19 21:53:59 +00:00
|
|
|
if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok {
|
2016-03-29 02:13:16 +00:00
|
|
|
var values []ContainerStatus
|
|
|
|
if err := json.Unmarshal([]byte(value), &values); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-31 13:15:51 +00:00
|
|
|
// Conversion from external to internal version exists more to
|
|
|
|
// satisfy the needs of the decoder than it does to be a general
|
|
|
|
// purpose tool. And Decode always creates an intermediate object
|
|
|
|
// to decode to. Thus the caller of UnsafeConvertToVersion is
|
|
|
|
// taking responsibility to ensure mutation of in is not exposed
|
|
|
|
// back to the caller.
|
2016-03-29 02:13:16 +00:00
|
|
|
in.Status.InitContainerStatuses = values
|
|
|
|
}
|
|
|
|
|
2016-05-19 21:53:59 +00:00
|
|
|
if err := autoConvert_v1_PodStatusResult_To_api_PodStatusResult(in, out, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
if len(out.Annotations) > 0 {
|
|
|
|
old := out.Annotations
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
|
|
|
}
|
|
|
|
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
|
|
|
}
|
2016-05-19 21:53:59 +00:00
|
|
|
return nil
|
2016-03-29 02:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in *api.PodTemplateSpec, out *PodTemplateSpec, s conversion.Scope) error {
|
|
|
|
if err := autoConvert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in, out, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: when we move init container to beta, remove these conversions
|
2016-05-20 19:02:33 +00:00
|
|
|
if old := out.Annotations; old != nil {
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 02:13:16 +00:00
|
|
|
if len(out.Spec.InitContainers) > 0 {
|
|
|
|
if out.Annotations == nil {
|
|
|
|
out.Annotations = make(map[string]string)
|
|
|
|
}
|
|
|
|
value, err := json.Marshal(out.Spec.InitContainers)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out.Annotations[PodInitContainersAnnotationKey] = string(value)
|
|
|
|
} else {
|
|
|
|
delete(out.Annotations, PodInitContainersAnnotationKey)
|
|
|
|
}
|
|
|
|
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
|
2016-05-19 21:53:59 +00:00
|
|
|
if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok {
|
2016-03-29 02:13:16 +00:00
|
|
|
var values []Container
|
|
|
|
if err := json.Unmarshal([]byte(value), &values); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-31 13:15:51 +00:00
|
|
|
// Conversion from external to internal version exists more to
|
|
|
|
// satisfy the needs of the decoder than it does to be a general
|
|
|
|
// purpose tool. And Decode always creates an intermediate object
|
|
|
|
// to decode to. Thus the caller of UnsafeConvertToVersion is
|
|
|
|
// taking responsibility to ensure mutation of in is not exposed
|
|
|
|
// back to the caller.
|
2016-03-29 02:13:16 +00:00
|
|
|
in.Spec.InitContainers = values
|
|
|
|
}
|
|
|
|
|
2016-05-19 21:53:59 +00:00
|
|
|
if err := autoConvert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in, out, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
if len(out.Annotations) > 0 {
|
|
|
|
old := out.Annotations
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
|
|
|
}
|
|
|
|
delete(out.Annotations, PodInitContainersAnnotationKey)
|
|
|
|
}
|
2016-05-19 21:53:59 +00:00
|
|
|
return nil
|
2016-03-29 02:13:16 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 19:02:12 +00:00
|
|
|
// The following two PodSpec conversions are done here to support ServiceAccount
|
|
|
|
// as an alias for ServiceAccountName.
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_api_PodSpec_To_v1_PodSpec(in *api.PodSpec, out *PodSpec, s conversion.Scope) error {
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.Volumes != nil {
|
|
|
|
out.Volumes = make([]Volume, len(in.Volumes))
|
|
|
|
for i := range in.Volumes {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_Volume_To_v1_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Volumes = nil
|
|
|
|
}
|
2016-03-29 02:13:16 +00:00
|
|
|
if in.InitContainers != nil {
|
|
|
|
out.InitContainers = make([]Container, len(in.InitContainers))
|
|
|
|
for i := range in.InitContainers {
|
|
|
|
if err := Convert_api_Container_To_v1_Container(&in.InitContainers[i], &out.InitContainers[i], s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.InitContainers = nil
|
|
|
|
}
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.Containers != nil {
|
|
|
|
out.Containers = make([]Container, len(in.Containers))
|
|
|
|
for i := range in.Containers {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_Container_To_v1_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Containers = nil
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
|
2015-07-16 19:02:12 +00:00
|
|
|
out.RestartPolicy = RestartPolicy(in.RestartPolicy)
|
2016-05-20 19:02:33 +00:00
|
|
|
out.TerminationGracePeriodSeconds = in.TerminationGracePeriodSeconds
|
|
|
|
out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds
|
2015-07-16 19:02:12 +00:00
|
|
|
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
|
2016-05-20 19:02:33 +00:00
|
|
|
out.NodeSelector = in.NodeSelector
|
|
|
|
|
2015-07-16 19:02:12 +00:00
|
|
|
out.ServiceAccountName = in.ServiceAccountName
|
|
|
|
// DeprecatedServiceAccount is an alias for ServiceAccountName.
|
|
|
|
out.DeprecatedServiceAccount = in.ServiceAccountName
|
|
|
|
out.NodeName = in.NodeName
|
2015-09-14 21:56:51 +00:00
|
|
|
if in.SecurityContext != nil {
|
|
|
|
out.SecurityContext = new(PodSecurityContext)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_PodSecurityContext_To_v1_PodSecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
2015-09-14 21:56:51 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:33:32 +00:00
|
|
|
// the host namespace fields have to be handled here for backward compatibility
|
2015-10-20 18:03:32 +00:00
|
|
|
// with v1.0.0
|
2015-09-14 21:56:51 +00:00
|
|
|
out.HostPID = in.SecurityContext.HostPID
|
|
|
|
out.HostNetwork = in.SecurityContext.HostNetwork
|
|
|
|
out.HostIPC = in.SecurityContext.HostIPC
|
|
|
|
}
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.ImagePullSecrets != nil {
|
|
|
|
out.ImagePullSecrets = make([]LocalObjectReference, len(in.ImagePullSecrets))
|
|
|
|
for i := range in.ImagePullSecrets {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_LocalObjectReference_To_v1_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.ImagePullSecrets = nil
|
|
|
|
}
|
2016-04-14 17:45:29 +00:00
|
|
|
out.Hostname = in.Hostname
|
|
|
|
out.Subdomain = in.Subdomain
|
2015-07-16 19:02:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_v1_PodSpec_To_api_PodSpec(in *PodSpec, out *api.PodSpec, s conversion.Scope) error {
|
2016-04-29 03:08:23 +00:00
|
|
|
SetDefaults_PodSpec(in)
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.Volumes != nil {
|
|
|
|
out.Volumes = make([]api.Volume, len(in.Volumes))
|
|
|
|
for i := range in.Volumes {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_Volume_To_api_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Volumes = nil
|
|
|
|
}
|
2016-03-29 02:13:16 +00:00
|
|
|
if in.InitContainers != nil {
|
|
|
|
out.InitContainers = make([]api.Container, len(in.InitContainers))
|
|
|
|
for i := range in.InitContainers {
|
|
|
|
if err := Convert_v1_Container_To_api_Container(&in.InitContainers[i], &out.InitContainers[i], s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.InitContainers = nil
|
|
|
|
}
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.Containers != nil {
|
|
|
|
out.Containers = make([]api.Container, len(in.Containers))
|
|
|
|
for i := range in.Containers {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_Container_To_api_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Containers = nil
|
|
|
|
}
|
|
|
|
out.RestartPolicy = api.RestartPolicy(in.RestartPolicy)
|
2016-05-20 19:02:33 +00:00
|
|
|
out.TerminationGracePeriodSeconds = in.TerminationGracePeriodSeconds
|
|
|
|
out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds
|
2015-07-16 19:02:12 +00:00
|
|
|
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
|
2016-05-20 19:02:33 +00:00
|
|
|
out.NodeSelector = in.NodeSelector
|
2015-07-16 19:02:12 +00:00
|
|
|
// We support DeprecatedServiceAccount as an alias for ServiceAccountName.
|
|
|
|
// If both are specified, ServiceAccountName (the new field) wins.
|
|
|
|
out.ServiceAccountName = in.ServiceAccountName
|
|
|
|
if in.ServiceAccountName == "" {
|
|
|
|
out.ServiceAccountName = in.DeprecatedServiceAccount
|
|
|
|
}
|
|
|
|
out.NodeName = in.NodeName
|
2015-09-14 21:56:51 +00:00
|
|
|
if in.SecurityContext != nil {
|
|
|
|
out.SecurityContext = new(api.PodSecurityContext)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_PodSecurityContext_To_api_PodSecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
2015-09-14 21:56:51 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 18:03:32 +00:00
|
|
|
|
|
|
|
// the host namespace fields have to be handled specially for backward compatibility
|
|
|
|
// with v1.0.0
|
2015-09-14 21:56:51 +00:00
|
|
|
if out.SecurityContext == nil {
|
|
|
|
out.SecurityContext = new(api.PodSecurityContext)
|
|
|
|
}
|
|
|
|
out.SecurityContext.HostNetwork = in.HostNetwork
|
|
|
|
out.SecurityContext.HostPID = in.HostPID
|
|
|
|
out.SecurityContext.HostIPC = in.HostIPC
|
2015-07-16 19:02:12 +00:00
|
|
|
if in.ImagePullSecrets != nil {
|
|
|
|
out.ImagePullSecrets = make([]api.LocalObjectReference, len(in.ImagePullSecrets))
|
|
|
|
for i := range in.ImagePullSecrets {
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_LocalObjectReference_To_api_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
|
2015-07-16 19:02:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.ImagePullSecrets = nil
|
|
|
|
}
|
2016-04-14 17:45:29 +00:00
|
|
|
out.Hostname = in.Hostname
|
|
|
|
out.Subdomain = in.Subdomain
|
2015-07-16 19:02:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-09-24 00:46:18 +00:00
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_api_Pod_To_v1_Pod(in *api.Pod, out *Pod, s conversion.Scope) error {
|
|
|
|
if err := autoConvert_api_Pod_To_v1_Pod(in, out, s); err != nil {
|
2015-10-21 21:11:32 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-03-29 02:13:16 +00:00
|
|
|
|
|
|
|
// TODO: when we move init container to beta, remove these conversions
|
2016-05-20 19:02:33 +00:00
|
|
|
if len(out.Spec.InitContainers) > 0 || len(out.Status.InitContainerStatuses) > 0 {
|
|
|
|
old := out.Annotations
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
2016-03-29 02:13:16 +00:00
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
delete(out.Annotations, PodInitContainersAnnotationKey)
|
|
|
|
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
|
|
|
}
|
|
|
|
if len(out.Spec.InitContainers) > 0 {
|
2016-03-29 02:13:16 +00:00
|
|
|
value, err := json.Marshal(out.Spec.InitContainers)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out.Annotations[PodInitContainersAnnotationKey] = string(value)
|
|
|
|
}
|
|
|
|
if len(out.Status.InitContainerStatuses) > 0 {
|
|
|
|
value, err := json.Marshal(out.Status.InitContainerStatuses)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out.Annotations[PodInitContainerStatusesAnnotationKey] = string(value)
|
|
|
|
}
|
|
|
|
|
2015-10-21 21:11:32 +00:00
|
|
|
// We need to reset certain fields for mirror pods from pre-v1.1 kubelet
|
|
|
|
// (#15960).
|
|
|
|
// TODO: Remove this code after we drop support for v1.0 kubelets.
|
|
|
|
if value, ok := in.Annotations[mirrorAnnotationKey]; ok && value == mirrorAnnotationValue_1_0 {
|
|
|
|
// Reset the TerminationGracePeriodSeconds.
|
|
|
|
out.Spec.TerminationGracePeriodSeconds = nil
|
|
|
|
// Reset the resource requests.
|
|
|
|
for i := range out.Spec.Containers {
|
|
|
|
out.Spec.Containers[i].Resources.Requests = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_v1_Pod_To_api_Pod(in *Pod, out *api.Pod, s conversion.Scope) error {
|
2016-03-29 02:13:16 +00:00
|
|
|
// TODO: when we move init container to beta, remove these conversions
|
2016-05-19 21:53:59 +00:00
|
|
|
if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok {
|
2016-03-29 02:13:16 +00:00
|
|
|
var values []Container
|
|
|
|
if err := json.Unmarshal([]byte(value), &values); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-31 13:15:51 +00:00
|
|
|
// Conversion from external to internal version exists more to
|
|
|
|
// satisfy the needs of the decoder than it does to be a general
|
|
|
|
// purpose tool. And Decode always creates an intermediate object
|
|
|
|
// to decode to. Thus the caller of UnsafeConvertToVersion is
|
|
|
|
// taking responsibility to ensure mutation of in is not exposed
|
|
|
|
// back to the caller.
|
2016-03-29 02:13:16 +00:00
|
|
|
in.Spec.InitContainers = values
|
|
|
|
}
|
2016-05-19 21:53:59 +00:00
|
|
|
if value, ok := in.Annotations[PodInitContainerStatusesAnnotationKey]; ok {
|
2016-03-29 02:13:16 +00:00
|
|
|
var values []ContainerStatus
|
|
|
|
if err := json.Unmarshal([]byte(value), &values); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-31 13:15:51 +00:00
|
|
|
// Conversion from external to internal version exists more to
|
|
|
|
// satisfy the needs of the decoder than it does to be a general
|
|
|
|
// purpose tool. And Decode always creates an intermediate object
|
|
|
|
// to decode to. Thus the caller of UnsafeConvertToVersion is
|
|
|
|
// taking responsibility to ensure mutation of in is not exposed
|
|
|
|
// back to the caller.
|
2016-03-29 02:13:16 +00:00
|
|
|
in.Status.InitContainerStatuses = values
|
|
|
|
}
|
|
|
|
|
2016-05-19 21:53:59 +00:00
|
|
|
if err := autoConvert_v1_Pod_To_api_Pod(in, out, s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
if len(out.Annotations) > 0 {
|
|
|
|
old := out.Annotations
|
|
|
|
out.Annotations = make(map[string]string, len(old))
|
|
|
|
for k, v := range old {
|
|
|
|
out.Annotations[k] = v
|
|
|
|
}
|
|
|
|
delete(out.Annotations, PodInitContainersAnnotationKey)
|
|
|
|
delete(out.Annotations, PodInitContainerStatusesAnnotationKey)
|
|
|
|
}
|
2016-05-19 21:53:59 +00:00
|
|
|
return nil
|
2015-10-21 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_api_ServiceSpec_To_v1_ServiceSpec(in *api.ServiceSpec, out *ServiceSpec, s conversion.Scope) error {
|
|
|
|
if err := autoConvert_api_ServiceSpec_To_v1_ServiceSpec(in, out, s); err != nil {
|
2015-09-24 00:46:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Publish both externalIPs and deprecatedPublicIPs fields in v1.
|
2016-05-20 19:02:33 +00:00
|
|
|
out.DeprecatedPublicIPs = in.ExternalIPs
|
2015-09-24 00:46:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_v1_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *api.ServiceSpec, s conversion.Scope) error {
|
|
|
|
if err := autoConvert_v1_ServiceSpec_To_api_ServiceSpec(in, out, s); err != nil {
|
2015-09-24 00:46:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Prefer the legacy deprecatedPublicIPs field, if provided.
|
|
|
|
if len(in.DeprecatedPublicIPs) > 0 {
|
2016-05-20 19:02:33 +00:00
|
|
|
out.ExternalIPs = in.DeprecatedPublicIPs
|
2015-09-24 00:46:18 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2015-09-14 21:56:51 +00:00
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_api_PodSecurityContext_To_v1_PodSecurityContext(in *api.PodSecurityContext, out *PodSecurityContext, s conversion.Scope) error {
|
2015-10-15 17:45:16 +00:00
|
|
|
out.SupplementalGroups = in.SupplementalGroups
|
2015-10-20 18:03:32 +00:00
|
|
|
if in.SELinuxOptions != nil {
|
|
|
|
out.SELinuxOptions = new(SELinuxOptions)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_api_SELinuxOptions_To_v1_SELinuxOptions(in.SELinuxOptions, out.SELinuxOptions, s); err != nil {
|
2015-10-20 18:03:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.SELinuxOptions = nil
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
out.RunAsUser = in.RunAsUser
|
|
|
|
out.RunAsNonRoot = in.RunAsNonRoot
|
|
|
|
out.FSGroup = in.FSGroup
|
2015-09-14 21:56:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-23 07:07:10 +00:00
|
|
|
func Convert_v1_PodSecurityContext_To_api_PodSecurityContext(in *PodSecurityContext, out *api.PodSecurityContext, s conversion.Scope) error {
|
2015-10-15 17:45:16 +00:00
|
|
|
out.SupplementalGroups = in.SupplementalGroups
|
2015-10-20 18:03:32 +00:00
|
|
|
if in.SELinuxOptions != nil {
|
|
|
|
out.SELinuxOptions = new(api.SELinuxOptions)
|
2015-12-23 07:07:10 +00:00
|
|
|
if err := Convert_v1_SELinuxOptions_To_api_SELinuxOptions(in.SELinuxOptions, out.SELinuxOptions, s); err != nil {
|
2015-10-20 18:03:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.SELinuxOptions = nil
|
|
|
|
}
|
2016-05-20 19:02:33 +00:00
|
|
|
out.RunAsUser = in.RunAsUser
|
|
|
|
out.RunAsNonRoot = in.RunAsNonRoot
|
|
|
|
out.FSGroup = in.FSGroup
|
2015-09-14 21:56:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
2016-01-07 22:55:19 +00:00
|
|
|
|
|
|
|
func Convert_v1_ResourceList_To_api_ResourceList(in *ResourceList, out *api.ResourceList, s conversion.Scope) error {
|
|
|
|
if *in == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:02:33 +00:00
|
|
|
if *out == nil {
|
|
|
|
*out = make(api.ResourceList, len(*in))
|
|
|
|
}
|
2016-01-07 22:55:19 +00:00
|
|
|
for key, val := range *in {
|
|
|
|
// TODO(#18538): We round up resource values to milli scale to maintain API compatibility.
|
|
|
|
// In the future, we should instead reject values that need rounding.
|
2016-05-17 04:36:56 +00:00
|
|
|
const milliScale = -3
|
2016-05-20 19:02:33 +00:00
|
|
|
val.RoundUp(milliScale)
|
2016-01-07 22:55:19 +00:00
|
|
|
|
2016-05-20 19:02:33 +00:00
|
|
|
(*out)[api.ResourceName(key)] = val
|
2016-01-07 22:55:19 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|