Skip to content

Commit

Permalink
Issue #2316 - support deprecated 'helm.repositories' config (#2405)
Browse files Browse the repository at this point in the history
* Issue #2316 - support deprecated 'helm.repositories' config

* Address reviewer notes
  • Loading branch information
Alexander Matyushentsev authored Oct 3, 2019
1 parent e9b2a62 commit 16e645b
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 102 deletions.
4 changes: 2 additions & 2 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type appStateManager struct {
}

func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, source v1alpha1.ApplicationSource, appLabelKey, revision string, noCache bool) ([]*unstructured.Unstructured, []*unstructured.Unstructured, *apiclient.ManifestResponse, error) {
repos, err := m.db.ListRepositories(context.Background())
helmRepos, err := m.db.ListHelmRepositories(context.Background())
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, source v1alpha1
}
manifestInfo, err := repoClient.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
Repo: repo,
Repos: repos,
Repos: helmRepos,
Revision: revision,
NoCache: noCache,
AppLabelKey: appLabelKey,
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,17 @@ func getCAPath(repoURL string) string {

type Repositories []*Repository

func (r Repositories) Filter(predicate func(r *Repository) bool) Repositories {
var res Repositories
for i := range r {
repo := r[i]
if predicate(repo) {
res = append(res, repo)
}
}
return res
}

// RepositoryList is a collection of Repositories.
type RepositoryList struct {
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Expand Down
4 changes: 1 addition & 3 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ func (s *Service) GenerateManifest(c context.Context, q *apiclient.ManifestReque
func getHelmRepos(repositories []*v1alpha1.Repository) []helm.HelmRepository {
repos := make([]helm.HelmRepository, 0)
for _, repo := range repositories {
if repo.Type == "helm" {
repos = append(repos, helm.HelmRepository{Name: repo.Name, Repo: repo.Repo, Creds: repo.GetHelmCreds()})
}
repos = append(repos, helm.HelmRepository{Name: repo.Name, Repo: repo.Repo, Creds: repo.GetHelmCreds()})
}
return repos
}
Expand Down
4 changes: 2 additions & 2 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan
if err != nil {
return nil, err
}
repos, err := s.db.ListRepositories(ctx)
helmRepos, err := s.db.ListHelmRepositories(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan
AppLabelValue: a.Name,
Namespace: a.Spec.Destination.Namespace,
ApplicationSource: &a.Spec.Source,
Repos: repos,
Repos: helmRepos,
Plugins: plugins,
KustomizeOptions: &kustomizeOptions,
KubeVersion: cluster.ServerVersion,
Expand Down
4 changes: 2 additions & 2 deletions server/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *Server) GetAppDetails(ctx context.Context, q *repositorypkg.RepoAppDeta
return nil, err
}
defer util.Close(conn)
repos, err := s.db.ListRepositories(ctx)
helmRepos, err := s.db.ListHelmRepositories(ctx)
if err != nil {
return nil, err
}
Expand All @@ -158,7 +158,7 @@ func (s *Server) GetAppDetails(ctx context.Context, q *repositorypkg.RepoAppDeta
return repoClient.GetAppDetails(ctx, &apiclient.RepoServerAppDetailsQuery{
Repo: repo,
Source: q.Source,
Repos: repos,
Repos: helmRepos,
KustomizeOptions: &appsv1.KustomizeOptions{
BuildOptions: buildOptions,
},
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixture/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (c *Context) HTTPSRepoURLWithClientCertAdded() *Context {
return c
}

func (c *Context) HelmRepoAdded() *Context {
repos.AddHelmRepo()
func (c *Context) HelmRepoAdded(name string) *Context {
repos.AddHelmRepo(name)
return c
}

Expand Down
12 changes: 12 additions & 0 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ func SetRepos(repos ...settings.RepoCredentials) {
})
}

func SetHelmRepos(repos ...settings.HelmRepoCredentials) {
updateSettingConfigMap(func(cm *corev1.ConfigMap) error {
yamlBytes, err := yaml.Marshal(repos)
if err != nil {
return err
}
cm.Data["helm.repositories"] = string(yamlBytes)
return nil
})
}

func SetRepoCredentials(repos ...settings.RepoCredentials) {
updateSettingConfigMap(func(cm *corev1.ConfigMap) error {
yamlBytes, err := yaml.Marshal(repos)
Expand Down Expand Up @@ -333,6 +344,7 @@ func EnsureCleanState(t *testing.T) {
SetConfigManagementPlugins()
SetRepoCredentials()
SetRepos()
SetHelmRepos()
SetResourceFilter(settings.ResourcesFilter{})
SetProjectSpec("default", v1alpha1.AppProjectSpec{
OrphanedResources: nil,
Expand Down
31 changes: 17 additions & 14 deletions test/e2e/fixture/repos/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import (
"github.com/argoproj/argo-cd/test/e2e/fixture"
)

var (
CertPath = mustToAbsPath("../fixture/certs/argocd-test-client.crt")
CertKeyPath = mustToAbsPath("../fixture/certs/argocd-test-client.key")
)

func mustToAbsPath(relativePath string) string {
res, err := filepath.Abs(relativePath)
errors.CheckError(err)
return res
}

// sets the current repo as the default SSH test repo
func AddSSHRepo(insecure bool) {
keyPath, err := filepath.Abs("../fixture/testrepos/id_rsa")
Expand All @@ -31,40 +42,32 @@ func AddHTTPSRepo(insecure bool) {

// sets a HTTPS repo using TLS client certificate authentication
func AddHTTPSRepoClientCert(insecure bool) {
certPath, err := filepath.Abs("../fixture/certs/argocd-test-client.crt")
errors.CheckError(err)
keyPath, err := filepath.Abs("../fixture/certs/argocd-test-client.key")
errors.CheckError(err)
args := []string{
"repo",
"add",
fixture.RepoURL(fixture.RepoURLTypeHTTPSClientCert),
"--username", fixture.GitUsername,
"--password", fixture.GitPassword,
"--tls-client-cert-path", certPath,
"--tls-client-cert-key-path", keyPath,
"--tls-client-cert-path", CertPath,
"--tls-client-cert-key-path", CertKeyPath,
}
if insecure {
args = append(args, "--insecure-skip-server-verification")
}
errors.FailOnErr(fixture.RunCli(args...))
}

func AddHelmRepo() {
certPath, err := filepath.Abs("../fixture/certs/argocd-test-client.crt")
errors.CheckError(err)
keyPath, err := filepath.Abs("../fixture/certs/argocd-test-client.key")
errors.CheckError(err)

func AddHelmRepo(name string) {
args := []string{
"repo",
"add",
fixture.RepoURL(fixture.RepoURLTypeHelm),
"--username", fixture.GitUsername,
"--password", fixture.GitPassword,
"--tls-client-cert-path", certPath,
"--tls-client-cert-key-path", keyPath,
"--tls-client-cert-path", CertPath,
"--tls-client-cert-key-path", CertKeyPath,
"--type", "helm",
"--name", name,
}
errors.FailOnErr(fixture.RunCli(args...))
}
51 changes: 50 additions & 1 deletion test/e2e/helm_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package e2e

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/argoproj/argo-cd/errors"
. "github.com/argoproj/argo-cd/errors"
. "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/test/e2e/fixture"
. "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/settings"
)

func TestHelmHooksAreCreated(t *testing.T) {
Expand Down Expand Up @@ -98,7 +104,7 @@ func TestDeclarativeHelmInvalidValuesFile(t *testing.T) {
func TestHelmRepo(t *testing.T) {
Given(t).
CustomCACertAdded().
HelmRepoAdded().
HelmRepoAdded("").
RepoURLType(RepoURLTypeHelm).
Chart("helm").
Revision("1.0.0").
Expand Down Expand Up @@ -178,3 +184,46 @@ func TestKubeVersion(t *testing.T) {
assert.Equal(t, GetVersions().ServerVersion.Format("v%s.%s.0"), kubeVersion)
})
}

func TestHelmWithDependencies(t *testing.T) {
testHelmWithDependencies(t, false)
}

func TestHelmWithDependenciesLegacyRepo(t *testing.T) {
testHelmWithDependencies(t, true)
}

func testHelmWithDependencies(t *testing.T, legacyRepo bool) {
ctx := Given(t).CustomCACertAdded()
if legacyRepo {
ctx.And(func() {
errors.FailOnErr(fixture.Run("", "kubectl", "create", "secret", "generic", "helm-repo",
"-n", fixture.ArgoCDNamespace,
fmt.Sprintf("--from-file=certSecret=%s", repos.CertPath),
fmt.Sprintf("--from-file=keySecret=%s", repos.CertKeyPath),
fmt.Sprintf("--from-literal=username=%s", GitUsername),
fmt.Sprintf("--from-literal=password=%s", GitPassword),
))
errors.FailOnErr(fixture.KubeClientset.CoreV1().Secrets(fixture.ArgoCDNamespace).Patch(
"helm-repo", types.MergePatchType, []byte(`{"metadata": { "labels": {"e2e.argoproj.io": "true"} }}`)))

fixture.SetHelmRepos(settings.HelmRepoCredentials{
URL: RepoURL(RepoURLTypeHelm),
Name: "custom-repo",
KeySecret: &v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "helm-repo"}, Key: "keySecret"},
CertSecret: &v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "helm-repo"}, Key: "certSecret"},
UsernameSecret: &v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "helm-repo"}, Key: "username"},
PasswordSecret: &v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "helm-repo"}, Key: "password"},
})
})
} else {
ctx = ctx.HelmRepoAdded("custom-repo")
}

ctx.Path("helm-with-dependencies").
When().
Create().
Sync().
Then().
Expect(SyncStatusIs(SyncStatusCodeSynced))
}
Loading

0 comments on commit 16e645b

Please sign in to comment.