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
Set singular names for core types to pass to discovery #113542
Set singular names for core types to pass to discovery #113542
Conversation
set +o errexit | ||
} | ||
|
||
run_assert_singular_name_tests() { |
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.
This test is not failing on master. I added it to just prevent future regressions.
kube::test::if_has_string "${output_message}" "test-crd-example" | ||
|
||
# test that get pod returns v1/pod instead crd | ||
output_message=$(kubectl get pod) |
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.
This test should fail on master without this patch.
current failing tests don't seem to be related to the changes; just to be sure rerun integration tests; |
/retest |
~all storage implementations already set a DefaultQualifiedResource field to the plural version of their resource... I think a peer field SingularQualifiedResource would be a clearer place to set this, making the SingularResource getter be implemented by the that field could also be validated in Store#CompleteWithOptions
|
pkg/registry/admissionregistration/mutatingwebhookconfiguration/storage/storage.go
Outdated
Show resolved
Hide resolved
e676db1
to
1f54f61
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.
I think we also want an integration test that enables all built-in resources and ensures we set singular names for them which match lower(kind)
Something like this:
diff --git a/test/integration/apiserver/discovery/discovery_test.go b/test/integration/apiserver/discovery/discovery_test.go
index c6b7caaa477..1906f9aa552 100644
--- a/test/integration/apiserver/discovery/discovery_test.go
+++ b/test/integration/apiserver/discovery/discovery_test.go
@@ -27,6 +27,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
+
apidiscoveryv2beta1 "k8s.io/api/apidiscovery/v2beta1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
@@ -690,6 +691,34 @@ func TestGroupPriorty(t *testing.T) {
})
}
+func TestSingularNames(t *testing.T) {
+ server := kubeapiservertesting.StartTestServerOrDie(t, nil, []string{"--runtime-config=api/all=true"}, framework.SharedEtcd())
+ t.Cleanup(server.TearDownFn)
+
+ kubeClientSet, err := kubernetes.NewForConfig(server.ClientConfig)
+ require.NoError(t, err)
+
+ _, resources, err := kubeClientSet.Discovery().ServerGroupsAndResources()
+ require.NoError(t, err)
+
+ for _, rr := range resources {
+ for _, r := range rr.APIResources {
+ if strings.Contains(r.Name, "/") {
+ continue
+ }
+ if r.SingularName == "" {
+ t.Errorf("missing singularName for resource %q in %q", r.Name, rr.GroupVersion)
+ continue
+ }
+ if r.SingularName != strings.ToLower(r.Kind) {
+ t.Errorf("expected singularName for resource %q in %q to be %q, got %q", r.Name, rr.GroupVersion, strings.ToLower(r.Kind), r.SingularName)
+ continue
+ }
+ }
+ }
+
+}
+
func makeCRDSpec(group string, kind string, namespaced bool, versions []string, categories ...string) apiextensionsv1.CustomResourceDefinitionSpec {
scope := apiextensionsv1.NamespaceScoped
if !namespaced {
@deads2k does that restriction for built-in types match your expectation? |
Reminder to myself: assure that aggregated discovery populates singular names. |
Failure seems unrelated to this change; /test pull-kubernetes-e2e-kind-ipv6 |
@deads2k would you mind taking a look at this one?. Thanks. |
I think it does, even though you can only directly observe it via the API and not via tools. The user visible change is that the nondeterministic behavior:
becomes deterministic. |
@@ -94,6 +95,12 @@ func (r *REST) NamespaceScoped() bool { | |||
return r.store.NamespaceScoped() | |||
} | |||
|
|||
var _ rest.SingularNameProvider = &REST{} | |||
|
|||
func (r *REST) GetSingularName() string { |
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.
this stands out. Why does this one need it?
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.
because it doesn't inline r.store and inherit the default implementation (see all other standard rest.Storage implementations forwarding to r.store
in this file)
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.
it does not inherit default store implementation as said ^
type REST struct { |
@@ -1320,6 +1325,12 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error { | |||
if e.DefaultQualifiedResource.Empty() { | |||
return fmt.Errorf("store %#v must have a non-empty qualified resource", e) | |||
} | |||
if e.SingularQualifiedResource.Empty() { |
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.
great.
namespace storage stood out. lgtm once I know why that needed a special case. |
/lgtm |
LGTM label has been added. Git tree hash: 3edda9b27f6880059cbb9d46d884a8d3f6744d6b
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ardaguclu, deads2k The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
var _ rest.SingularNameProvider = &REST{} | ||
|
||
func (r *REST) GetSingularName() string { | ||
return "selfsubjectrulesreview" |
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.
@ardaguclu Hello, it seems like a bug, but I don't know why the tests are passing. I will fix this on promoting selfsubjectreviews to beta, jfyi.
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.
The name is selfsubjectreview
.
What type of PR is this?
/kind bug
What this PR does / why we need it:
Core types don't set their singular names for discovery endpoint(as opposed to CRDs).
This results in nondeterministic behavior when there is a CRD whose shortname is
one of core types singular name format. Thereby, when user requests resource via this short name,
it becomes unpredictable(because it is determined by the order of which one is requested first).
This PR adds singular names for all core types. As a result, core types will
have always higher precedence when their singular name format is requested
regardless of request order.
Which issue(s) this PR fixes:
Fixes #113227
Special notes for your reviewer:
In terms of backwards compatibility, this change has negative impact only on the use cases where people currently are expecting CRDs via singular form of core types. Isn't this already extreme case and incorrect expectation?
Does this PR introduce a user-facing change?