Skip to content

Commit b004ff4

Browse files
committed
feat: support virtual workspace URL path in --config-workspace
Allow --config-workspace to accept a direct URL path (starting with /) in addition to logical cluster paths. This enables init-agent to watch InitTarget/InitTemplate resources via an APIExport virtual workspace, which aggregates resources from multiple provider workspaces. When the value starts with /, it is used as a direct URL path appended to the base KCP host. Otherwise, existing behavior is preserved (appending /clusters/<path>). Ref: #18
1 parent 374f9b1 commit b004ff4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd/init-agent/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"flag"
2222
"fmt"
2323
golog "log"
24+
"strings"
2425

2526
"github.com/go-logr/zapr"
2627
"github.com/spf13/pflag"
@@ -145,7 +146,15 @@ func setupManager(ctx context.Context, cfg *rest.Config, opts *Options) (manager
145146
return nil, fmt.Errorf("failed to register local scheme %s: %w", initializationv1alpha1.SchemeGroupVersion, err)
146147
}
147148

148-
cfg = kcp.RetargetRestConfig(cfg, logicalcluster.Name(opts.ConfigWorkspace))
149+
if strings.HasPrefix(opts.ConfigWorkspace, "/") {
150+
// Direct URL path (e.g., virtual workspace)
151+
stripped := kcp.StripCluster(cfg)
152+
stripped.Host = strings.TrimRight(stripped.Host, "/") + opts.ConfigWorkspace
153+
cfg = stripped
154+
} else {
155+
// Logical cluster path (existing behavior)
156+
cfg = kcp.RetargetRestConfig(cfg, logicalcluster.Name(opts.ConfigWorkspace))
157+
}
149158

150159
return manager.New(cfg, manager.Options{
151160
Scheme: scheme,

cmd/init-agent/options.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ type Options struct {
3434
// work.
3535
// KubeconfigFile string
3636

37-
// ConfigWorkspace is the kcp workspace (either a path or a cluster name)
38-
// where the InitTarget and InitTemplate objects live that should be processed
39-
// by this init-agent.
37+
// ConfigWorkspace is the kcp workspace (either a path, a cluster name, or a
38+
// URL path starting with / for virtual workspaces) where the InitTarget and
39+
// InitTemplate objects live that should be processed by this init-agent.
4040
ConfigWorkspace string
4141

4242
// Whether or not to perform leader election (requires permissions to
@@ -67,7 +67,7 @@ func NewOptions() *Options {
6767
func (o *Options) AddFlags(flags *pflag.FlagSet) {
6868
o.LogOptions.AddPFlags(flags)
6969

70-
flags.StringVar(&o.ConfigWorkspace, "config-workspace", o.ConfigWorkspace, "kcp workspace or cluster where the InitTargets live that should be processed")
70+
flags.StringVar(&o.ConfigWorkspace, "config-workspace", o.ConfigWorkspace, "kcp workspace, cluster, or URL path (starting with /) where the InitTargets live that should be processed")
7171
flags.StringVar(&o.InitTargetSelectorString, "init-target-selector", o.InitTargetSelectorString, "restrict to only process InitTargets matching this label selector (optional)")
7272
flags.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "whether to perform leader election")
7373
flags.StringVar(&o.LeaderElectionNamespace, "leader-election-namespace", o.LeaderElectionNamespace, "Kubernetes namespace for the leader election lease")

0 commit comments

Comments
 (0)