Skip to content

Commit fe57497

Browse files
committed
Add --kubeconfig-host-override and --kubeconfig-ca-override flags
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent a4959e0 commit fe57497

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

cmd/api-syncagent/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func run(ctx context.Context, log *zap.SugaredLogger, opts *Options) error {
119119
log.Infow("Resolved APIExport", "apigroup", opts.APIExportRef, "workspace", lcPath, "logicalcluster", lcName)
120120

121121
// init the "permanent" platform cluster connection
122-
platformCluster, err := setupPlatformCluster(platformRestConfig, opts.APIExportRef)
122+
platformCluster, err := setupPlatformCluster(platformRestConfig, opts)
123123
if err != nil {
124124
return fmt.Errorf("failed to initialize platform cluster: %w", err)
125125
}
@@ -149,8 +149,21 @@ func run(ctx context.Context, log *zap.SugaredLogger, opts *Options) error {
149149

150150
func setupLocalManager(ctx context.Context, opts *Options) (manager.Manager, error) {
151151
scheme := runtime.NewScheme()
152+
restConfig := ctrlruntime.GetConfigOrDie()
152153

153-
mgr, err := manager.New(ctrlruntime.GetConfigOrDie(), manager.Options{
154+
if opts.KubeconfigHostOverride != "" {
155+
restConfig.Host = opts.KubeconfigHostOverride
156+
}
157+
158+
if opts.KubeconfigCAFileOverride != "" {
159+
// override the caData if it exists.
160+
if len(restConfig.TLSClientConfig.CAData) > 0 {
161+
restConfig.TLSClientConfig.CAData = nil
162+
}
163+
restConfig.TLSClientConfig.CAFile = opts.KubeconfigCAFileOverride
164+
}
165+
166+
mgr, err := manager.New(restConfig, manager.Options{
154167
Scheme: scheme,
155168
BaseContext: func() context.Context {
156169
return ctx
@@ -220,7 +233,7 @@ func resolveAPIExport(ctx context.Context, restConfig *rest.Config, apiExportRef
220233

221234
// setupPlatformCluster sets up a plain, non-kcp-aware ctrl-runtime Cluster object
222235
// that is solvely used to interact with the APIExport and APIResourceSchemas.
223-
func setupPlatformCluster(restConfig *rest.Config, apiexportRef string) (cluster.Cluster, error) {
236+
func setupPlatformCluster(restConfig *rest.Config, opts *Options) (cluster.Cluster, error) {
224237
scheme := runtime.NewScheme()
225238

226239
if err := kcpdevv1alpha1.AddToScheme(scheme); err != nil {
@@ -239,7 +252,7 @@ func setupPlatformCluster(restConfig *rest.Config, apiexportRef string) (cluster
239252
Scheme: scheme,
240253
ByObject: map[ctrlruntimeclient.Object]cache.ByObject{
241254
&kcpdevv1alpha1.APIExport{}: {
242-
Field: fields.SelectorFromSet(fields.Set{"metadata.name": apiexportRef}),
255+
Field: fields.SelectorFromSet(fields.Set{"metadata.name": opts.APIExportRef}),
243256
},
244257
},
245258
}

cmd/api-syncagent/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ type Options struct {
6161
PublishedResourceSelectorString string
6262
PublishedResourceSelector labels.Selector
6363

64+
KubeconfigHostOverride string
65+
KubeconfigCAFileOverride string
66+
6467
LogOptions log.Options
6568
}
6669

@@ -80,6 +83,8 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
8083
flags.StringVar(&o.APIExportRef, "apiexport-ref", o.APIExportRef, "name of the APIExport in kcp that this Sync Agent is powering")
8184
flags.StringVar(&o.PublishedResourceSelectorString, "published-resource-selector", o.PublishedResourceSelectorString, "restrict this Sync Agent to only process PublishedResources matching this label selector (optional)")
8285
flags.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "whether to perform leader election")
86+
flags.StringVar(&o.KubeconfigHostOverride, "kubeconfig-host-override", o.KubeconfigHostOverride, "Override the host configured in the local kubeconfig")
87+
flags.StringVar(&o.KubeconfigCAFileOverride, "kubeconfig-ca-file-override", o.KubeconfigCAFileOverride, "Override the server CA file configured in the local kubeconfig")
8388
}
8489

8590
func (o *Options) Validate() error {

0 commit comments

Comments
 (0)