Skip to content

Commit

Permalink
fix: adding tests for helm OCI registry (argoproj#5978)
Browse files Browse the repository at this point in the history
* initial draft of adding tests for OCI

Signed-off-by: May Zhang <[email protected]>

* fix: initial draft of adding tests for OCI

Signed-off-by: May Zhang <[email protected]>

* bring up registry for tests

Signed-off-by: May Zhang <[email protected]>

* bring up registry for tests

Signed-off-by: May Zhang <[email protected]>

* bring up registry for tests

Signed-off-by: May Zhang <[email protected]>

* fix: just to test if PR is working

Signed-off-by: May Zhang <[email protected]>

* adding additional helm oci dependencies tests

Signed-off-by: May Zhang <[email protected]>
  • Loading branch information
mayzhang2000 authored Apr 12, 2021
1 parent 9da9514 commit 12cabdf
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ define run-in-test-server
-w ${DOCKER_WORKDIR} \
-p ${ARGOCD_E2E_APISERVER_PORT}:8080 \
-p 4000:4000 \
-p 5000:5000 \
$(TEST_TOOLS_PREFIX)$(TEST_TOOLS_IMAGE):$(TEST_TOOLS_TAG) \
bash -c "$(1)"
endef
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ redis: bash -c "if [ $ARGOCD_REDIS_LOCAL == 'true' ]; then redis-server --save '
repo-server: sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-repo-server go run ./cmd/main.go --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379}"
ui: sh -c 'cd ui && ${ARGOCD_E2E_YARN_CMD:-yarn} start'
git-server: test/fixture/testrepos/start-git.sh
helm-registry: test/fixture/testrepos/start-helm-registry.sh
dev-mounter: [[ "$ARGOCD_E2E_TEST" != "true" ]] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source}
6 changes: 6 additions & 0 deletions test/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM node:12.18.4 as node

FROM golang:1.16.0 as golang

FROM registry:2.7.1 as registry

