Skip to content

Commit 634329b

Browse files
committed
enhancement: kubeconfig provider support more params
Signed-off-by: Colvin-Y <[email protected]>
1 parent 5a71e2a commit 634329b

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

providers/kubeconfig/provider.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import (
2929

3030
corev1 "k8s.io/api/core/v1"
3131
apierrors "k8s.io/apimachinery/pkg/api/errors"
32-
"k8s.io/apimachinery/pkg/runtime"
33-
"k8s.io/client-go/kubernetes/scheme"
32+
"k8s.io/client-go/rest"
3433
"k8s.io/client-go/tools/clientcmd"
3534

3635
ctrl "sigs.k8s.io/controller-runtime"
@@ -63,9 +62,6 @@ func New(opts Options) *Provider {
6362
if opts.KubeconfigSecretKey == "" {
6463
opts.KubeconfigSecretKey = DefaultKubeconfigSecretKey
6564
}
66-
if opts.Scheme == nil {
67-
opts.Scheme = scheme.Scheme
68-
}
6965

7066
return &Provider{
7167
opts: opts,
@@ -82,8 +78,10 @@ type Options struct {
8278
KubeconfigSecretLabel string
8379
// KubeconfigSecretKey is the key in the secret data that contains the kubeconfig.
8480
KubeconfigSecretKey string
85-
// Scheme is the scheme to use for the clusters.
86-
Scheme *runtime.Scheme
81+
// ClusterOptions is the list of options to pass to the cluster object.
82+
ClusterOptions []cluster.Option
83+
// RESTOptions is the list of options to pass to the rest client.
84+
RESTOptions []func(cfg *rest.Config) error
8785
}
8886

8987
type index struct {
@@ -259,11 +257,16 @@ func (p *Provider) createAndEngageCluster(ctx context.Context, clusterName strin
259257
return fmt.Errorf("failed to parse kubeconfig: %w", err)
260258
}
261259

260+
// Apply REST options
261+
for _, opt := range p.opts.RESTOptions {
262+
if err := opt(restConfig); err != nil {
263+
return fmt.Errorf("failed to apply REST option: %w", err)
264+
}
265+
}
266+
262267
// Create a new cluster
263268
log.Info("Creating new cluster from kubeconfig")
264-
cl, err := cluster.New(restConfig, func(o *cluster.Options) {
265-
o.Scheme = p.opts.Scheme
266-
})
269+
cl, err := cluster.New(restConfig, p.opts.ClusterOptions...)
267270
if err != nil {
268271
return fmt.Errorf("failed to create cluster: %w", err)
269272
}

providers/kubeconfig/provider_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/util/runtime"
31+
"k8s.io/client-go/kubernetes/scheme"
3132
"k8s.io/client-go/rest"
3233
"k8s.io/client-go/tools/clientcmd"
3334
"k8s.io/client-go/tools/clientcmd/api"
@@ -79,6 +80,18 @@ var _ = Describe("Provider Namespace", Ordered, func() {
7980
KubeconfigSecretLabel: kubeconfigSecretLabel,
8081
Namespace: kubeconfigSecretNamespace,
8182
KubeconfigSecretKey: kubeconfigSecretKey,
83+
RESTOptions: []func(cfg *rest.Config) error{
84+
func(cfg *rest.Config) error {
85+
cfg.QPS = 100
86+
cfg.Burst = 200
87+
return nil
88+
},
89+
},
90+
ClusterOptions: []cluster.Option{
91+
func(clusterOptions *cluster.Options) {
92+
clusterOptions.Scheme = scheme.Scheme
93+
},
94+
},
8295
})
8396

8497
By("Creating a namespace in the local cluster", func() {

0 commit comments

Comments
 (0)