Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Add tests for updateDependencies #1562

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ clean:
realclean: clean
rm -rf ./cache

test:
PATH=${PATH}:${PWD}/bin go test ${TEST_FLAGS} $(shell go list ./... | grep -v "^github.com/weaveworks/flux/vendor" | sort -u)
test: build/helm
PATH=${PWD}/bin:${PWD}/build:${PATH} go test ${TEST_FLAGS} $(shell go list ./... | grep -v "^github.com/weaveworks/flux/vendor" | sort -u)

build/.%.done: docker/Dockerfile.%
mkdir -p ./build/docker/$*
Expand All @@ -64,11 +64,13 @@ build/helm-operator: cmd/helm-operator/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $@ $(LDFLAGS) -ldflags "-X main.version=$(shell ./docker/image-tag)" ./cmd/helm-operator

build/kubectl: cache/kubectl-$(KUBECTL_VERSION)
mkdir -p build
cp cache/kubectl-$(KUBECTL_VERSION) $@
strip $@
chmod a+x $@

build/helm: cache/helm-$(HELM_VERSION)
mkdir -p build
cp cache/helm-$(HELM_VERSION) $@
strip $@
chmod a+x $@
Expand Down
2 changes: 1 addition & 1 deletion integrations/helm/chartsync/chartsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (chs *ChartChangeSync) reconcileReleaseDef(fhr fluxv1beta1.HelmRelease) {
chartPath = filepath.Join(chartClone.export.Dir(), chartSource.Path)

if chs.config.UpdateDeps {
if err := updateDependencies(chartPath); err != nil {
if err := updateDependencies(chartPath, ""); err != nil {
chs.setCondition(&fhr, fluxv1beta1.HelmReleaseReleased, v1.ConditionFalse, ReasonDependencyFailed, err.Error())
chs.logger.Log("warning", "Failed to update chart dependencies", "namespace", fhr.Namespace, "name", fhr.Name, "error", err)
return
Expand Down
6 changes: 5 additions & 1 deletion integrations/helm/chartsync/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"path/filepath"
)

func updateDependencies(chartDir string) error {
// helmHome is optional; if it's "", it's left to default
func updateDependencies(chartDir, helmhome string) error {
var hasLockFile bool

// We are going to use `helm dep build`, which tries to update the
Expand All @@ -29,6 +30,9 @@ func updateDependencies(chartDir string) error {
}

cmd := exec.Command("helm", "repo", "update")
if helmhome != "" {
cmd.Args = append(cmd.Args, "--home", helmhome)
}
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("could not update repo: %s", string(out))
Expand Down
51 changes: 51 additions & 0 deletions integrations/helm/chartsync/deps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package chartsync

import (
"io/ioutil"
"os"
"os/exec"
"testing"
)

func Test_updateDependencies(t *testing.T) {
helmhome, err := ioutil.TempDir("", "flux-helm")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(helmhome)
cmd := exec.Command("helm", "init", "--client-only", "--home", helmhome)
if err := cmd.Run(); err != nil {
t.Fatal(err)
}

type args struct {
chartDir string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Chart without dependencies",
args: args{
chartDir: "test/chart-without-deps",
},
wantErr: false,
},
{
name: "non-existent chart",
args: args{
chartDir: "test/folder-doesnt-exist",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := updateDependencies(tt.args.chartDir, helmhome); (err != nil) != tt.wantErr {
t.Errorf("updateDependencies() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
21 changes: 21 additions & 0 deletions integrations/helm/chartsync/test/chart-without-deps/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A bare bones Helm chart for Kubernetes
name: chart-without-deps
version: 0.1.0