Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding conversion functions for event field selectors #5200

Merged
merged 1 commit into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
22 changes: 22 additions & 0 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
29 changes: 24 additions & 5 deletions pkg/api/v1beta3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions pkg/runtime/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend not forcing people to write conversion function if it's unnecessary. Up to you, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, we do need conversion functions for all field selectors. So its good to have this check to catch errors.
We can remove this later, if we add resources for which do not need conversion functions.

}
conversionFunc, ok := s.fieldLabelConversionFuncs[version][apiResource]
if !ok {
return "", "", fmt.Errorf("No conversion function found for version %s and api resource %s", version, apiResource)
}
// Don't fail on types we haven't added conversion funcs for yet.
return label, value, nil
return conversionFunc(label, value)
}

// ConvertToVersion attempts to convert an input object to its matching Kind in another
Expand Down