-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements DependencyUpdate for helm charts
A new flag `disableDependencyUpdate` is added to the `fleet.yaml` file in order to disable the feature, which is active by default. A new package `helmupdater` is added to implement the dependencies update. The implementation is based on helm's when ussing the `--dependency-update` flag in the install command. Dependencies are applied to the bundle (upstream) to they're resolved already when applying downstream. Refers to: #1672 Signed-off-by: Xavi Garcia <[email protected]>
- Loading branch information
Showing
46 changed files
with
867 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
kind: GitRepo | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
metadata: | ||
name: {{.Name}} | ||
spec: | ||
repo: {{.Repo}} | ||
branch: {{.Branch}} | ||
helmSecretName: "helm-secret" | ||
targetNamespace: {{.TargetNamespace}} | ||
paths: | ||
- examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v2 | ||
appVersion: 1.16.0 | ||
description: A chart for testing dependencies | ||
name: deps-chart | ||
type: application | ||
version: 1.0.0 | ||
dependencies: | ||
- name: sleeper-chart | ||
version: "0.1.0" | ||
repository: {{.HelmRepoUrl}} |
7 changes: 7 additions & 0 deletions
7
e2e/assets/deps-charts/no-fleet-yaml/templates/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test-simple-deps-chart | ||
data: | ||
test: "valuedeps" | ||
name: {{ .Values.name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: deps-default-name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v2 | ||
appVersion: 1.16.0 | ||
description: A chart for testing dependencies | ||
name: deps-chart | ||
type: application | ||
version: 1.0.0 | ||
dependencies: | ||
- name: sleeper-chart | ||
version: "0.1.0" | ||
repository: {{.HelmRepoUrl}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace: {{.TestNamespace}} | ||
helm: | ||
releaseName: simple-with-fleet-yaml | ||
chart: "" | ||
repo: "" | ||
version: "" | ||
disableDependencyUpdate: {{.DisableDependencyUpdate}} | ||
|
7 changes: 7 additions & 0 deletions
7
e2e/assets/deps-charts/with-fleet-yaml/templates/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: test-simple-deps-chart | ||
data: | ||
test: "valuedeps" | ||
name: {{ .Values.name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: deps-default-name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package singlecluster_test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/githelper" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
cp "github.com/otiai10/copy" | ||
) | ||
|
||
func getChartMuseumExternalAddr(env *testenv.Env) string { | ||
os.Getenv("GIT_HTTP_USER") | ||
username := os.Getenv("GIT_HTTP_USER") | ||
passwd := os.Getenv("GIT_HTTP_PASSWORD") | ||
Expect(username).ToNot(Equal("")) | ||
Expect(passwd).ToNot(Equal("")) | ||
return fmt.Sprintf("https://%s:%s@chartmuseum-service.%s.svc.cluster.local:8081", username, passwd, env.Namespace) | ||
} | ||
|
||
func setupChartDepsInTmpDir(chartDir string, tmpDir string, namespace string, disableDependencyUpdate bool, env *testenv.Env) { | ||
err := cp.Copy(chartDir, tmpDir) | ||
Expect(err).ToNot(HaveOccurred()) | ||
// replace the helm repo url | ||
helmRepoUrl := getChartMuseumExternalAddr(env) | ||
out := filepath.Join(tmpDir, "Chart.yaml") | ||
in := filepath.Join(chartDir, "Chart.yaml") | ||
err = testenv.Template(out, in, struct { | ||
HelmRepoUrl string | ||
}{ | ||
helmRepoUrl, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
if _, err = os.Stat(filepath.Join(chartDir, "fleet.yaml")); !os.IsNotExist(err) { | ||
out = filepath.Join(tmpDir, "fleet.yaml") | ||
in = filepath.Join(chartDir, "fleet.yaml") | ||
err = testenv.Template(out, in, struct { | ||
TestNamespace string | ||
DisableDependencyUpdate bool | ||
}{ | ||
namespace, | ||
disableDependencyUpdate, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
} | ||
} | ||
|
||
var _ = Describe("Helm dependency update tests", Label("infra-setup", "helm-registry"), func() { | ||
var ( | ||
asset string | ||
k kubectl.Command | ||
gh *githelper.Git | ||
clonedir string | ||
inClusterRepoURL string | ||
tmpDir string | ||
gitrepoName string | ||
r = rand.New(rand.NewSource(GinkgoRandomSeed())) | ||
namespace string | ||
disableDependencyUpdate bool | ||
) | ||
|
||
JustBeforeEach(func() { | ||
k = env.Kubectl.Namespace(env.Namespace) | ||
// Build git repo URL reachable _within_ the cluster, for the GitRepo | ||
host, err := githelper.BuildGitHostname(env.Namespace) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
addr, err := githelper.GetExternalRepoAddr(env, port, repoName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
gh = githelper.NewHTTP(addr) | ||
|
||
inClusterRepoURL = gh.GetInClusterURL(host, port, repoName) | ||
|
||
tmpDir, _ = os.MkdirTemp("", "fleet-") | ||
clonedir = path.Join(tmpDir, repoName) | ||
|
||
gitrepoName = testenv.RandomFilename("gitrepo-test", r) | ||
|
||
// setup the tmp chart dir. | ||
// we use a tmp dir because dependencies are downloaded to the directory | ||
tmpChart := GinkgoT().TempDir() | ||
setupChartDepsInTmpDir(testenv.AssetPath(asset), tmpChart, namespace, disableDependencyUpdate, env) | ||
|
||
_, err = gh.Create(clonedir, tmpChart, "examples") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
err = testenv.ApplyTemplate(k, testenv.AssetPath("deps-charts/gitrepo.yaml"), struct { | ||
Name string | ||
Repo string | ||
Branch string | ||
TargetNamespace string | ||
}{ | ||
gitrepoName, | ||
inClusterRepoURL, | ||
gh.Branch, | ||
namespace, // to avoid conflicts with other tests | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
AfterEach(func() { | ||
out, err := k.Delete("gitrepo", gitrepoName) | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
out, err = k.Delete("ns", namespace) | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
}) | ||
|
||
When("applying a gitrepo resource", func() { | ||
Context("containing a helm chart with dependencies and no fleet.yaml", func() { | ||
BeforeEach(func() { | ||
namespace = "no-fleet-yaml" | ||
asset = "deps-charts/" + namespace | ||
disableDependencyUpdate = false | ||
}) | ||
It("deploys the chart plus its dependencies", func() { | ||
Eventually(func() bool { | ||
outConfigMaps, _ := k.Namespace(namespace).Get("configmaps") | ||
outPods, _ := k.Namespace(namespace).Get("pods") | ||
return strings.Contains(outConfigMaps, "test-simple-deps-chart") && strings.Contains(outPods, "sleeper-") | ||
}).Should(BeTrue()) | ||
}) | ||
}) | ||
Context("containing a helm chart with dependencies and fleet.yaml with disableDependencyUpdate=false", func() { | ||
BeforeEach(func() { | ||
namespace = "with-fleet-yaml" | ||
asset = "deps-charts/" + namespace | ||
disableDependencyUpdate = false | ||
}) | ||
It("deploys the chart plus its dependencies", func() { | ||
Eventually(func() bool { | ||
outConfigMaps, _ := k.Namespace(namespace).Get("configmaps") | ||
outPods, _ := k.Namespace(namespace).Get("pods") | ||
return strings.Contains(outConfigMaps, "test-simple-deps-chart") && strings.Contains(outPods, "sleeper-") | ||
}).Should(BeTrue()) | ||
}) | ||
}) | ||
Context("containing a helm chart with dependencies and fleet.yaml with disableDependencyUpdate=true", func() { | ||
BeforeEach(func() { | ||
namespace = "with-fleet-yaml" | ||
asset = "deps-charts/" + namespace | ||
disableDependencyUpdate = true | ||
}) | ||
It("deploys the chart, but not its dependencies", func() { | ||
Eventually(func() bool { | ||
outConfigMaps, _ := k.Namespace(namespace).Get("configmaps") | ||
outPods, _ := k.Namespace(namespace).Get("pods") | ||
return strings.Contains(outConfigMaps, "test-simple-deps-chart") && !strings.Contains(outPods, "sleeper-") | ||
}).Should(BeTrue()) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.