mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-08 00:37:27 +00:00
Merge pull request #721 from fluxcd/git-impl-fixes
This commit is contained in:
commit
388642d9dd
6 changed files with 118 additions and 20 deletions
|
|
@ -164,14 +164,13 @@ func applyInstallManifests(ctx context.Context, manifestPath string, components
|
|||
|
||||
func generateSyncManifests(url, branch, name, namespace, targetPath, tmpDir string, interval time.Duration) (string, error) {
|
||||
opts := sync.Options{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
URL: url,
|
||||
Branch: branch,
|
||||
Interval: interval,
|
||||
TargetPath: targetPath,
|
||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||
GitImplementation: sync.MakeDefaultOptions().GitImplementation,
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
URL: url,
|
||||
Branch: branch,
|
||||
Interval: interval,
|
||||
TargetPath: targetPath,
|
||||
ManifestFile: sync.MakeDefaultOptions().ManifestFile,
|
||||
}
|
||||
|
||||
manifest, err := sync.Generate(opts)
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ var (
|
|||
sourceGitRSABits flags.RSAKeyBits = 2048
|
||||
sourceGitECDSACurve = flags.ECDSACurve{Curve: elliptic.P384()}
|
||||
sourceGitSecretRef string
|
||||
sourceGitImplementation string
|
||||
sourceGitImplementation flags.GitImplementation
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -110,7 +110,7 @@ func init() {
|
|||
createSourceGitCmd.Flags().Var(&sourceGitRSABits, "ssh-rsa-bits", sourceGitRSABits.Description())
|
||||
createSourceGitCmd.Flags().Var(&sourceGitECDSACurve, "ssh-ecdsa-curve", sourceGitECDSACurve.Description())
|
||||
createSourceGitCmd.Flags().StringVarP(&sourceGitSecretRef, "secret-ref", "", "", "the name of an existing secret containing SSH or basic credentials")
|
||||
createSourceGitCmd.Flags().StringVar(&sourceGitImplementation, "git-implementation", "", "the git implementation to use, can be 'go-git' or 'libgit2'")
|
||||
createSourceGitCmd.Flags().Var(&sourceGitImplementation, "git-implementation", sourceGitImplementation.Description())
|
||||
|
||||
createSourceCmd.AddCommand(createSourceGitCmd)
|
||||
}
|
||||
|
|
@ -141,10 +141,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !utils.ContainsItemString([]string{sourcev1.GoGitImplementation, sourcev1.LibGit2Implementation, ""}, sourceGitImplementation) {
|
||||
return fmt.Errorf("Invalid git implementation %q", sourceGitImplementation)
|
||||
}
|
||||
|
||||
gitRepository := sourcev1.GitRepository{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
|
|
@ -156,11 +152,14 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||
Interval: metav1.Duration{
|
||||
Duration: interval,
|
||||
},
|
||||
Reference: &sourcev1.GitRepositoryRef{},
|
||||
GitImplementation: sourceGitImplementation,
|
||||
Reference: &sourcev1.GitRepositoryRef{},
|
||||
},
|
||||
}
|
||||
|
||||
if sourceGitImplementation != "" {
|
||||
gitRepository.Spec.GitImplementation = sourceGitImplementation.String()
|
||||
}
|
||||
|
||||
if sourceGitSemver != "" {
|
||||
gitRepository.Spec.Reference.SemVer = sourceGitSemver
|
||||
} else if sourceGitTag != "" {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ flux create source git [name] [flags]
|
|||
|
||||
```
|
||||
--branch string git branch (default "master")
|
||||
--git-implementation string the git implementation to use, can be 'go-git' or 'libgit2'
|
||||
--git-implementation gitImplementation the Git implementation to use, available options are: (go-git, libgit2)
|
||||
-h, --help help for git
|
||||
-p, --password string basic authentication password
|
||||
--secret-ref string the name of an existing secret containing SSH or basic credentials
|
||||
|
|
|
|||
55
internal/flags/git_implementation.go
Normal file
55
internal/flags/git_implementation.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
Copyright 2021 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
)
|
||||
|
||||
var supportedGitImplementations = []string{sourcev1.GoGitImplementation, sourcev1.LibGit2Implementation}
|
||||
|
||||
type GitImplementation string
|
||||
|
||||
func (i *GitImplementation) String() string {
|
||||
return string(*i)
|
||||
}
|
||||
|
||||
func (i *GitImplementation) Set(str string) error {
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
if !utils.ContainsItemString(supportedGitImplementations, str) {
|
||||
return fmt.Errorf("unsupported Git implementation '%s', must be one of: %s",
|
||||
str, strings.Join(supportedGitImplementations, ", "))
|
||||
|
||||
}
|
||||
*i = GitImplementation(str)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *GitImplementation) Type() string {
|
||||
return "gitImplementation"
|
||||
}
|
||||
|
||||
func (i *GitImplementation) Description() string {
|
||||
return fmt.Sprintf("the Git implementation to use, available options are: (%s)", strings.Join(supportedGitImplementations, ", "))
|
||||
}
|
||||
47
internal/flags/git_implementation_test.go
Normal file
47
internal/flags/git_implementation_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
Copyright 2021 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package flags
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
)
|
||||
|
||||
func TestGitImplementation_Set(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
str string
|
||||
expect string
|
||||
expectErr bool
|
||||
}{
|
||||
{"supported", sourcev1.GoGitImplementation, sourcev1.GoGitImplementation, false},
|
||||
{"unsupported", "unsupported", "", true},
|
||||
{"empty", "", "", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var i GitImplementation
|
||||
if err := i.Set(tt.str); (err != nil) != tt.expectErr {
|
||||
t.Errorf("Set() error = %v, expectErr %v", err, tt.expectErr)
|
||||
}
|
||||
if str := i.String(); str != tt.expect {
|
||||
t.Errorf("Set() = %v, expect %v", str, tt.expect)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +18,6 @@ package sync
|
|||
|
||||
import (
|
||||
"time"
|
||||
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
|
|
@ -42,6 +40,6 @@ func MakeDefaultOptions() Options {
|
|||
Branch: "main",
|
||||
ManifestFile: "gotk-sync.yaml",
|
||||
TargetPath: "",
|
||||
GitImplementation: sourcev1.GoGitImplementation,
|
||||
GitImplementation: "",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue