Skip to content
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

wire TemporaryRootShardKcpSharedInformerFactory #1572

Merged

Conversation

p0lyn0mial
Copy link
Contributor

@p0lyn0mial p0lyn0mial commented Jul 20, 2022

Summary

wires TemporaryRootShardKcpSharedInformerFactory, essentially when c.Options.Extra.RootShardKubeconfigFile is set then:

  • we start a new SharedInformerFactory for the root shard
  • we create a KcpClusterClient to the root shard
  • we registerer a new shard in the root namespace

Related issue(s)

Fixes #

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 20, 2022
@openshift-ci openshift-ci bot requested review from davidfestal and sttts July 20, 2022 10:48
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from c3fc225 to eb2c902 Compare July 21, 2022 15:22
@p0lyn0mial
Copy link
Contributor Author

/retest

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2022

getAPIResourceSchema: func(clusterName logicalcluster.Name, name string) (*apisv1alpha1.APIResourceSchema, error) {
return apiResourceSchemaInformer.Lister().Get(clusters.ToClusterAwareKey(clusterName, name))
apiResourceSchema, err := apiResourceSchemaInformer.Lister().Get(clusters.ToClusterAwareKey(clusterName, name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the expected sequencing here? I'm not sure we want to have this structure around in the code for a long time, it seems easy to do incorrectly from the dev side.

@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from eb2c902 to 3112756 Compare July 26, 2022 11:12
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 26, 2022
@p0lyn0mial p0lyn0mial changed the title [WIP] multiple shard support multiple shard support Jul 26, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 26, 2022
@@ -28,6 +28,7 @@ import (
apiextensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs better commit name

@@ -121,6 +122,9 @@ type ExtraConfig struct {
// resource identities for the root shard into the rest.Config used by the client.
// Only after it succeeds, the clients can wildcard-list/watch most kcp resources.
ResolveRootKcpShardIdentities func(ctx context.Context) error

// RootShardKcpClusterClient holds a cluster-wide client to the root shard
RootShardKcpClusterClient *kcpclient.Cluster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move up to the clients

@p0lyn0mial p0lyn0mial changed the title multiple shard support wire TemporaryRootShardKcpSharedInformerFactory Jul 26, 2022
// ResolveRootKcpShardIdentities is to be called on server start until it succeeds. It injects the kcp
// resource identities for the root shard into the rest.Config used by the client.
// Only after it succeeds, the clients can wildcard-list/watch most kcp resources.
ResolveRootKcpShardIdentities func(ctx context.Context) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have that at the top already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the root shard only, resolved in a different place. I think we need both.

pkg/server/server.go Outdated Show resolved Hide resolved
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from f0a34db to e6a75d7 Compare July 26, 2022 12:30
// Only after it succeeds, the clients can wildcard-list/watch most kcp resources.
ResolveRootKcpShardIdentities func(ctx context.Context) error

identityConfig *rest.Config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am still confused about the new fields. The existing should do exactly that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I think I know what you mean :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what we need #1620

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you wire it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, err
}
var rootKcpShardIdentityConfig *rest.Config
rootKcpShardIdentityConfig, c.ResolveRootKcpShardIdentities = boostrap.NewConfigWithWildcardIdentities(nonIdentityRootKcpShardSystemAdminConfig, boostrap.KcpRootGroupExportNames, boostrap.KcpRootGroupResourceExportNames, nonIdentityRootKcpShardClient.Cluster(tenancyv1alpha1.RootCluster))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am lost in this wiring. Don't we have these two cases:

  1. we are the root shard. Then we need the old, staged flow where we start the local informer only for apis.kcp.dev first, then pick the identities from the APIExports, inject them into the roundtripper and then start the rest.
  2. we are NOT the root shard. Then we can run resolveRootKcpShardIdentities here in-place very early before anything of the code further down runs, i.e. before any of the informers have been started.

@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from e6a75d7 to 0df6f34 Compare July 28, 2022 12:27
}

if rootKcpShardIdentityRoundTripper != nil {
c.identityConfig = rest.CopyConfig(c.GenericConfig.LoopbackClientConfig)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could move this inside the if clause in L190

c.identityConfig = rest.CopyConfig(c.GenericConfig.LoopbackClientConfig)
c.identityConfig.Wrap(rootKcpShardIdentityRoundTripper)
} else {
// The informers here are not used before the informers are actually started (i.e. no race).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this into the else clause in L214

@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from 0df6f34 to 99baec0 Compare July 28, 2022 12:55
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 30, 2022
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from 99baec0 to eb21f33 Compare August 1, 2022 07:03
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 1, 2022
NewWildcardIdentitiesWrappingRoundTripper creates a HTTP RoundTripper that injected resource identities for
individual group or group resources. Each group or resource is coming from one APIExport whose
names are passed in as a map.
The RoundTripper is exposed as a function that allows wrapping the RoundTripper.

The method also returns the resolve function that gets the APIExports and extract the identities.
The resolve func might return an error if the APIExport is not found or for other reason. Only
after it succeeds a client using the returned RoundTripper can use the group and group resources
with identities.
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from eb21f33 to 3639d33 Compare August 1, 2022 07:03
return nil, err
}
var rootKcpShardIdentityRoundTripper func(rt http.RoundTripper) http.RoundTripper
rootKcpShardIdentityRoundTripper, c.resolveIdentities = boostrap.NewWildcardIdentitiesWrappingRoundTripper(boostrap.KcpRootGroupExportNames, boostrap.KcpRootGroupResourceExportNames, nonIdentityRootKcpShardClient.Cluster(tenancyv1alpha1.RootCluster))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to resolve it here, config is for setting up configuration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an argument indeed

@@ -172,24 +173,76 @@ func (s *Server) Run(ctx context.Context) error {
return nil // don't klog.Fatal. This only happens when context is cancelled.
}
klog.Infof("Bootstrapped root workspace phase 0")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the flow is:

  1. common
  2. root
  3. non-root
  4. common
  5. root (moving 4 and 5 breaks the server, not sure it can be done in any other way)

@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from 3639d33 to ad0010a Compare August 1, 2022 07:44
@@ -86,6 +87,8 @@ type ExtraConfig struct {
KubeClusterClient kubernetes.ClusterInterface
ApiExtensionsClusterClient apiextensionsclient.ClusterInterface
KcpClusterClient kcpclient.ClusterInterface
// RootShardKcpClusterClient holds a cluster-wide client to the root shard
RootShardKcpClusterClient *kcpclient.Cluster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ClusterInterface

@@ -86,6 +87,8 @@ type ExtraConfig struct {
KubeClusterClient kubernetes.ClusterInterface
ApiExtensionsClusterClient apiextensionsclient.ClusterInterface
KcpClusterClient kcpclient.ClusterInterface
// RootShardKcpClusterClient holds a cluster-wide client to the root shard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the comment. Doesn't add anything :)

rootKcpShardIdentityRoundTripper, c.resolveIdentities = boostrap.NewWildcardIdentitiesWrappingRoundTripper(boostrap.KcpRootGroupExportNames, boostrap.KcpRootGroupResourceExportNames, nonIdentityRootKcpShardClient.Cluster(tenancyv1alpha1.RootCluster))
rootKcpShardIdentityConfig := rest.CopyConfig(nonIdentityRootKcpShardSystemAdminConfig)
rootKcpShardIdentityConfig.Wrap(rootKcpShardIdentityRoundTripper)
c.RootShardKcpClusterClient, err = kcpclient.NewClusterForConfig(rootKcpShardIdentityConfig) // this is now generic to be used for all kcp API groups
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is not correct. The client can be used after resolving via c.resolveIdentities. Would just drop the comment.

pkg/server/config.go Outdated Show resolved Hide resolved
pkg/server/config.go Outdated Show resolved Hide resolved
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from ad0010a to 64aa157 Compare August 1, 2022 09:09
@p0lyn0mial p0lyn0mial force-pushed the multiple-shard-support branch from 64aa157 to c881323 Compare August 1, 2022 09:24
@sttts
Copy link
Member

sttts commented Aug 1, 2022

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 1, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2022
@p0lyn0mial
Copy link
Contributor Author

/retest

2 similar comments
@sttts
Copy link
Member

sttts commented Aug 1, 2022

/retest

@sttts
Copy link
Member

sttts commented Aug 1, 2022

/retest

@openshift-merge-robot openshift-merge-robot merged commit 614a724 into kcp-dev:main Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants