From 61be0775afe718efbd70f970eb909599548c16ea Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 1 Nov 2021 15:32:22 +0200 Subject: [PATCH] Add fetch timeout arg to create source commands Signed-off-by: Stefan Prodan --- cmd/flux/create_source.go | 10 ++++++++++ cmd/flux/create_source_bucket.go | 5 +++++ cmd/flux/create_source_git.go | 4 ++++ cmd/flux/create_source_helm.go | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/cmd/flux/create_source.go b/cmd/flux/create_source.go index 5b51209f..9e1e93f5 100644 --- a/cmd/flux/create_source.go +++ b/cmd/flux/create_source.go @@ -17,6 +17,8 @@ limitations under the License. package main import ( + "time" + "github.com/spf13/cobra" ) @@ -26,6 +28,14 @@ var createSourceCmd = &cobra.Command{ Long: "The create source sub-commands generate sources.", } +type createSourceFlags struct { + fetchTimeout time.Duration +} + +var createSourceArgs createSourceFlags + func init() { + createSourceCmd.PersistentFlags().DurationVar(&createSourceArgs.fetchTimeout, "fetch-timeout", createSourceArgs.fetchTimeout, + "set a timeout for fetch operations performed by source-controller (e.g. 'git clone' or 'helm repo update')") createCmd.AddCommand(createSourceCmd) } diff --git a/cmd/flux/create_source_bucket.go b/cmd/flux/create_source_bucket.go index 035f670e..4ec6aaea 100644 --- a/cmd/flux/create_source_bucket.go +++ b/cmd/flux/create_source_bucket.go @@ -134,6 +134,11 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error { }, }, } + + if createSourceArgs.fetchTimeout > 0 { + bucket.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout} + } + if sourceBucketArgs.secretRef != "" { bucket.Spec.SecretRef = &meta.LocalObjectReference{ Name: sourceBucketArgs.secretRef, diff --git a/cmd/flux/create_source_git.go b/cmd/flux/create_source_git.go index 4e62dd34..3b987f71 100644 --- a/cmd/flux/create_source_git.go +++ b/cmd/flux/create_source_git.go @@ -206,6 +206,10 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { }, } + if createSourceArgs.fetchTimeout > 0 { + gitRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout} + } + if sourceGitArgs.gitImplementation != "" { gitRepository.Spec.GitImplementation = sourceGitArgs.gitImplementation.String() } diff --git a/cmd/flux/create_source_helm.go b/cmd/flux/create_source_helm.go index b2d0b01f..a1edd409 100644 --- a/cmd/flux/create_source_helm.go +++ b/cmd/flux/create_source_helm.go @@ -129,6 +129,10 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { }, } + if createSourceArgs.fetchTimeout > 0 { + helmRepository.Spec.Timeout = &metav1.Duration{Duration: createSourceArgs.fetchTimeout} + } + if sourceHelmArgs.secretRef != "" { helmRepository.Spec.SecretRef = &meta.LocalObjectReference{ Name: sourceHelmArgs.secretRef,