fix the route field selectors#16305
Conversation
|
/assign soltysh |
daee968 to
02e0217
Compare
soltysh
left a comment
There was a problem hiding this comment.
A few nits, but mostly lgtm
| // which many of our older resources used. | ||
| func LegacyMetaV1FieldSelectorConversionWithName(label, value string) (string, string, error) { | ||
| switch label { | ||
| case "name": |
There was a problem hiding this comment.
Why we're not handling namespace similarly?
There was a problem hiding this comment.
Why we're not handling namespace similarly?
It namespace was never special cased in a field selector.
|
|
||
| func TestFieldSelectors(t *testing.T) { | ||
| testutil.CheckFieldLabelConversions(t, "v1", "ImageStream", | ||
| converter := runtime.NewScheme() |
There was a problem hiding this comment.
nit: scheme
it is getting used as a converter, not a scheme. Scheme happens to implement converter.
|
|
||
| _ "github.com/openshift/origin/pkg/api/install" | ||
| // some side-effect of this import is causing TestRoundTripVersionedObject to pass. I don't see it. | ||
| _ "github.com/openshift/origin/pkg/image/apis/image/install" |
There was a problem hiding this comment.
If you're manually creating the scheme do you still need to install the api?
There was a problem hiding this comment.
If you're manually creating the scheme do you still need to install the api?
I found the side-effect last night, but I haven't found a good solution yet. For now, it has to remain like this.
| return name | ||
| } | ||
|
|
||
| // TODO this should probably be removed and replaced with an upstream keyfunc |
There was a problem hiding this comment.
👍 mind creating an issue and assigning this to networking team?
There was a problem hiding this comment.
And since this is only template and route and you're touching it, would you mind :) ?
sure.
There was a problem hiding this comment.
mind creating an issue and assigning this to networking team?
sure
| // ValidateTemplate tests if required fields in the Template are set. | ||
| func ValidateTemplate(template *templateapi.Template) (allErrs field.ErrorList) { | ||
| allErrs = validation.ValidateObjectMeta(&template.ObjectMeta, true, oapi.GetNameValidationFunc(validation.ValidatePodName), field.NewPath("metadata")) | ||
| allErrs = validation.ValidateObjectMeta(&template.ObjectMeta, true, validation.ValidatePodName, field.NewPath("metadata")) |
There was a problem hiding this comment.
OMG, we should probably stop using ValidatePodName and create our own, as in ValidateTemplateName pointing to what that ValidatePodName is pointing, which is NameIsDNSSubdomain.
There was a problem hiding this comment.
And since this is only template and route and you're touching it, would you mind :) ?
| apihelpers.GetFieldLabelConversionFunc(routeapi.RouteToSelectableFields(&routeapi.Route{}), nil), | ||
| ) | ||
| func addLegacyFieldConversionFuncs(scheme *runtime.Scheme) error { | ||
| if err := scheme.AddFieldLabelConversionFunc(LegacySchemeGroupVersion.String(), "Route", legacyRouteFieldSelectorConversionFunc); err != nil { |
There was a problem hiding this comment.
return scheme.AddField...
Are you sure? This stanza is copy/pasteable as more Kinds are added.
There was a problem hiding this comment.
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.
That still can be, and in most cases is the last line in addConversionFuncs. Above you'll keep adding type-specific conversion funcs.
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.
| } | ||
|
|
||
| func addFieldConversionFuncs(scheme *runtime.Scheme) error { | ||
| if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Route", routeFieldSelectorConversionFunc); err != nil { |
| "spec.to.name": | ||
| return label, value, nil | ||
| default: | ||
| return runtime.DefaultMetaV1FieldSelectorConversion(label, value) |
There was a problem hiding this comment.
Looking at the other pr adding this to the rest, this struck me. Shouldn't that be return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) ?
There was a problem hiding this comment.
Looking at the other pr adding this to the rest, this struck me. Shouldn't that be return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) ?
Interestingly enough, no. The "name" -> "metadata.name" mapping never existed for routes.
02e0217 to
ba743f0
Compare
|
/retest |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, soltysh The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
Automatic merge from submit-queue (batch tested with PRs 16089, 16305, 16219, 15934, 16366) |
Automatic merge from submit-queue (batch tested with PRs 16384, 16327, 16199, 16286, 16378) fix remaining field selectors Really hoping that #16305 works out. This updates all the rest for that pattern and allows us to remove a ton of boilerplate while maintaining decent unit test coverage. Still need a "you forgot to add a test" test, but that was already missing.
This makes the field selectors for routes work correctly and makes a slightly different pattern which works with the upstream defaulting and fieldkey methods so that we won't slip on object meta updates in the future. It also uses the actual scheme registration to determine if the field key conversion methods work.