-
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
fix the route field selectors #16305
Conversation
/assign soltysh |
daee968
to
02e0217
Compare
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.
A few nits, but mostly lgtm
pkg/api/apihelpers/fields.go
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we're not handling namespace
similarly?
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.
Why we're not handling namespace similarly?
It namespace was never special cased in a field selector.
@@ -50,7 +65,10 @@ func TestRoundTripVersionedObject(t *testing.T) { | |||
} | |||
|
|||
func TestFieldSelectors(t *testing.T) { | |||
testutil.CheckFieldLabelConversions(t, "v1", "ImageStream", | |||
converter := runtime.NewScheme() |
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.
nit: scheme
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're manually creating the scheme do you still need to install the api?
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.
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.
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.
Lovely 😉
pkg/router/controller/ingress.go
Outdated
@@ -565,3 +564,11 @@ func GetSafeRouteName(name string) string { | |||
} | |||
return name | |||
} | |||
|
|||
// TODO this should probably be removed and replaced with an upstream keyfunc |
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.
👍 mind creating an issue and assigning this to networking team?
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.
And since this is only template and route and you're touching it, would you mind :) ?
sure.
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.
mind creating an issue and assigning this to networking team?
sure
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.
@@ -37,7 +36,7 @@ func ValidateProcessedTemplate(template *templateapi.Template) field.ErrorList { | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return scheme.AddField...
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.
return scheme.AddField...
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.
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 { |
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.
Same
"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.
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.
Choose a reason for hiding this comment
The 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 return apihelpers.LegacyMetaV1FieldSelectorConversionWithName(label, value) ?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
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.
Needs 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.