mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #5200 from nikhiljindal/eventConverter
Adding conversion functions for event field selectors
This commit is contained in:
commit
7d72b64f60
@ -1400,4 +1400,26 @@ func init() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1316,4 +1316,26 @@ func init() {
|
|||||||
// If one of the conversion functions is malformed, detect it immediately.
|
// If one of the conversion functions is malformed, detect it immediately.
|
||||||
panic(err)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,30 @@ func init() {
|
|||||||
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "pods",
|
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "pods",
|
||||||
func(label, value string) (string, string, error) {
|
func(label, value string) (string, string, error) {
|
||||||
switch label {
|
switch label {
|
||||||
case "name":
|
case "name",
|
||||||
fallthrough
|
"status.phase",
|
||||||
case "status.phase":
|
"spec.host":
|
||||||
fallthrough
|
return label, value, nil
|
||||||
case "spec.host":
|
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
|
return label, value, nil
|
||||||
default:
|
default:
|
||||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||||
|
@ -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
|
// Converts the given field label and value for an apiResource field selector from
|
||||||
// versioned representation to an unversioned one.
|
// versioned representation to an unversioned one.
|
||||||
func (s *Scheme) ConvertFieldLabel(version, apiResource, label, value string) (string, string, error) {
|
func (s *Scheme) ConvertFieldLabel(version, apiResource, label, value string) (string, string, error) {
|
||||||
if typeFuncMap, ok := s.fieldLabelConversionFuncs[version]; ok {
|
if s.fieldLabelConversionFuncs[version] == nil {
|
||||||
if conversionFunc, ok := typeFuncMap[apiResource]; ok {
|
return "", "", fmt.Errorf("No conversion function found for version: %s", version)
|
||||||
return conversionFunc(label, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Don't fail on types we haven't added conversion funcs for yet.
|
conversionFunc, ok := s.fieldLabelConversionFuncs[version][apiResource]
|
||||||
return label, value, nil
|
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
|
// ConvertToVersion attempts to convert an input object to its matching Kind in another
|
||||||
|
Loading…
Reference in New Issue
Block a user