2015-04-28 19:23:13 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
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 (
|
|
|
|
"fmt"
|
2015-05-18 20:19:43 +00:00
|
|
|
"reflect"
|
2015-04-28 19:23:13 +00:00
|
|
|
|
2015-05-15 00:38:08 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2015-05-18 20:19:43 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
2015-04-28 19:23:13 +00:00
|
|
|
)
|
|
|
|
|
2015-05-05 23:53:22 +00:00
|
|
|
func addConversionFuncs() {
|
2015-05-18 20:19:43 +00:00
|
|
|
err := api.Scheme.AddConversionFuncs(
|
|
|
|
convert_api_StatusDetails_To_v1_StatusDetails,
|
|
|
|
convert_v1_StatusDetails_To_api_StatusDetails,
|
|
|
|
)
|
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
|
|
|
|
|
|
|
// 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",
|
|
|
|
"status.phase",
|
|
|
|
"spec.host":
|
|
|
|
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", "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",
|
|
|
|
"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",
|
|
|
|
"source":
|
|
|
|
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 {
|
|
|
|
case "status.phase":
|
|
|
|
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-18 20:19:43 +00:00
|
|
|
|
|
|
|
func convert_v1_StatusDetails_To_api_StatusDetails(in *StatusDetails, out *api.StatusDetails, s conversion.Scope) error {
|
|
|
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
|
|
|
defaulting.(func(*StatusDetails))(in)
|
|
|
|
}
|
|
|
|
out.ID = in.Name
|
|
|
|
out.Kind = in.Kind
|
|
|
|
if in.Causes != nil {
|
|
|
|
out.Causes = make([]api.StatusCause, len(in.Causes))
|
|
|
|
for i := range in.Causes {
|
|
|
|
if err := convert_v1_StatusCause_To_api_StatusCause(&in.Causes[i], &out.Causes[i], s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Causes = nil
|
|
|
|
}
|
|
|
|
out.RetryAfterSeconds = in.RetryAfterSeconds
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convert_api_StatusDetails_To_v1_StatusDetails(in *api.StatusDetails, out *StatusDetails, s conversion.Scope) error {
|
|
|
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
|
|
|
defaulting.(func(*api.StatusDetails))(in)
|
|
|
|
}
|
|
|
|
out.Name = in.ID
|
|
|
|
out.Kind = in.Kind
|
|
|
|
if in.Causes != nil {
|
|
|
|
out.Causes = make([]StatusCause, len(in.Causes))
|
|
|
|
for i := range in.Causes {
|
|
|
|
if err := convert_api_StatusCause_To_v1_StatusCause(&in.Causes[i], &out.Causes[i], s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
out.Causes = nil
|
|
|
|
}
|
|
|
|
out.RetryAfterSeconds = in.RetryAfterSeconds
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convert_v1_StatusCause_To_api_StatusCause(in *StatusCause, out *api.StatusCause, s conversion.Scope) error {
|
|
|
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
|
|
|
defaulting.(func(*StatusCause))(in)
|
|
|
|
}
|
|
|
|
out.Type = api.CauseType(in.Type)
|
|
|
|
out.Message = in.Message
|
|
|
|
out.Field = in.Field
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func convert_api_StatusCause_To_v1_StatusCause(in *api.StatusCause, out *StatusCause, s conversion.Scope) error {
|
|
|
|
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
|
|
|
defaulting.(func(*api.StatusCause))(in)
|
|
|
|
}
|
|
|
|
out.Type = CauseType(in.Type)
|
|
|
|
out.Message = in.Message
|
|
|
|
out.Field = in.Field
|
|
|
|
return nil
|
|
|
|
}
|