FROM ubuntu:20.10

ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -63,6 +65,10 @@ COPY ./test/fixture/testrepos/ssh_host_*_key* /etc/ssh/
# Copy redis binaries to the image
COPY --from=redis /usr/local/bin/* /usr/local/bin/

# Copy registry binaries to the image
COPY --from=registry /bin/registry /usr/local/bin/
COPY --from=registry /etc/docker/registry/config.yml /etc/docker/registry/config.yml

# Copy node binaries
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /usr/local/bin/node /usr/local/bin
Expand Down
1 change: 1 addition & 0 deletions test/container/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ui: sh -c "test $ARGOCD_IN_CI = true && exit 0; cd ui && ARGOCD_E2E_YARN_HOST=0.
sshd: sudo sh -c "test $ARGOCD_E2E_TEST = true && /usr/sbin/sshd -p 2222 -D -e"
fcgiwrap: sudo sh -c "test $ARGOCD_E2E_TEST = true && (fcgiwrap -s unix:/var/run/fcgiwrap.socket & sleep 1 && chmod 777 /var/run/fcgiwrap.socket && wait)"
nginx: sudo sh -c "test $ARGOCD_E2E_TEST = true && nginx -g 'daemon off;' -c $(pwd)/test/fixture/testrepos/nginx.conf"
helm-registry: sudo sh -c "registry serve /etc/docker/registry/config.yml"
10 changes: 10 additions & 0 deletions test/e2e/fixture/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ func (c *Context) HelmRepoAdded(name string) *Context {
return c
}

func (c *Context) HelmOCIRepoAdded(name string) *Context {
repos.AddHelmOCIRepo(name)
return c
}

func (c *Context) PushChartToOCIRegistry(chartPathName, chartName, chartVersion string) *Context {
repos.PushChartToOCIRegistry(chartPathName, chartName, chartVersion)
return c
}

func (c *Context) HTTPSCredentialsUserPassAdded() *Context {
repos.AddHTTPSCredentialsUserPass()
return c
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ const (
RepoURLTypeSSHSubmodule = "ssh-sub"
RepoURLTypeSSHSubmoduleParent = "ssh-par"
RepoURLTypeHelm = "helm"
RepoURLTypeHelmOCI = "helm-oci"
GitUsername = "admin"
GitPassword = "password"
GpgGoodKeyID = "D56C4FCA57A46444"
HelmOCIRegistryURL = "localhost:5000/myrepo"
)

// TestNamespace returns the namespace where Argo CD E2E test instance will be
Expand Down Expand Up @@ -243,6 +245,8 @@ func RepoURL(urlType RepoURLType) string {
// Default - file based Git repository
case RepoURLTypeHelm:
return GetEnvWithDefault(EnvRepoURLTypeHelm, "https://localhost:9444/argo-e2e/testdata.git/helm-repo/local")
case RepoURLTypeHelmOCI:
return HelmOCIRegistryURL
default:
return GetEnvWithDefault(EnvRepoURLDefault, fmt.Sprintf("file://%s", repoDirectory()))
}
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/fixture/repos/repos.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package repos

import (
"fmt"
"os"
"path/filepath"

"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
Expand Down Expand Up @@ -77,6 +79,18 @@ func AddHelmRepo(name string) {
errors.FailOnErr(fixture.RunCli(args...))
}

func AddHelmOCIRepo(name string) {
args := []string{
"repo",
"add",
fixture.HelmOCIRegistryURL,
"--type", "helm",
"--name", name,
"--enable-oci",
}
errors.FailOnErr(fixture.RunCli(args...))
}

// AddHTTPSRepoCredentialsUserPass adds E2E username/password credentials for HTTPS repos to context
func AddHTTPSCredentialsUserPass() {
var repoURLType fixture.RepoURLType = fixture.RepoURLTypeHTTPS
Expand Down Expand Up @@ -110,3 +124,14 @@ func AddSSHCredentials() {
args := []string{"repocreds", "add", fixture.RepoBaseURL(repoURLType), "--ssh-private-key-path", keyPath}
errors.FailOnErr(fixture.RunCli(args...))
}

// PushChartToOCIRegistry adds a helm chart to helm OCI registry
func PushChartToOCIRegistry(chartPathName, chartName, chartVersion string) {
chartAbsPath, err := filepath.Abs(fmt.Sprintf("./testdata/%s", chartPathName))
errors.CheckError(err)

_ = os.Setenv("HELM_EXPERIMENTAL_OCI", "1")
errors.FailOnErr(fixture.Run("", "helm", "chart", "save", chartAbsPath, fmt.Sprintf("%s/%s:%s", fixture.HelmOCIRegistryURL, chartName, chartVersion)))
errors.FailOnErr(fixture.Run("", "helm", "chart", "push", fmt.Sprintf("%s/%s:%s", fixture.HelmOCIRegistryURL, chartName, chartVersion)))

}
53 changes: 53 additions & 0 deletions test/e2e/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,56 @@ func TestHelmRepoDiffLocal(t *testing.T) {
assert.Empty(t, diffOutput)
})
}

func TestHelmOCIRegistry(t *testing.T) {
Given(t).
PushChartToOCIRegistry("helm-values", "helm-values", "1.0.0").
HelmOCIRepoAdded("myrepo").
RepoURLType(RepoURLTypeHelmOCI).
Chart("helm-values").
Revision("1.0.0").
When().
Create().
Then().
When().
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(SyncStatusIs(SyncStatusCodeSynced))
}

func TestGitWithHelmOCIRegistryDependencies(t *testing.T) {
Given(t).
PushChartToOCIRegistry("helm-values", "helm-values", "1.0.0").
HelmOCIRepoAdded("myrepo").
Path("helm-oci-with-dependencies").
When().
Create().
Then().
When().
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(SyncStatusIs(SyncStatusCodeSynced))
}

func TestHelmOCIRegistryWithDependencies(t *testing.T) {
Given(t).
PushChartToOCIRegistry("helm-values", "helm-values", "1.0.0").
PushChartToOCIRegistry("helm-oci-with-dependencies", "helm-oci-with-dependencies", "1.0.0").
HelmOCIRepoAdded("myrepo").
RepoURLType(RepoURLTypeHelmOCI).
Chart("helm-oci-with-dependencies").
Revision("1.0.0").
When().
Create().
Then().
When().
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(SyncStatusIs(SyncStatusCodeSynced))
}
7 changes: 7 additions & 0 deletions test/e2e/testdata/helm-oci-with-dependencies/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: helm-oci-with-dependencies
version: 1.0.0
dependencies:
- name: helm-values
repository: "oci://localhost:5000/myrepo"
version: 1.0.0
3 changes: 3 additions & 0 deletions test/fixture/testrepos/start-helm-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
export HELM_EXPERIMENTAL_OCI=1
docker run -p 5000:5000 --restart=always --name registry registry
14 changes: 8 additions & 6 deletions util/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ func (h *helm) DependencyBuild() error {
repo := h.repos[i]
if repo.EnableOci {
h.cmd.IsHelmOci = true
_, err := h.cmd.Login(repo.Repo, repo.Creds)
if repo.Creds.Username != "" && repo.Creds.Password != "" {
_, err := h.cmd.Login(repo.Repo, repo.Creds)

defer func() {
_, _ = h.cmd.Logout(repo.Repo, repo.Creds)
}()
defer func() {
_, _ = h.cmd.Logout(repo.Repo, repo.Creds)
}()

if err != nil {
return err
if err != nil {
return err
}
}
} else {
_, err := h.cmd.RepoAdd(repo.Name, repo.Repo, repo.Creds)
Expand Down

0 comments on commit 12cabdf

Please sign in to comment.