diff --git a/cmd/generate_test.go b/cmd/generate_test.go index e67f5bd..eec4a50 100644 --- a/cmd/generate_test.go +++ b/cmd/generate_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestGenerate(t *testing.T) { +func TestGenerateJSON(t *testing.T) { components, err := Generate("../test/fixtures/generate", "prod") assert.Nil(t, err) @@ -25,3 +25,20 @@ func TestGenerate(t *testing.T) { assert.Equal(t, "kibana", components[5].Name) assert.Equal(t, 1595, len(components[5].Manifest)) } + +func TestGenerateYAML(t *testing.T) { + components, err := Generate("../test/fixtures/generate-yaml", "prod") + + assert.Nil(t, err) + + assert.Equal(t, 3, len(components)) + + assert.Equal(t, "prometheus-grafana", components[0].Name) + assert.Equal(t, 125, len(components[0].Manifest)) + + assert.Equal(t, "grafana", components[1].Name) + assert.Equal(t, 8159, len(components[1].Manifest)) + + assert.Equal(t, "prometheus", components[2].Name) + assert.Equal(t, 21023, len(components[2].Manifest)) +} diff --git a/cmd/install_test.go b/cmd/install_test.go index 96130b7..6c5abff 100644 --- a/cmd/install_test.go +++ b/cmd/install_test.go @@ -6,13 +6,13 @@ import ( "github.com/stretchr/testify/assert" ) -func TestInstall(t *testing.T) { +func TestInstallJSON(t *testing.T) { err := Install("../test/fixtures/install") assert.Nil(t, err) } -func TestInstallYaml(t *testing.T) { +func TestInstallYAML(t *testing.T) { err := Install("../test/fixtures/install-yaml") assert.Nil(t, err) diff --git a/generators/helm.go b/generators/helm.go index 05e8d3c..550ce30 100644 --- a/generators/helm.go +++ b/generators/helm.go @@ -51,6 +51,7 @@ func GenerateHelmComponent(component *core.Component) (manifest string, err erro configYaml, err := yaml.Marshal(&component.Config.Config) if err != nil { + log.Errorf("marshalling config yaml for helm generated component '%s' failed with: %s\n", component.Name, err.Error()) return "", err } @@ -71,6 +72,7 @@ func GenerateHelmComponent(component *core.Component) (manifest string, err erro manifests, err := exec.Command("docker", "run", "--rm", "-v", volumeMount, "alpine/helm:latest", "template", "/app/chart", "--values", "/app/chart/overriddenValues.yaml", "--name", name).Output() if err != nil { + log.Errorf("helm template failed with: %s\n", err.Error()) return "", err } diff --git a/test/fixtures/install-yaml/component.yaml b/test/fixtures/install-yaml/component.yaml new file mode 100644 index 0000000..c927ef9 --- /dev/null +++ b/test/fixtures/install-yaml/component.yaml @@ -0,0 +1,12 @@ +name: "elasticsearch-fluentd-kibana" +generator: "static" +path: "./manifests" +subcomponents: +- name: "grafana" + generator: "helm" + repo: "https://github.com/helm/charts" + path: "stable/grafana" +- name: "prometheus" + generator: "helm" + repo: "https://github.com/helm/charts" + path: "stable/prometheus" \ No newline at end of file diff --git a/test/fixtures/install-yaml/config/common.yaml b/test/fixtures/install-yaml/config/common.yaml new file mode 100644 index 0000000..5ebc84d --- /dev/null +++ b/test/fixtures/install-yaml/config/common.yaml @@ -0,0 +1,52 @@ +config: +subcomponents: + prometheus: + config: + namespace: "prometheus" + adminUser: "ops" + alertmanager: + persistentVolume: + storageClass: "default" + server: + persistentVolume: + storageClass": "default" + grafana: + config: + namespace: "grafana" + datasources: + datasources.yaml: + apiVersion: 1 + datasources: + - name: Prometheus + type: prometheus + url: http://prometheus-server.prometheus.svc.cluster.local + access: proxy + isDefault: true + dashboardProviders: + dashboardproviders.yaml: + apiVersion: 1 + providers: + - name: default + orgId: 1 + folder: + type: file + disableDeletion: false + editable: true + options: + path: /var/lib/grafana/dashboards/default + dashboards: + default: + cluster-metrics: + gnetId: 6417 + revision: 1 + datasource: Prometheus + persistent-volumes: + gnetId: 6739 + revision: 1 + datasource: Prometheus + persistence: + enabled: true + storageClassName: default + accessModes: + - ReadWriteOnce + size: 4Gi diff --git a/test/fixtures/install-yaml/manifests/grafana-namespace.yaml b/test/fixtures/install-yaml/manifests/grafana-namespace.yaml new file mode 100644 index 0000000..678134a --- /dev/null +++ b/test/fixtures/install-yaml/manifests/grafana-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: grafana \ No newline at end of file diff --git a/test/fixtures/install-yaml/manifests/prometheus-namespace.yaml b/test/fixtures/install-yaml/manifests/prometheus-namespace.yaml new file mode 100644 index 0000000..11563cd --- /dev/null +++ b/test/fixtures/install-yaml/manifests/prometheus-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: prometheus \ No newline at end of file