From 18c3f793192cb73c4a936ba72dabdebf6ddb4ed0 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 1 Apr 2021 09:45:55 +0300 Subject: [PATCH] Add recurse submodules arg to create source git cmd Signed-off-by: Stefan Prodan --- .github/workflows/e2e.yaml | 3 ++- cmd/flux/create_source_git.go | 9 ++++++++- docs/cmd/flux_create_source_git.md | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index ef4bc8bf..d6c23218 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -188,7 +188,8 @@ jobs: run: | /tmp/flux create source git flux-system \ --url=https://github.com/fluxcd/flux2-kustomize-helm-example \ - --branch=main + --branch=main \ + --recurse-submodules /tmp/flux create kustomization flux-system \ --source=flux-system \ --path=./clusters/staging diff --git a/cmd/flux/create_source_git.go b/cmd/flux/create_source_git.go index 8f00636c..eaee699a 100644 --- a/cmd/flux/create_source_git.go +++ b/cmd/flux/create_source_git.go @@ -56,6 +56,7 @@ type sourceGitFlags struct { gitImplementation flags.GitImplementation caFile string privateKeyFile string + recurseSubmodules bool } var createSourceGitCmd = &cobra.Command{ @@ -124,6 +125,7 @@ func init() { createSourceGitCmd.Flags().Var(&sourceGitArgs.gitImplementation, "git-implementation", sourceGitArgs.gitImplementation.Description()) createSourceGitCmd.Flags().StringVar(&sourceGitArgs.caFile, "ca-file", "", "path to TLS CA file used for validating self-signed certificates") createSourceGitCmd.Flags().StringVar(&sourceGitArgs.privateKeyFile, "private-key-file", "", "path to a passwordless private key file used for authenticating to the Git SSH server") + createSourceGitCmd.Flags().BoolVar(&sourceGitArgs.recurseSubmodules, "recurse-submodules", false, "when enabled, after the clone is created, initializes all Git submodules within") createSourceCmd.AddCommand(createSourceGitCmd) } @@ -158,6 +160,10 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("specifing a CA file is not supported for Git over SSH") } + if sourceGitArgs.recurseSubmodules && sourceGitArgs.gitImplementation == sourcev1.LibGit2Implementation { + return fmt.Errorf("recurse submodules requires --git-implementation=%s", sourcev1.GoGitImplementation) + } + tmpDir, err := ioutil.TempDir("", name) if err != nil { return err @@ -180,7 +186,8 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error { Interval: metav1.Duration{ Duration: createArgs.interval, }, - Reference: &sourcev1.GitRepositoryRef{}, + RecurseSubmodules: sourceGitArgs.recurseSubmodules, + Reference: &sourcev1.GitRepositoryRef{}, }, } diff --git a/docs/cmd/flux_create_source_git.md b/docs/cmd/flux_create_source_git.md index 14cddd5a..faab2f92 100644 --- a/docs/cmd/flux_create_source_git.md +++ b/docs/cmd/flux_create_source_git.md @@ -70,6 +70,7 @@ flux create source git [name] [flags] -h, --help help for git -p, --password string basic authentication password --private-key-file string path to a passwordless private key file used for authenticating to the Git SSH server + --recurse-submodules when enabled, after the clone is created, initializes all Git submodules within --secret-ref string the name of an existing secret containing SSH or basic credentials --ssh-ecdsa-curve ecdsaCurve SSH ECDSA public key curve (p256, p384, p521) (default p384) --ssh-key-algorithm publicKeyAlgorithm SSH public key algorithm (rsa, ecdsa, ed25519) (default rsa)