mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-24 09:50:08 +00:00
fix: the 'repo add' command incorrectly requires upsert flag (#2926)
This commit is contained in:
parent
d4c0ee80ee
commit
3911cd48ca
3 changed files with 31 additions and 12 deletions
|
|
@ -239,6 +239,7 @@ func (s *Server) CreateRepository(ctx context.Context, q *repositorypkg.RepoCrea
|
|||
return nil, status.Errorf(codes.Internal, "unable to check existing repository details: %v", getErr)
|
||||
}
|
||||
|
||||
existing.Type = util.FirstNonEmpty(existing.Type, "git")
|
||||
// repository ConnectionState may differ, so make consistent before testing
|
||||
existing.ConnectionState = r.ConnectionState
|
||||
if reflect.DeepEqual(existing, r) {
|
||||
|
|
|
|||
|
|
@ -195,13 +195,6 @@ func CreateSecret(username, password string) string {
|
|||
return secretName
|
||||
}
|
||||
|
||||
func Settings(consumer func(s *settings.ArgoCDSettings)) {
|
||||
s, err := settingsManager.GetSettings()
|
||||
CheckError(err)
|
||||
consumer(s)
|
||||
CheckError(settingsManager.SaveSettings(s))
|
||||
}
|
||||
|
||||
func updateSettingConfigMap(updater func(cm *corev1.ConfigMap) error) {
|
||||
cm, err := KubeClientset.CoreV1().ConfigMaps(ArgoCDNamespace).Get(common.ArgoCDConfigMapName, v1.GetOptions{})
|
||||
errors.CheckError(err)
|
||||
|
|
@ -266,6 +259,17 @@ func SetHelmRepos(repos ...settings.HelmRepoCredentials) {
|
|||
})
|
||||
}
|
||||
|
||||
func SetRepos(repos ...settings.RepositoryCredentials) {
|
||||
updateSettingConfigMap(func(cm *corev1.ConfigMap) error {
|
||||
yamlBytes, err := yaml.Marshal(repos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cm.Data["repositories"] = string(yamlBytes)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func SetProjectSpec(project string, spec v1alpha1.AppProjectSpec) {
|
||||
proj, err := AppClientset.ArgoprojV1alpha1().AppProjects(ArgoCDNamespace).Get(project, v1.GetOptions{})
|
||||
errors.CheckError(err)
|
||||
|
|
|
|||
|
|
@ -4,20 +4,19 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/test/e2e/fixture/repos"
|
||||
|
||||
"github.com/argoproj/argo-cd/test/e2e/fixture/app"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
repositorypkg "github.com/argoproj/argo-cd/pkg/apiclient/repository"
|
||||
"github.com/argoproj/argo-cd/test/e2e/fixture"
|
||||
"github.com/argoproj/argo-cd/test/e2e/fixture/app"
|
||||
"github.com/argoproj/argo-cd/test/e2e/fixture/repos"
|
||||
"github.com/argoproj/argo-cd/util"
|
||||
"github.com/argoproj/argo-cd/util/settings"
|
||||
)
|
||||
|
||||
func TestAddRemovePublicRepo(t *testing.T) {
|
||||
app.Given(t).And(func() {
|
||||
repoUrl := "https://github.com/argoproj/argocd-example-apps.git"
|
||||
repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile)
|
||||
_, err := fixture.RunCli("repo", "add", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -53,6 +52,21 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestUpsertExistingRepo(t *testing.T) {
|
||||
app.Given(t).And(func() {
|
||||
fixture.SetRepos(settings.RepositoryCredentials{URL: fixture.RepoURL(fixture.RepoURLTypeFile)})
|
||||
repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile)
|
||||
_, err := fixture.RunCli("repo", "add", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("repo", "add", repoUrl, "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = fixture.RunCli("repo", "add", repoUrl, "--upsert", "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddRemoveHelmRepo(t *testing.T) {
|
||||
app.Given(t).CustomCACertAdded().And(func() {
|
||||
_, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm),
|
||||
|
|
|
|||
Loading…
Reference in a new issue