Adding conversion functions for event field selectors

pull/6/head
nikhiljindal 2015-03-09 14:39:04 -07:00
parent 07c2035630
commit 790a8bbd23
4 changed files with 75 additions and 11 deletions

View File

@ -1398,4 +1398,26 @@ func init() {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta1", "events",
func(label, value string) (string, string, error) {
switch label {
case "involvedObject.kind",
"involvedObject.namespace",
"involvedObject.uid",
"involvedObject.apiVersion",
"involvedObject.resourceVersion",
"involvedObject.fieldPath",
"reason",
"source":
return label, value, nil
case "involvedObject.id":
return "involvedObject.name", 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)
}
}

View File

@ -1314,4 +1314,26 @@ func init() {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "events",
func(label, value string) (string, string, error) {
switch label {
case "involvedObject.kind",
"involvedObject.namespace",
"involvedObject.uid",
"involvedObject.apiVersion",
"involvedObject.resourceVersion",
"involvedObject.fieldPath",
"reason",
"source":
return label, value, nil
case "involvedObject.id":
return "involvedObject.name", 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)
}
}

View File

@ -27,11 +27,30 @@ func init() {
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "pods",
func(label, value string) (string, string, error) {
switch label {
case "name":
fallthrough
case "status.phase":
fallthrough
case "spec.host":
case "name",
"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)
}
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "events",
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)

View File

@ -322,13 +322,14 @@ func (s *Scheme) Convert(in, out interface{}) error {
// Converts the given field label and value for an apiResource field selector from
// versioned representation to an unversioned one.
func (s *Scheme) ConvertFieldLabel(version, apiResource, label, value string) (string, string, error) {
if typeFuncMap, ok := s.fieldLabelConversionFuncs[version]; ok {
if conversionFunc, ok := typeFuncMap[apiResource]; ok {
return conversionFunc(label, value)
}
if s.fieldLabelConversionFuncs[version] == nil {
return "", "", fmt.Errorf("No conversion function found for version: %s", version)
}
// Don't fail on types we haven't added conversion funcs for yet.
return label, value, nil
conversionFunc, ok := s.fieldLabelConversionFuncs[version][apiResource]
if !ok {
return "", "", fmt.Errorf("No conversion function found for version %s and api resource %s", version, apiResource)
}
return conversionFunc(label, value)
}
// ConvertToVersion attempts to convert an input object to its matching Kind in another