-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
fix the route field selectors #16305
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
package route | ||
|
||
import "k8s.io/apimachinery/pkg/fields" | ||
import ( | ||
"fmt" | ||
|
||
// RouteToSelectableFields returns a label set that represents the object | ||
func RouteToSelectableFields(route *Route) fields.Set { | ||
return fields.Set{ | ||
"metadata.name": route.Name, | ||
"metadata.namespace": route.Namespace, | ||
"spec.path": route.Spec.Path, | ||
"spec.host": route.Spec.Host, | ||
"spec.to.name": route.Spec.To.Name, | ||
"k8s.io/apimachinery/pkg/fields" | ||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func RouteFieldSelector(obj runtime.Object, fieldSet fields.Set) error { | ||
route, ok := obj.(*Route) | ||
if !ok { | ||
return fmt.Errorf("%T not a Route", obj) | ||
} | ||
fieldSet["spec.path"] = route.Spec.Path | ||
fieldSet["spec.host"] = route.Spec.Host | ||
fieldSet["spec.to.name"] = route.Spec.To.Name | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,43 @@ package v1 | |
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
"github.com/openshift/origin/pkg/api/apihelpers" | ||
routeapi "github.com/openshift/origin/pkg/route/apis/route" | ||
) | ||
|
||
func addConversionFuncs(scheme *runtime.Scheme) error { | ||
return scheme.AddFieldLabelConversionFunc("v1", "Route", | ||
apihelpers.GetFieldLabelConversionFunc(routeapi.RouteToSelectableFields(&routeapi.Route{}), nil), | ||
) | ||
func addLegacyFieldConversionFuncs(scheme *runtime.Scheme) error { | ||
if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Route", legacyRouteFieldSelectorConversionFunc); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func addFieldConversionFuncs(scheme *runtime.Scheme) error { | ||
if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Route", routeFieldSelectorConversionFunc); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// because field selectors can vary in support by version they are exposed under, we have one function for each | ||
// groupVersion we're registering for | ||
|
||
func legacyRouteFieldSelectorConversionFunc(label, value string) (internalLabel, internalValue string, err error) { | ||
switch label { | ||
case "spec.path", | ||
"spec.host", | ||
"spec.to.name": | ||
return label, value, nil | ||
default: | ||
return runtime.DefaultMetaV1FieldSelectorConversion(label, value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the other pr adding this to the rest, this struck me. Shouldn't that be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Interestingly enough, no. The "name" -> "metadata.name" mapping never existed for routes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
} | ||
} | ||
|
||
func routeFieldSelectorConversionFunc(label, value string) (internalLabel, internalValue string, err error) { | ||
switch label { | ||
case "spec.path", | ||
"spec.host", | ||
"spec.to.name": | ||
return label, value, nil | ||
default: | ||
return runtime.DefaultMetaV1FieldSelectorConversion(label, value) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? This stanza is copy/pasteable as more Kinds are added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still can be, and in most cases is the last line in
addConversionFuncs
. Above you'll keep adding type-specific conversion funcs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, it really can't be. Conversions aren't tied to a particular external schema version, but field conversions are. That's why there are two different methods.