Skip to content

Commit

Permalink
workspace controller: use loopback client for local shard
Browse files Browse the repository at this point in the history
This means we can bootstrap without relying on the shard
BaseURL, which may not be available during bootstrapping
e.g if the endpoint is behind a k8s service controlled by
a readiness probe
  • Loading branch information
Steven Hardy committed Jan 5, 2023
1 parent ac0b2c4 commit e5f1ad0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/reconciler/tenancy/workspace/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
)

func NewController(
shardName string,
shardExternalURL func() string,
kcpClusterClient kcpclientset.ClusterInterface,
kubeClusterClient kubernetes.ClusterInterface,
Expand All @@ -66,6 +67,7 @@ func NewController(
c := &Controller{
queue: queue,

shardName: shardName,
shardExternalURL: shardExternalURL,

logicalClusterAdminConfig: logicalClusterAdminConfig,
Expand Down Expand Up @@ -119,6 +121,7 @@ type workspaceResource = committer.Resource[*tenancyv1beta1.WorkspaceSpec, *tena
type Controller struct {
queue workqueue.RateLimitingInterface

shardName string
shardExternalURL func() string
logicalClusterAdminConfig *rest.Config

Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/tenancy/workspace/workspace_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (c *Controller) reconcile(ctx context.Context, ws *tenancyv1beta1.Workspace
// the returned client establishes a direct connection with the shard with credentials stored in r.logicalClusterAdminConfig.
// TODO:(p0lyn0mial): make it more efficient, maybe we need a per shard client pool or we could use an HTTPRoundTripper
kcpDirectClientFor := func(shard *corev1alpha1.Shard) (kcpclientset.ClusterInterface, error) {
if shard.Name == c.shardName {
return c.kcpClusterClient, nil
}
shardConfig := restclient.CopyConfig(c.logicalClusterAdminConfig)
shardConfig.Host = shard.Spec.BaseURL
shardClient, err := kcpclientset.NewForConfig(shardConfig)
Expand All @@ -78,6 +81,9 @@ func (c *Controller) reconcile(ctx context.Context, ws *tenancyv1beta1.Workspace
// the returned client establishes a direct connection with the shard with credentials stored in r.logicalClusterAdminConfig.
// TODO:(p0lyn0mial): make it more efficient, maybe we need a per shard client pool or we could use an HTTPRoundTripper
kubeDirectClientFor := func(shard *corev1alpha1.Shard) (kubernetes.ClusterInterface, error) {
if shard.Name == c.shardName {
return c.kubeClusterClient, nil
}
shardConfig := restclient.CopyConfig(c.logicalClusterAdminConfig)
shardConfig.Host = shard.Spec.BaseURL
shardClient, err := kubernetes.NewForConfig(shardConfig)
Expand Down
1 change: 1 addition & 0 deletions pkg/server/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func (s *Server) installWorkspaceScheduler(ctx context.Context, config *rest.Con
logicalClusterAdminConfig = rest.AddUserAgent(logicalClusterAdminConfig, workspace.ControllerName)

workspaceController, err := workspace.NewController(
s.Options.Extra.ShardName,
s.CompletedConfig.ShardExternalURL,
kcpClusterClient,
kubeClusterClient,
Expand Down

0 comments on commit e5f1ad0

Please sign in to comment.