From 0d8194c800482b6f8e7ba8aeec25ceeb8681e4c5 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 24 Mar 2022 20:02:17 +0200 Subject: [PATCH] Add the kube client qps and burst to the global args Signed-off-by: Stefan Prodan --- cmd/flux/bootstrap_bitbucket_server.go | 4 ++-- cmd/flux/bootstrap_git.go | 4 ++-- cmd/flux/bootstrap_github.go | 4 ++-- cmd/flux/bootstrap_gitlab.go | 4 ++-- cmd/flux/build_kustomization.go | 2 +- cmd/flux/check.go | 6 +++--- cmd/flux/completion.go | 2 +- cmd/flux/create.go | 2 +- cmd/flux/create_alert.go | 2 +- cmd/flux/create_alertprovider.go | 2 +- cmd/flux/create_helmrelease.go | 2 +- cmd/flux/create_kustomization.go | 2 +- cmd/flux/create_receiver.go | 2 +- cmd/flux/create_secret_git.go | 2 +- cmd/flux/create_secret_helm.go | 2 +- cmd/flux/create_secret_tls.go | 2 +- cmd/flux/create_source_bucket.go | 2 +- cmd/flux/create_source_git.go | 2 +- cmd/flux/create_source_helm.go | 2 +- cmd/flux/create_tenant.go | 2 +- cmd/flux/delete.go | 2 +- cmd/flux/diff_kustomization.go | 4 ++-- cmd/flux/diff_kustomization_test.go | 2 +- cmd/flux/export.go | 2 +- cmd/flux/export_secret.go | 2 +- cmd/flux/get.go | 2 +- cmd/flux/install.go | 4 ++-- cmd/flux/logs.go | 2 +- cmd/flux/main.go | 5 +++++ cmd/flux/reconcile.go | 2 +- cmd/flux/reconcile_alertprovider.go | 2 +- cmd/flux/reconcile_receiver.go | 2 +- cmd/flux/reconcile_with_source.go | 2 +- cmd/flux/resume.go | 2 +- cmd/flux/suspend.go | 2 +- cmd/flux/trace.go | 2 +- cmd/flux/tree_kustomization.go | 2 +- cmd/flux/uninstall.go | 2 +- cmd/flux/version.go | 2 +- go.mod | 10 ++++++++++ go.sum | 8 +++++++- internal/bootstrap/bootstrap_plain_git.go | 12 +++++++----- internal/bootstrap/options.go | 14 +++++++++---- internal/build/build.go | 13 +++++++----- internal/utils/apply.go | 24 ++++++++++++----------- internal/utils/utils.go | 12 ++++++++---- 46 files changed, 114 insertions(+), 76 deletions(-) diff --git a/cmd/flux/bootstrap_bitbucket_server.go b/cmd/flux/bootstrap_bitbucket_server.go index d71754e4..4898e1fe 100644 --- a/cmd/flux/bootstrap_bitbucket_server.go +++ b/cmd/flux/bootstrap_bitbucket_server.go @@ -121,7 +121,7 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } @@ -251,7 +251,7 @@ func bootstrapBServerCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(bServerArgs.teams, bServerDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(bServerArgs.readWriteKey), - bootstrap.WithKubeconfig(kubeconfigArgs), + bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions), bootstrap.WithLogger(logger), bootstrap.WithCABundle(caBundle), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), diff --git a/cmd/flux/bootstrap_git.go b/cmd/flux/bootstrap_git.go index 91738ae5..3104ea97 100644 --- a/cmd/flux/bootstrap_git.go +++ b/cmd/flux/bootstrap_git.go @@ -101,7 +101,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } @@ -225,7 +225,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithBranch(bootstrapArgs.branch), bootstrap.WithAuthor(bootstrapArgs.authorName, bootstrapArgs.authorEmail), bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), - bootstrap.WithKubeconfig(kubeconfigArgs), + bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions), bootstrap.WithPostGenerateSecretFunc(promptPublicKey), bootstrap.WithLogger(logger), bootstrap.WithCABundle(caBundle), diff --git a/cmd/flux/bootstrap_github.go b/cmd/flux/bootstrap_github.go index 904f6890..3f2ff342 100644 --- a/cmd/flux/bootstrap_github.go +++ b/cmd/flux/bootstrap_github.go @@ -125,7 +125,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } @@ -240,7 +240,7 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(githubArgs.teams, ghDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(githubArgs.readWriteKey), - bootstrap.WithKubeconfig(kubeconfigArgs), + bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions), bootstrap.WithLogger(logger), bootstrap.WithCABundle(caBundle), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), diff --git a/cmd/flux/bootstrap_gitlab.go b/cmd/flux/bootstrap_gitlab.go index 1e58834d..afebfa91 100644 --- a/cmd/flux/bootstrap_gitlab.go +++ b/cmd/flux/bootstrap_gitlab.go @@ -129,7 +129,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } @@ -254,7 +254,7 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { bootstrap.WithCommitMessageAppendix(bootstrapArgs.commitMessageAppendix), bootstrap.WithProviderTeamPermissions(mapTeamSlice(gitlabArgs.teams, glDefaultPermission)), bootstrap.WithReadWriteKeyPermissions(gitlabArgs.readWriteKey), - bootstrap.WithKubeconfig(kubeconfigArgs), + bootstrap.WithKubeconfig(kubeconfigArgs, kubeclientOptions), bootstrap.WithLogger(logger), bootstrap.WithCABundle(caBundle), bootstrap.WithGitCommitSigning(bootstrapArgs.gpgKeyRingPath, bootstrapArgs.gpgPassphrase, bootstrapArgs.gpgKeyID), diff --git a/cmd/flux/build_kustomization.go b/cmd/flux/build_kustomization.go index 966046b7..41280976 100644 --- a/cmd/flux/build_kustomization.go +++ b/cmd/flux/build_kustomization.go @@ -65,7 +65,7 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("invalid resource path %q", buildKsArgs.path) } - builder, err := build.NewBuilder(kubeconfigArgs, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout)) + builder, err := build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, buildKsArgs.path, build.WithTimeout(rootArgs.timeout)) if err != nil { return err } diff --git a/cmd/flux/check.go b/cmd/flux/check.go index d530f553..5ad70f9b 100644 --- a/cmd/flux/check.go +++ b/cmd/flux/check.go @@ -125,7 +125,7 @@ func fluxCheck() { } func kubernetesCheck(constraints []string) bool { - cfg, err := utils.KubeConfig(kubeconfigArgs) + cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions) if err != nil { logger.Failuref("Kubernetes client initialization failed: %s", err.Error()) return false @@ -173,7 +173,7 @@ func componentsCheck() bool { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeConfig, err := utils.KubeConfig(kubeconfigArgs) + kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions) if err != nil { return false } @@ -183,7 +183,7 @@ func componentsCheck() bool { return false } - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return false } diff --git a/cmd/flux/completion.go b/cmd/flux/completion.go index 06beac2a..c24c16be 100644 --- a/cmd/flux/completion.go +++ b/cmd/flux/completion.go @@ -60,7 +60,7 @@ func resourceNamesCompletionFunc(gvk schema.GroupVersionKind) func(cmd *cobra.Co ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - cfg, err := utils.KubeConfig(kubeconfigArgs) + cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions) if err != nil { return completionError(err) } diff --git a/cmd/flux/create.go b/cmd/flux/create.go index 9aed0c43..ee339775 100644 --- a/cmd/flux/create.go +++ b/cmd/flux/create.go @@ -117,7 +117,7 @@ func (names apiType) upsertAndWait(object upsertWaitable, mutate func() error) e ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) // NB globals + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) // NB globals if err != nil { return err } diff --git a/cmd/flux/create_alert.go b/cmd/flux/create_alert.go index 7f9968b8..282f8a70 100644 --- a/cmd/flux/create_alert.go +++ b/cmd/flux/create_alert.go @@ -119,7 +119,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_alertprovider.go b/cmd/flux/create_alertprovider.go index 2663482c..fe4d0651 100644 --- a/cmd/flux/create_alertprovider.go +++ b/cmd/flux/create_alertprovider.go @@ -115,7 +115,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_helmrelease.go b/cmd/flux/create_helmrelease.go index d8f37cc5..a6705f29 100644 --- a/cmd/flux/create_helmrelease.go +++ b/cmd/flux/create_helmrelease.go @@ -247,7 +247,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_kustomization.go b/cmd/flux/create_kustomization.go index 4d0ebb99..ef55c23c 100644 --- a/cmd/flux/create_kustomization.go +++ b/cmd/flux/create_kustomization.go @@ -229,7 +229,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_receiver.go b/cmd/flux/create_receiver.go index 6533f173..47b2570f 100644 --- a/cmd/flux/create_receiver.go +++ b/cmd/flux/create_receiver.go @@ -127,7 +127,7 @@ func createReceiverCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_secret_git.go b/cmd/flux/create_secret_git.go index 0effc1b5..054c8a98 100644 --- a/cmd/flux/create_secret_git.go +++ b/cmd/flux/create_secret_git.go @@ -173,7 +173,7 @@ func createSecretGitCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_secret_helm.go b/cmd/flux/create_secret_helm.go index 80a7ce9d..1928c109 100644 --- a/cmd/flux/create_secret_helm.go +++ b/cmd/flux/create_secret_helm.go @@ -96,7 +96,7 @@ func createSecretHelmCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_secret_tls.go b/cmd/flux/create_secret_tls.go index b89a2601..e3afd380 100644 --- a/cmd/flux/create_secret_tls.go +++ b/cmd/flux/create_secret_tls.go @@ -93,7 +93,7 @@ func createSecretTLSCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_source_bucket.go b/cmd/flux/create_source_bucket.go index 6160be0c..4ba4d636 100644 --- a/cmd/flux/create_source_bucket.go +++ b/cmd/flux/create_source_bucket.go @@ -151,7 +151,7 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_source_git.go b/cmd/flux/create_source_git.go index 28c1be50..a520523e 100644 --- a/cmd/flux/create_source_git.go +++ b/cmd/flux/create_source_git.go @@ -234,7 +234,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_source_helm.go b/cmd/flux/create_source_helm.go index 789ff6e5..d294aace 100644 --- a/cmd/flux/create_source_helm.go +++ b/cmd/flux/create_source_helm.go @@ -144,7 +144,7 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/create_tenant.go b/cmd/flux/create_tenant.go index 4ac8eb96..deb62f90 100644 --- a/cmd/flux/create_tenant.go +++ b/cmd/flux/create_tenant.go @@ -156,7 +156,7 @@ func createTenantCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/delete.go b/cmd/flux/delete.go index 7facf933..ae808b77 100644 --- a/cmd/flux/delete.go +++ b/cmd/flux/delete.go @@ -60,7 +60,7 @@ func (del deleteCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/diff_kustomization.go b/cmd/flux/diff_kustomization.go index 04628ad7..8be50fc1 100644 --- a/cmd/flux/diff_kustomization.go +++ b/cmd/flux/diff_kustomization.go @@ -69,9 +69,9 @@ func diffKsCmdRun(cmd *cobra.Command, args []string) error { var builder *build.Builder var err error if diffKsArgs.progressBar { - builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar()) + builder, err = build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar()) } else { - builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout)) + builder, err = build.NewBuilder(kubeconfigArgs, kubeclientOptions, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout)) } if err != nil { diff --git a/cmd/flux/diff_kustomization_test.go b/cmd/flux/diff_kustomization_test.go index db309ea8..60e73a6c 100644 --- a/cmd/flux/diff_kustomization_test.go +++ b/cmd/flux/diff_kustomization_test.go @@ -97,7 +97,7 @@ func TestDiffKustomization(t *testing.T) { "fluxns": allocateNamespace("flux-system"), } - b, _ := build.NewBuilder(kubeconfigArgs, "podinfo", "") + b, _ := build.NewBuilder(kubeconfigArgs, kubeclientOptions, "podinfo", "") resourceManager, err := b.Manager() if err != nil { diff --git a/cmd/flux/export.go b/cmd/flux/export.go index e9b3be11..4291ee5f 100644 --- a/cmd/flux/export.go +++ b/cmd/flux/export.go @@ -74,7 +74,7 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/export_secret.go b/cmd/flux/export_secret.go index eb7dfb05..1c9e475d 100644 --- a/cmd/flux/export_secret.go +++ b/cmd/flux/export_secret.go @@ -59,7 +59,7 @@ func (export exportWithSecretCommand) run(cmd *cobra.Command, args []string) err ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/get.go b/cmd/flux/get.go index 29fa1c2d..ac099a9f 100644 --- a/cmd/flux/get.go +++ b/cmd/flux/get.go @@ -136,7 +136,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/install.go b/cmd/flux/install.go index 11e6ee77..616e3c95 100644 --- a/cmd/flux/install.go +++ b/cmd/flux/install.go @@ -193,14 +193,14 @@ func installCmdRun(cmd *cobra.Command, args []string) error { return nil } - applyOutput, err := utils.Apply(ctx, kubeconfigArgs, filepath.Join(tmpDir, manifest.Path)) + applyOutput, err := utils.Apply(ctx, kubeconfigArgs, kubeclientOptions, filepath.Join(tmpDir, manifest.Path)) if err != nil { return fmt.Errorf("install failed: %w", err) } fmt.Fprintln(os.Stderr, applyOutput) - kubeConfig, err := utils.KubeConfig(kubeconfigArgs) + kubeConfig, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions) if err != nil { return fmt.Errorf("install failed: %w", err) } diff --git a/cmd/flux/logs.go b/cmd/flux/logs.go index b16d044d..50cf96af 100644 --- a/cmd/flux/logs.go +++ b/cmd/flux/logs.go @@ -99,7 +99,7 @@ func logsCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - cfg, err := utils.KubeConfig(kubeconfigArgs) + cfg, err := utils.KubeConfig(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/main.go b/cmd/flux/main.go index cf803e5d..9c49b3c5 100644 --- a/cmd/flux/main.go +++ b/cmd/flux/main.go @@ -30,6 +30,8 @@ import ( "k8s.io/cli-runtime/pkg/genericclioptions" _ "k8s.io/client-go/plugin/pkg/client/auth" + runclient "github.com/fluxcd/pkg/runtime/client" + "github.com/fluxcd/flux2/pkg/manifestgen/install" ) @@ -117,6 +119,7 @@ func (r *RequestError) Error() string { var rootArgs = NewRootFlags() var kubeconfigArgs = genericclioptions.NewConfigFlags(false) +var kubeclientOptions = new(runclient.Options) func init() { rootCmd.PersistentFlags().DurationVar(&rootArgs.timeout, "timeout", 5*time.Minute, "timeout for this operation") @@ -134,6 +137,8 @@ func init() { kubeconfigArgs.APIServer = &apiServer rootCmd.PersistentFlags().StringVar(kubeconfigArgs.APIServer, "server", *kubeconfigArgs.APIServer, "The address and port of the Kubernetes API server") + kubeclientOptions.BindFlags(rootCmd.PersistentFlags()) + rootCmd.RegisterFlagCompletionFunc("context", contextsCompletionFunc) rootCmd.RegisterFlagCompletionFunc("namespace", resourceNamesCompletionFunc(corev1.SchemeGroupVersion.WithKind("Namespace"))) diff --git a/cmd/flux/reconcile.go b/cmd/flux/reconcile.go index 4ce8cc2c..d116dddb 100644 --- a/cmd/flux/reconcile.go +++ b/cmd/flux/reconcile.go @@ -85,7 +85,7 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/reconcile_alertprovider.go b/cmd/flux/reconcile_alertprovider.go index df24a68e..f5399802 100644 --- a/cmd/flux/reconcile_alertprovider.go +++ b/cmd/flux/reconcile_alertprovider.go @@ -54,7 +54,7 @@ func reconcileAlertProviderCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/reconcile_receiver.go b/cmd/flux/reconcile_receiver.go index 676aa30a..6f13a35f 100644 --- a/cmd/flux/reconcile_receiver.go +++ b/cmd/flux/reconcile_receiver.go @@ -54,7 +54,7 @@ func reconcileReceiverCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/reconcile_with_source.go b/cmd/flux/reconcile_with_source.go index 55361372..0eda5f60 100644 --- a/cmd/flux/reconcile_with_source.go +++ b/cmd/flux/reconcile_with_source.go @@ -35,7 +35,7 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 38613eff..368c5e59 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -76,7 +76,7 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/suspend.go b/cmd/flux/suspend.go index 6b31f5c0..58f7a962 100644 --- a/cmd/flux/suspend.go +++ b/cmd/flux/suspend.go @@ -70,7 +70,7 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/trace.go b/cmd/flux/trace.go index 27227f88..926b6016 100644 --- a/cmd/flux/trace.go +++ b/cmd/flux/trace.go @@ -84,7 +84,7 @@ func traceCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/tree_kustomization.go b/cmd/flux/tree_kustomization.go index 9cb9ea2b..c471295f 100644 --- a/cmd/flux/tree_kustomization.go +++ b/cmd/flux/tree_kustomization.go @@ -77,7 +77,7 @@ func treeKsCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/uninstall.go b/cmd/flux/uninstall.go index c26cbf00..d982ed5b 100644 --- a/cmd/flux/uninstall.go +++ b/cmd/flux/uninstall.go @@ -82,7 +82,7 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) defer cancel() - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/cmd/flux/version.go b/cmd/flux/version.go index f5da9e29..8d563dc1 100644 --- a/cmd/flux/version.go +++ b/cmd/flux/version.go @@ -74,7 +74,7 @@ func versionCmdRun(cmd *cobra.Command, args []string) error { info["flux"] = rootArgs.defaults.Version if !versionArgs.client { - kubeClient, err := utils.KubeClient(kubeconfigArgs) + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) if err != nil { return err } diff --git a/go.mod b/go.mod index a6ca1c2f..2d2a4ee4 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,8 @@ require ( github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/acomagu/bufpipe v1.0.3 // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect @@ -76,6 +78,7 @@ require ( github.com/fluxcd/pkg/apis/acl v0.0.3 // indirect github.com/fluxcd/pkg/apis/kustomize v0.3.2 // indirect github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect + github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/fvbommel/sortorder v1.0.1 // indirect github.com/go-errors/errors v1.0.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect @@ -85,6 +88,7 @@ require ( github.com/go-openapi/jsonreference v0.19.5 // indirect github.com/go-openapi/swag v0.19.14 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/gonvenience/neat v1.3.9 // indirect github.com/gonvenience/term v1.0.2 // indirect @@ -113,6 +117,7 @@ require ( github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect @@ -126,6 +131,10 @@ require ( github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v1.12.1 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.32.1 // indirect + github.com/prometheus/procfs v0.7.3 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday v1.5.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -143,6 +152,7 @@ require ( golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect + gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index a89b47c9..d1f3687b 100644 --- a/go.sum +++ b/go.sum @@ -163,7 +163,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= @@ -361,6 +360,7 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go. github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws= +github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= @@ -679,6 +679,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -902,6 +903,7 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -918,6 +920,7 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8 github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= github.com/prometheus/common v0.28.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= +github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -930,6 +933,7 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -1101,6 +1105,7 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -1467,6 +1472,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY= +gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY= google.golang.org/api v0.0.0-20160322025152-9bf6e6e569ff/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= diff --git a/internal/bootstrap/bootstrap_plain_git.go b/internal/bootstrap/bootstrap_plain_git.go index a5979476..ea4895fd 100644 --- a/internal/bootstrap/bootstrap_plain_git.go +++ b/internal/bootstrap/bootstrap_plain_git.go @@ -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 } diff --git a/internal/bootstrap/options.go b/internal/bootstrap/options.go index 6d79055c..2d1f69b7 100644 --- a/internal/bootstrap/options.go +++ b/internal/bootstrap/options.go @@ -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) { diff --git a/internal/build/build.go b/internal/build/build.go index a6fbf696..3eb0844c 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -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 } diff --git a/internal/utils/apply.go b/internal/utils/apply.go index 087c0e13..95badc1f 100644 --- a/internal/utils/apply.go +++ b/internal/utils/apply.go @@ -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 } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index cc24354d..c41b2f4e 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -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,