Skip to content
Snippets Groups Projects
Commit ef4877d6d4e0 authored by steeve.chailloux's avatar steeve.chailloux
Browse files

runner: add Ytt type and Ytt.BuildArgs methode

parent 47583b2d05ff
No related branches found
No related tags found
No related merge requests found
......@@ -109,7 +109,29 @@
type CmdSpec struct {
Variables []Variable
Charts CmdCharts
Ytt []string
Ytt Ytt
}
type Ytt []string
func (y Ytt) BuildArgs(namespace string, compiled []string) ([]string, error) {
// ytt -f $chartsTmpFile --file-mark "$(basename $chartsTmpFile):type=yaml-plain"\
// -f base/ytt/ -f base/ytt.yml -f ns1/ytt/ -f ns1/ytt.yml
var args []string
for _, c := range compiled {
args = append(args, "-f", c, "--file-mark", filepath.Base(c))
}
for _, entry := range []string{
filepath.Join("base", "ytt"),
filepath.Join("base", "ytt.yaml"),
filepath.Join("environments", namespace, "ytt"),
filepath.Join("environments", namespace, "ytt.yaml")} {
if _, err := os.Stat(entry); !os.IsExist(err) {
args = append(args, "-f", entry)
}
}
return args, nil
}
type CmdCharts map[string]CmdChart
......@@ -144,9 +166,6 @@
return args, nil
}
// ytt -f $chartsTmpFile --file-mark "$(basename $chartsTmpFile):type=yaml-plain"\
// -f base/ytt/ -f base/ytt.yml -f ns1/ytt/ -f ns1/ytt.yml
func cmdChartFromChart(c Chart) CmdChart {
return CmdChart{
Type: c.Type,
......
package runner
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
......@@ -4,7 +5,8 @@
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"orus.io/cloudcrane/beaver/testutils"
)
func TestConfig(t *testing.T) {
......@@ -17,3 +19,27 @@
assert.Equal(t, "vendor/helm/postgresql", config.Spec.Charts["postgres"].Path)
assert.Equal(t, "vendor/ytt/odoo", config.Spec.Charts["odoo"].Path)
}
func TestYttBuildArgs(t *testing.T) {
tl := testutils.NewTestLogger(t)
testNS := "ns1"
absConfigDir, err := filepath.Abs("fixtures/")
require.NoError(t, err)
c := NewCmdConfig(tl.Logger(), absConfigDir, testNS, false)
require.NoError(t, c.Initialize())
args, err := c.Spec.Ytt.BuildArgs(testNS, []string{"/tmp/postgres.1234.yaml", "/tmp/odoo.5678.yaml"})
require.NoError(t, err)
assert.Equal(
t,
args,
[]string{
"-f", "/tmp/postgres.1234.yaml", "--file-mark", "postgres.1234.yaml",
"-f", "/tmp/odoo.5678.yaml", "--file-mark", "odoo.5678.yaml",
"-f", "base/ytt",
"-f", "base/ytt.yaml",
"-f", "environments/ns1/ytt",
"-f", "environments/ns1/ytt.yaml",
},
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment