Skip to content

Commit

Permalink
Bump shoal and add acceptance test
Browse files Browse the repository at this point in the history
The acceptance test suite can be run with `TF_HELMFILE_ACC=1 go test ./...` where `main_test.go` contains code.
  • Loading branch information
mumoshu committed Jan 2, 2021
1 parent 4e0c25b commit ecba81b
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 47 deletions.
6 changes: 3 additions & 3 deletions examples/testdata/01-bootstrap/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repositories:
- name: sp
url: https://stefanprodan.github.io/podinfo
- name: flagger
url: https://flagger.app

releases:
- name: {{ .Values.name }}-{{ requiredEnv "FOO" }}
chart: sp/podinfo
chart: flagger/podinfo
values:
- values.yaml
labels:
Expand Down
4 changes: 4 additions & 0 deletions examples/testdata/01-bootstrap/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ resource "helmfile_release_set" "mystack" {

helm_binary = "helm3"

version = "0.135.0"

working_directory = path.module

environment = "default"
Expand All @@ -13,6 +15,8 @@ resource "helmfile_release_set" "mystack" {
FOO = "foo"
}

kubeconfig = "kubeconfig"

values = [
<<EOF
{"name": "myapp"}
Expand Down
22 changes: 19 additions & 3 deletions examples/testdata/02-more-resources/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
repositories:
- name: sp
url: https://stefanprodan.github.io/podinfo
- name: flagger
url: https://flagger.app

releases:
- name: {{ .Values.name }}-{{ requiredEnv "FOO" }}
chart: sp/podinfo
chart: flagger/podinfo
values:
- values.yaml
labels:
labelkey1: value1
labelkey2: value2

- name: {{ .Values.name }}-{{ requiredEnv "FOO" }}-2
chart: flagger/podinfo
values:
- values.yaml
labels:
labelkey1: value1
labelkey2: value2

- name: {{ .Values.name }}-{{ requiredEnv "FOO" }}-3
chart: flagger/podinfo
values:
- values.yaml
labels:
Expand Down
76 changes: 47 additions & 29 deletions examples/testdata/02-more-resources/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "helmfile_embedding_example" "emb1" {

helm_binary = "helm3"


version = "0.135.0"

working_directory = path.module

Expand All @@ -16,6 +16,8 @@ resource "helmfile_embedding_example" "emb1" {
FOO = "emb1"
}

kubeconfig = "kubeconfig"

values = [
<<EOF
{"name": "myapp"}
Expand All @@ -33,7 +35,7 @@ resource "helmfile_release_set" "mystack" {

helm_binary = "helm3"


version = "0.135.0"

working_directory = path.module

Expand All @@ -43,6 +45,8 @@ resource "helmfile_release_set" "mystack" {
FOO = "foo"
}

kubeconfig = "kubeconfig"

values = [
<<EOF
{"name": "myapp"}
Expand All @@ -59,21 +63,23 @@ resource "helmfile_release_set" "mystack2" {
releases:
- name: myapp2
chart: sp/podinfo
chart: flagger/podinfo
values:
- image:
tag: "123"
labels:
labelkey1: value1
- name: myapp3
chart: sp/podinfo
chart: flagger/podinfo
values:
- image:
tag: "2345"
EOF

helm_binary = "helm3"

version = "0.135.0"

// working_directory = path.module
working_directory = "mystack2"

Expand All @@ -83,6 +89,8 @@ EOF
FOO = "foo"
}

kubeconfig = "kubeconfig"

values = [
<<EOF
{"name": "myapp"}
Expand All @@ -92,6 +100,10 @@ EOF
selector = {
labelkey1 = "value1"
}

depends_on = [
helmfile_release_set.mystack,
]
}

output "mystack_diff" {
Expand All @@ -109,28 +121,34 @@ output "mystack2_diff" {
output "mystack2_apply" {
value = helmfile_release_set.mystack2.apply_output
}

resource "helmfile_release" "myapp" {
name = "myapp"
namespace = "default"
chart = "sp/podinfo"
helm_binary = "helm3"

// working_directory = path.module
// working_directory = "myapp"
values = [
<<EOF
{ "image": {"tag": "3.1455" } }
EOF
]
}


output "myapp_diff" {
value = helmfile_release.myapp.diff_output
}

output "myapp_apply" {
value = helmfile_release.myapp.apply_output
}

//
//resource "helmfile_release" "myapp" {
// name = "myapp"
// namespace = "default"
// chart = "flagger/podinfo"
// helm_binary = "helm3"
// version = "0.135.0"
// kubeconfig = "kubeconfig"
//
// // working_directory = path.module
// // working_directory = "myapp"
// values = [
// <<EOF
//{ "image": {"tag": "3.1455" } }
//EOF
// ]
//
// depends_on = [
// helmfile_release_set.mystack2,
// ]
//}
//
//
//output "myapp_diff" {
// value = helmfile_release.myapp.diff_output
//}
//
//output "myapp_apply" {
// value = helmfile_release.myapp.apply_output
//}
//
6 changes: 3 additions & 3 deletions examples/testdata/03-add-prom/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repositories:
- name: sp
url: https://stefanprodan.github.io/podinfo
- name: flagger
url: https://flagger.app

releases:
- name: {{ .Values.name }}-{{ requiredEnv "FOO" }}
chart: sp/podinfo
chart: flagger/podinfo
values:
- values.yaml
labels:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/hashicorp/terraform-plugin-sdk v1.0.0
github.com/mitchellh/go-linereader v0.0.0-20190213213312-1b945b3263eb
github.com/mumoshu/shoal v0.2.14
github.com/mumoshu/shoal v0.2.18
github.com/pkg/profile v1.5.0
github.com/rs/xid v1.2.1
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ github.com/mumoshu/shoal v0.2.13 h1:eur91JPm0EqPMsPSX62DLe6M0Lqyjdwi3sBESuEQTd8=
github.com/mumoshu/shoal v0.2.13/go.mod h1:/uyTFO3SO6tTcFEdpG35j/xGhRkBCcvkr523VxTDrrg=
github.com/mumoshu/shoal v0.2.14 h1:CTrYl/rlUqvosP6A+2IopKcPaoNFddwqolSzrK3mRGU=
github.com/mumoshu/shoal v0.2.14/go.mod h1:/uyTFO3SO6tTcFEdpG35j/xGhRkBCcvkr523VxTDrrg=
github.com/mumoshu/shoal v0.2.18 h1:aazA6O1oXAbkJqyJSWdrVLwnj1vETeLf4fGW2QCZs9A=
github.com/mumoshu/shoal v0.2.18/go.mod h1:TjMI6WkJ20NAhdP7xvXoDfd7EFpeSOh6xI34HMLRrHo=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down
41 changes: 33 additions & 8 deletions pkg/helmfile/shoal.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package helmfile

import (
"bytes"
"errors"
"fmt"
"github.com/mumoshu/shoal"
"golang.org/x/xerrors"
"os"
"path/filepath"
"sync"
"time"
)

var shoalMu sync.Mutex
Expand Down Expand Up @@ -60,31 +63,53 @@ func prepareBinaries(fs *ReleaseSet) (*string, *string, error) {
shoalMu.Lock()
defer shoalMu.Unlock()

s, err := shoal.New()
buf := &bytes.Buffer{}

s, err := shoal.New(shoal.LogOutput(buf))
if err != nil {
return nil, nil, err
}

if len(conf.Dependencies) > 0 {
if err := s.Init(); err != nil {
return nil, nil, fmt.Errorf("initializing shoal: %w", err)
return nil, nil, fmt.Errorf("initializing shoal: %w\n%s", err, buf.String())
}

if err := s.InitGitProvider(conf); err != nil {
return nil, nil, fmt.Errorf("initializing shoal git provider: %w", err)
return nil, nil, fmt.Errorf("initializing shoal git provider: %w\n%s", err, buf.String())
}

wd, err := os.Getwd()
if err != nil {
return nil, nil, err
}

// TODO Any better place to do this?
// This is for letting helm know about the location of helm plugins installed by shoal
os.Setenv("XDG_DATA_HOME", filepath.Join(wd, ".shoal/Library"))
if conf.Helm.Plugins.Diff != "" {
// TODO Any better place to do this?
// This is for letting helm know about the location of helm plugins installed by shoal
os.Setenv("XDG_DATA_HOME", filepath.Join(wd, ".shoal/Library"))
}

errch := make(chan error)

if err := s.Sync(conf); err != nil {
return nil, nil, err
go func() {
if err := s.Sync(conf); err != nil {
errch <- fmt.Errorf("syncing shoal foods: %w\n%s", err, buf.String())
}

errch <- nil
}()

timer := time.NewTicker(60 * time.Second)
defer timer.Stop()

select {
case err := <-errch:
if err != nil {
return nil, nil, xerrors.Errorf("running shoal-sync: %w\n%s", err, buf.String())
}
case <-timer.C:
return nil, nil, fmt.Errorf("timeout exceeded while waiting for shoal-sync\n%s", buf.String())
}
}

Expand Down

0 comments on commit ecba81b

Please sign in to comment.