-
Notifications
You must be signed in to change notification settings - Fork 381
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
cache-server: expose apiresourceschemas and apiexports #1815
cache-server: expose apiresourceschemas and apiexports #1815
Conversation
/hold I still need to test it manually. |
|
||
return wait.PollInfiniteWithContext(ctx, time.Second, func(ctx context.Context) (bool, error) { | ||
for _, crd := range crds { | ||
_, err := apiExtensionsClusterClient.Cluster(SystemCRDLogicalCluster).ApiextensionsV1().CustomResourceDefinitions().Create(ctx, crd, metav1.CreateOptions{}) |
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.
creating crds with empty schemas is cheap and doesn't require creating an in-memory
storage implementation.
it can be reworked in the future if we don't like 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.
the storage is required for listing CRDs
and for discovery (not implemented yet).
675859b
to
f162ca2
Compare
/hold cancel |
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.
Mostly seems reasonable, some small comments
configcrds "github.com/kcp-dev/kcp/config/crds" | ||
) | ||
|
||
var SystemCRDLogicalCluster = logicalcluster.New("system:system-crds") |
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 is a constant somewhere already, could we import 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.
I think we should treat it as a distinct value, I picked up the same logical cluster for symmetry.
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 comment to explain that would be great! Makes sense.
Type: "object", | ||
XPreserveUnknownFields: pointer.BoolPtr(true), | ||
}, | ||
} // wipe the schema, we don't need validation |
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.
Is this the only diff from the other bootstrap functions? could we DRY this out?
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.
we could call CreateSingle
from this function and retry on any error.
@@ -125,17 +143,31 @@ func NewConfig(opts *cacheserveroptions.CompletedOptions) (*Config, error) { | |||
serverConfig.LoopbackClientConfig.DisableCompression = true | |||
clientutils.EnableMultiCluster(serverConfig.LoopbackClientConfig, &serverConfig.Config, "namespaces", "apiservices", "customresourcedefinitions", "clusterroles", "clusterrolebindings", "roles", "rolebindings", "serviceaccounts", "secrets") | |||
|
|||
var err error | |||
c.ApiExtensionsClusterClient, err = apiextensionsclient.NewClusterForConfig(serverConfig.LoopbackClientConfig) |
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: we're moving to the context-based clients instead of NewCluster
- can we do that here as well to save Varsha some work in the future? :)
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.
np, mind sharing an example?
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.
Look for any use of logicalcluster.WithCluster()
e.g.:
return c.kubeClusterClient.CoreV1().Namespaces().Patch(logicalcluster.WithCluster(ctx, clusterName), name, pt, data, opts, subresources...)
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.
okay, but I need a Wildcard
logical cluster for informers, it seems like informers don't support the new way of passing a cluster 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.
Yes, that is the one case where this approach does not work
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.
#1813 fixes that :)
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.
do we need 2
clients until it merges?
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.
Not sure I follow actually - you need a cluster-scoped client for the factory:
# github.com/kcp-dev/kcp/pkg/client/informers
func NewSharedInformerFactoryWithOptions( ... versioned.Interface, ... ) {}
Where you can get such a thing from .Cluster(logicalcluster.Wildcard)
which should be identical to SetCluster()
on the *rest.Config
, no?
# github.com/kcp-dev/kcp/pkg/client/clientset/versioned
func (c *Cluster) Cluster(name v2.Name) Interface {}
So NewClusterForConfig(cfg).Cluster(logicalcluster.Wildcard)
would become NewClientForConfig(kcpclienthelper.SetCluster(rest.CopyConfig(cfg), logicalcluster.Wildcard))
?
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.
something is broken, I think I have to use it along with NewClusterRoundTripper
but then the path seems to be incorrect /clusters/*/clusters/system:system-crds/apis/apiextensions.k8s.io/v1/customresourcedefinitions/apiresourceschemas.apis.kcp.dev
I'd like to proceed with this PR if that's okay. I can revisit using the context-based clients in the future
f162ca2
to
09c3398
Compare
pkg/server/server.go
Outdated
// run inside of a post-start-hook. The k8s APIServer wrote the post-start-hook context code before contexts | ||
// were part of the Go stdlib. | ||
func goContext(parent genericapiserver.PostStartHookContext) context.Context { | ||
func GoContext(parent genericapiserver.PostStartHookContext) context.Context { |
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 don't like creating common/utils
pkgs :P
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.
You and @sttts both ... but I like copy-pasting something 100x even less than I like creating a utility package ;)
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.
moved to a util pkg
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.
util packages 😱
09c3398
to
fe9bf89
Compare
@p0lyn0mial if you wouldn't mind, please prefix the PR titles with the area they're for (it makes it easier to know at a glance) - thanks! /retitle cache-server: expose apiresourceschemas and apiexports |
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.
Other comments can/will be follow-ups.
import ( | ||
"context" | ||
|
||
genericapiserver "k8s.io/apiserver/pkg/server" |
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: If I had a crystal ball, I think I'd make the prophecy that Stefan would want this helper to end up in this upstream package ... :^)
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.
How about moving that into the upstream package?
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: stevekuznetsov 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 |
Summary
exposes schema-less
apiresourceschemas
andapiexports
resources. It allows us to store any fields we need. Since this server will be used by the shards, schemas will be implicit.I did the following manual test which indicates storing
"foo": "bar"
with anapiexport
obj works.POST:
GET:
note for now passing a logical cluster name is not required in the future it might be required along with a shard name.
Related issue(s)
requires kcp-dev/kubernetes#93