From 17df7a46e28b10b2b7006e6b4e23ceb15fbee690 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Mon, 17 Aug 2020 19:58:17 +0300 Subject: [PATCH] Make export work offline --- cmd/tk/create_kustomization.go | 16 ++++++++-------- cmd/tk/create_source_git.go | 16 ++++++++-------- cmd/tk/create_source_helm.go | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/tk/create_kustomization.go b/cmd/tk/create_kustomization.go index e358f533..92b8057c 100644 --- a/cmd/tk/create_kustomization.go +++ b/cmd/tk/create_kustomization.go @@ -113,14 +113,6 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("path must begin with ./") } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - kubeClient, err := utils.kubeClient(kubeconfig) - if err != nil { - return err - } - if !export { logger.Generatef("generating kustomization") } @@ -190,6 +182,14 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { return exportKs(kustomization) } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.kubeClient(kubeconfig) + if err != nil { + return err + } + logger.Actionf("applying kustomization") if err := upsertKustomization(ctx, kubeClient, kustomization); err != nil { return err diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go index 9fa7d6f2..31f3635c 100644 --- a/cmd/tk/create_source_git.go +++ b/cmd/tk/create_source_git.go @@ -129,14 +129,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("git URL parse failed: %w", err) } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - kubeClient, err := utils.kubeClient(kubeconfig) - if err != nil { - return err - } - gitRepository := sourcev1.GitRepository{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -163,6 +155,14 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { return exportGit(gitRepository) } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.kubeClient(kubeconfig) + if err != nil { + return err + } + withAuth := false // TODO(hidde): move all auth prep to separate func? if u.Scheme == "ssh" { diff --git a/cmd/tk/create_source_helm.go b/cmd/tk/create_source_helm.go index 82ec91f1..2037989c 100644 --- a/cmd/tk/create_source_helm.go +++ b/cmd/tk/create_source_helm.go @@ -101,14 +101,6 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("url parse failed: %w", err) } - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - kubeClient, err := utils.kubeClient(kubeconfig) - if err != nil { - return err - } - helmRepository := sourcev1.HelmRepository{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -126,6 +118,14 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { return exportHelmRepository(helmRepository) } + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + kubeClient, err := utils.kubeClient(kubeconfig) + if err != nil { + return err + } + logger.Generatef("generating source") secret := corev1.Secret{