Add the kube client qps and burst to the global args
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
committed by
Hidde Beydals
parent
150d9d7ae6
commit
0d8194c800
@@ -36,6 +36,7 @@ import (
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/bootstrap/git"
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
@@ -59,7 +60,8 @@ type PlainGitBootstrapper struct {
|
||||
gpgPassphrase string
|
||||
gpgKeyID string
|
||||
|
||||
restClientGetter genericclioptions.RESTClientGetter
|
||||
restClientGetter genericclioptions.RESTClientGetter
|
||||
restClientOptions *runclient.Options
|
||||
|
||||
postGenerateSecret []PostGenerateSecretFunc
|
||||
|
||||
@@ -168,12 +170,12 @@ func (b *PlainGitBootstrapper) ReconcileComponents(ctx context.Context, manifest
|
||||
if _, err := os.Stat(kfile); err == nil {
|
||||
// Apply the components and their patches
|
||||
b.logger.Actionf("installing components in %q namespace", options.Namespace)
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, kfile); err != nil {
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, kfile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Apply the CRDs and controllers
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, componentsYAML); err != nil {
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, componentsYAML); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -318,7 +320,7 @@ func (b *PlainGitBootstrapper) ReconcileSyncConfig(ctx context.Context, options
|
||||
|
||||
// Apply to cluster
|
||||
b.logger.Actionf("applying sync manifests")
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, filepath.Join(b.git.Path(), kusManifests.Path)); err != nil {
|
||||
if _, err := utils.Apply(ctx, b.restClientGetter, b.restClientOptions, filepath.Join(b.git.Path(), kusManifests.Path)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -351,7 +353,7 @@ func (b *PlainGitBootstrapper) ReportKustomizationHealth(ctx context.Context, op
|
||||
}
|
||||
|
||||
func (b *PlainGitBootstrapper) ReportComponentsHealth(ctx context.Context, install install.Options, timeout time.Duration) error {
|
||||
cfg, err := utils.KubeConfig(b.restClientGetter)
|
||||
cfg, err := utils.KubeConfig(b.restClientGetter, b.restClientOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@ limitations under the License.
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/bootstrap/git"
|
||||
"github.com/fluxcd/flux2/pkg/log"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
)
|
||||
|
||||
type Option interface {
|
||||
@@ -91,18 +94,21 @@ func (o commitMessageAppendixOption) applyGitProvider(b *GitProviderBootstrapper
|
||||
o.applyGit(b.PlainGitBootstrapper)
|
||||
}
|
||||
|
||||
func WithKubeconfig(rcg genericclioptions.RESTClientGetter) Option {
|
||||
func WithKubeconfig(rcg genericclioptions.RESTClientGetter, opts *runclient.Options) Option {
|
||||
return kubeconfigOption{
|
||||
rcg: rcg,
|
||||
rcg: rcg,
|
||||
opts: opts,
|
||||
}
|
||||
}
|
||||
|
||||
type kubeconfigOption struct {
|
||||
rcg genericclioptions.RESTClientGetter
|
||||
rcg genericclioptions.RESTClientGetter
|
||||
opts *runclient.Options
|
||||
}
|
||||
|
||||
func (o kubeconfigOption) applyGit(b *PlainGitBootstrapper) {
|
||||
b.restClientGetter = o.rcg
|
||||
b.restClientOptions = o.opts
|
||||
}
|
||||
|
||||
func (o kubeconfigOption) applyGitProvider(b *GitProviderBootstrapper) {
|
||||
|
||||
@@ -25,9 +25,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||
"github.com/fluxcd/pkg/kustomize"
|
||||
"github.com/theckman/yacspin"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -39,6 +36,12 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||
"github.com/fluxcd/pkg/kustomize"
|
||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -103,8 +106,8 @@ func WithProgressBar() BuilderOptionFunc {
|
||||
|
||||
// NewBuilder returns a new Builder
|
||||
// to dp : create functional options
|
||||
func NewBuilder(rcg *genericclioptions.ConfigFlags, name, resources string, opts ...BuilderOptionFunc) (*Builder, error) {
|
||||
kubeClient, err := utils.KubeClient(rcg)
|
||||
func NewBuilder(rcg *genericclioptions.ConfigFlags, clientOpts *runclient.Options, name, resources string, opts ...BuilderOptionFunc) (*Builder, error) {
|
||||
kubeClient, err := utils.KubeClient(rcg, clientOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -25,19 +25,21 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/ssa"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
|
||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||
"github.com/fluxcd/pkg/ssa"
|
||||
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen/kustomization"
|
||||
)
|
||||
|
||||
// Apply is the equivalent of 'kubectl apply --server-side -f'.
|
||||
// If the given manifest is a kustomization.yaml, then apply performs the equivalent of 'kubectl apply --server-side -k'.
|
||||
func Apply(ctx context.Context, rcg genericclioptions.RESTClientGetter, manifestPath string) (string, error) {
|
||||
func Apply(ctx context.Context, rcg genericclioptions.RESTClientGetter, opts *runclient.Options, manifestPath string) (string, error) {
|
||||
objs, err := readObjects(manifestPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -68,19 +70,19 @@ func Apply(ctx context.Context, rcg genericclioptions.RESTClientGetter, manifest
|
||||
}
|
||||
|
||||
if len(stageOne) > 0 {
|
||||
cs, err := applySet(ctx, rcg, stageOne)
|
||||
cs, err := applySet(ctx, rcg, opts, stageOne)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
changeSet.Append(cs.Entries)
|
||||
}
|
||||
|
||||
if err := waitForSet(rcg, changeSet); err != nil {
|
||||
if err := waitForSet(rcg, opts, changeSet); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(stageTwo) > 0 {
|
||||
cs, err := applySet(ctx, rcg, stageTwo)
|
||||
cs, err := applySet(ctx, rcg, opts, stageTwo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -112,8 +114,8 @@ func readObjects(manifestPath string) ([]*unstructured.Unstructured, error) {
|
||||
return ssa.ReadObjects(bufio.NewReader(ms))
|
||||
}
|
||||
|
||||
func newManager(rcg genericclioptions.RESTClientGetter) (*ssa.ResourceManager, error) {
|
||||
cfg, err := KubeConfig(rcg)
|
||||
func newManager(rcg genericclioptions.RESTClientGetter, opts *runclient.Options) (*ssa.ResourceManager, error) {
|
||||
cfg, err := KubeConfig(rcg, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,8 +136,8 @@ func newManager(rcg genericclioptions.RESTClientGetter) (*ssa.ResourceManager, e
|
||||
|
||||
}
|
||||
|
||||
func applySet(ctx context.Context, rcg genericclioptions.RESTClientGetter, objects []*unstructured.Unstructured) (*ssa.ChangeSet, error) {
|
||||
man, err := newManager(rcg)
|
||||
func applySet(ctx context.Context, rcg genericclioptions.RESTClientGetter, opts *runclient.Options, objects []*unstructured.Unstructured) (*ssa.ChangeSet, error) {
|
||||
man, err := newManager(rcg, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -143,8 +145,8 @@ func applySet(ctx context.Context, rcg genericclioptions.RESTClientGetter, objec
|
||||
return man.ApplyAll(ctx, objects, ssa.DefaultApplyOptions())
|
||||
}
|
||||
|
||||
func waitForSet(rcg genericclioptions.RESTClientGetter, changeSet *ssa.ChangeSet) error {
|
||||
man, err := newManager(rcg)
|
||||
func waitForSet(rcg genericclioptions.RESTClientGetter, opts *runclient.Options, changeSet *ssa.ChangeSet) error {
|
||||
man, err := newManager(rcg, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import (
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta1"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
runclient "github.com/fluxcd/pkg/runtime/client"
|
||||
"github.com/fluxcd/pkg/version"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||
|
||||
@@ -106,15 +107,15 @@ func ExecKubectlCommand(ctx context.Context, mode ExecMode, kubeConfigPath strin
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func KubeConfig(rcg genericclioptions.RESTClientGetter) (*rest.Config, error) {
|
||||
func KubeConfig(rcg genericclioptions.RESTClientGetter, opts *runclient.Options) (*rest.Config, error) {
|
||||
cfg, err := rcg.ToRESTConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes configuration load failed: %w", err)
|
||||
}
|
||||
|
||||
// avoid throttling request when some Flux CRDs are not registered
|
||||
cfg.QPS = 50
|
||||
cfg.Burst = 100
|
||||
cfg.QPS = opts.QPS
|
||||
cfg.Burst = opts.Burst
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
@@ -137,12 +138,15 @@ func NewScheme() *apiruntime.Scheme {
|
||||
return scheme
|
||||
}
|
||||
|
||||
func KubeClient(rcg genericclioptions.RESTClientGetter) (client.WithWatch, error) {
|
||||
func KubeClient(rcg genericclioptions.RESTClientGetter, opts *runclient.Options) (client.WithWatch, error) {
|
||||
cfg, err := rcg.ToRESTConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.QPS = opts.QPS
|
||||
cfg.Burst = opts.Burst
|
||||
|
||||
scheme := NewScheme()
|
||||
kubeClient, err := client.NewWithWatch(cfg, client.Options{
|
||||
Scheme: scheme,
|
||||
|
||||
Reference in New Issue
Block a user