Skip to content

Commit d2211f6

Browse files
add context flag to backend and konnector (#480)
1 parent bd2edb7 commit d2211f6

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

backend/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ func NewConfig(options *options.CompletedOptions) (*Config, error) {
6161
// create clients
6262
rules := clientcmd.NewDefaultClientConfigLoadingRules()
6363
rules.ExplicitPath = options.KubeConfig
64+
var overrides *clientcmd.ConfigOverrides
65+
if options.Context != "" {
66+
overrides = &clientcmd.ConfigOverrides{
67+
CurrentContext: options.Context,
68+
}
69+
}
6470
var err error
65-
config.ClientConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, nil).ClientConfig()
71+
config.ClientConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides).ClientConfig()
6672
if err != nil {
6773
return nil, err
6874
}

backend/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Options struct {
4545

4646
type ExtraOptions struct {
4747
KubeConfig string
48+
Context string
4849

4950
Provider string
5051

@@ -152,6 +153,7 @@ func (options *Options) AddFlags(fs *pflag.FlagSet) {
152153
options.ProviderKcp.AddFlags(fs)
153154

154155
fs.StringVar(&options.KubeConfig, "kubeconfig", options.KubeConfig, "path to a kubeconfig. Only required if out-of-cluster")
156+
fs.StringVar(&options.Context, "context", options.Context, "The name of the kubeconfig context to use.")
155157
fs.StringVar(&options.NamespacePrefix, "namespace-prefix", options.NamespacePrefix, "The prefix to use for cluster namespaces")
156158
fs.StringVar(&options.PrettyName, "pretty-name", options.PrettyName, "Pretty name for the backend")
157159
fs.StringVar(&options.ConsumerScope, "consumer-scope", options.ConsumerScope, "How consumers access the service provider cluster. In Kubernetes, \"namespaced\" allows namespace isolation. In kcp, \"cluster\" allows workspace isolation, and with that allows cluster-scoped resources to bind and it is generally more performant.")

pkg/konnector/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ func NewConfig(options *options.CompletedOptions) (*Config, error) {
5454
// create clients
5555
rules := clientcmd.NewDefaultClientConfigLoadingRules()
5656
rules.ExplicitPath = options.KubeConfigPath
57+
var overrides *clientcmd.ConfigOverrides
58+
if options.Context != "" {
59+
overrides = &clientcmd.ConfigOverrides{
60+
CurrentContext: options.Context,
61+
}
62+
}
5763
var err error
58-
config.ClientConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, nil).ClientConfig()
64+
config.ClientConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides).ClientConfig()
5965
if err != nil {
6066
return nil, err
6167
}

pkg/konnector/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Options struct {
3535

3636
type ExtraOptions struct {
3737
KubeConfigPath string
38+
Context string
3839

3940
LeaseLockName string
4041
LeaseLockNamespace string
@@ -80,6 +81,7 @@ func (options *Options) AddFlags(fs *pflag.FlagSet) {
8081
logsv1.AddFlags(options.Logs, fs)
8182

8283
fs.StringVar(&options.KubeConfigPath, "kubeconfig", options.KubeConfigPath, "Kubeconfig file for the local cluster.")
84+
fs.StringVar(&options.Context, "context", options.Context, "The name of the kubeconfig context to use.")
8385
fs.StringVar(&options.LeaseLockName, "lease-name", options.LeaseLockName, "Name of lease lock")
8486
fs.StringVar(&options.LeaseLockNamespace, "lease-namespace", options.LeaseLockNamespace, "Name of lease lock namespace")
8587
fs.StringVar(&options.ServerAddr, "server-address", options.ServerAddr, "Address for server")

0 commit comments

Comments
 (0)