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

bootstrap the root workspace only on the root shard #1587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/apis/tenancy/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
// RootCluster is the root of ClusterWorkspace based logical clusters.
var RootCluster = logicalcluster.New("root")

// RootShard holds a name of the root shard.
var RootShard = "root"

// ClusterWorkspace defines a Kubernetes-cluster-like endpoint that holds a default set
// of resources and exhibits standard Kubernetes API semantics of CRUD operations. It represents
// the full life-cycle of the persisted data in this workspace in a KCP installation.
Expand Down
72 changes: 39 additions & 33 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,20 @@ func (s *Server) Run(ctx context.Context) error {

klog.Infof("Finished starting APIExport and APIBinding informers")

// bootstrap root workspace phase 0, no APIBinding resources yet
if err := configrootphase0.Bootstrap(goContext(ctx),
kcpClusterClient.Cluster(tenancyv1alpha1.RootCluster),
apiextensionsClusterClient.Cluster(tenancyv1alpha1.RootCluster).Discovery(),
dynamicClusterClient.Cluster(tenancyv1alpha1.RootCluster),
); err != nil {
// nolint:nilerr
return nil // don't klog.Fatal. This only happens when context is cancelled.
if s.options.Extra.ShardName == tenancyv1alpha1.RootShard {
// bootstrap root workspace phase 0 only if we are on the root shard, no APIBinding resources yet
if err := configrootphase0.Bootstrap(goContext(ctx),
kcpClusterClient.Cluster(tenancyv1alpha1.RootCluster),
apiextensionsClusterClient.Cluster(tenancyv1alpha1.RootCluster).Discovery(),
dynamicClusterClient.Cluster(tenancyv1alpha1.RootCluster),
); err != nil {
// nolint:nilerr
klog.Errorf("failed to bootstrap root workspace phase 0: %w", err)
return nil // don't klog.Fatal. This only happens when context is cancelled.
}
klog.Infof("Bootstrapped root workspace phase 0")
}

klog.Infof("Bootstrapped root workspace phase 0")

klog.Infof("Getting kcp APIExport identities")

if err := wait.PollImmediateInfiniteWithContext(goContext(ctx), time.Millisecond*500, func(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -465,32 +467,36 @@ func (s *Server) Run(ctx context.Context) error {
klog.Infof("Synced all informers. Ready to start controllers")
close(s.syncedCh)

klog.Infof("Starting bootstrapping root workspace phase 1")
servingCert, _ := server.SecureServingInfo.Cert.CurrentCertKeyContent()
if err := configroot.Bootstrap(goContext(ctx),
apiextensionsClusterClient.Cluster(tenancyv1alpha1.RootCluster).Discovery(),
dynamicClusterClient.Cluster(tenancyv1alpha1.RootCluster),
s.options.Extra.ShardName,
clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
// cross-cluster is the virtual cluster running by default
"shard": {
Server: "https://" + server.ExternalAddress,
CertificateAuthorityData: servingCert, // TODO(sttts): wire controller updating this when it changes, or use CA
if s.options.Extra.ShardName == tenancyv1alpha1.RootShard {
// the root ws is only present on the root shard
klog.Infof("Starting bootstrapping root workspace phase 1")
servingCert, _ := server.SecureServingInfo.Cert.CurrentCertKeyContent()
if err := configroot.Bootstrap(goContext(ctx),
apiextensionsClusterClient.Cluster(tenancyv1alpha1.RootCluster).Discovery(),
dynamicClusterClient.Cluster(tenancyv1alpha1.RootCluster),
s.options.Extra.ShardName,
clientcmdapi.Config{
Clusters: map[string]*clientcmdapi.Cluster{
// cross-cluster is the virtual cluster running by default
"shard": {
Server: "https://" + server.ExternalAddress,
CertificateAuthorityData: servingCert, // TODO(sttts): wire controller updating this when it changes, or use CA
},
},
Contexts: map[string]*clientcmdapi.Context{
"shard": {Cluster: "shard"},
},
CurrentContext: "shard",
},
Contexts: map[string]*clientcmdapi.Context{
"shard": {Cluster: "shard"},
},
CurrentContext: "shard",
},
logicalcluster.New(s.options.HomeWorkspaces.HomeRootPrefix).Base(),
s.options.HomeWorkspaces.HomeCreatorGroups,
); err != nil {
// nolint:nilerr
return nil // don't klog.Fatal. This only happens when context is cancelled.
logicalcluster.New(s.options.HomeWorkspaces.HomeRootPrefix).Base(),
s.options.HomeWorkspaces.HomeCreatorGroups,
); err != nil {
// nolint:nilerr
klog.Errorf("failed to bootstrap root workspace phase 1: %w", err)
return nil // don't klog.Fatal. This only happens when context is cancelled.
}
klog.Infof("Finished bootstrapping root workspace phase 1")
}
klog.Infof("Finished bootstrapping root workspace phase 1")

return nil
})
Expand Down