Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helm3 Support #307

Merged
merged 1 commit into from
Sep 6, 2024
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
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
with:
go-version: 1.17
id: go
- uses: azure/setup-helm@v1
- uses: azure/setup-helm@v4.2.0
with:
version: "v3.7.0" # default is latest stable
id: helm
version: 'v3.7.0'
id: install
- uses: azure/setup-kubectl@v1
id: install-kubectl
- uses: actions/checkout@v2
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: goreleaser
uses: goreleaser/goreleaser-action@v2
with:
args: release --snapshot --skip-publish --rm-dist --release-notes .release-notes.md
args: release --snapshot --skip=publish --clean --release-notes .release-notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-windows:
Expand All @@ -74,10 +74,10 @@ jobs:
with:
go-version: 1.17
id: go
- uses: azure/setup-helm@v1
- uses: azure/setup-helm@v4.2.0
with:
version: "v3.3.1" # default is latest stable
id: helm
version: 'v3.7.0'
id: install
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ bin/
.tools/
.vscode/
*.generated
.gitconfig

5 changes: 3 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
before:
hooks:
- make release-notes
Expand Down Expand Up @@ -43,7 +44,7 @@ archives:

brews:
- name: qbec
tap:
repository:
owner: splunk
name: homebrew-tap
url_template: https://github.com/splunk/qbec/releases/download/{{.Tag}}/{{.ArtifactName}}
Expand All @@ -59,7 +60,7 @@ brews:
checksum:
name_template: "sha256-checksums.txt"
snapshot:
name_template: "{{.Version}}-next"
version_template: "{{.Version}}-next"
changelog:
sort: asc
filters:
Expand Down
14 changes: 14 additions & 0 deletions examples/helm3/components/apache/datasource.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
objects: import 'data://helm/apache?config-from=apache-config',
config: {
name: 'mock-release',
options: {
repo: 'https://charts.bitnami.com/bitnami',
version: '11.2.17',
namespace: 'foobar',
},
values: {
key: 'value',
},
},
}
1 change: 1 addition & 0 deletions examples/helm3/components/apache/index.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import 'datasource.libsonnet').objects
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
objects: import 'data://helm/github.com/VictoriaMetrics/helm-charts/raw/347d4558d9c25cd341718bf5a2ee167da042c080/packages/victoria-metrics-cluster-0.9.6.tgz?config-from=victoria-config',
config: {
options: {},
values: {},
},
}
1 change: 1 addition & 0 deletions examples/helm3/components/victoria-metrics/index.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import 'datasource.libsonnet').objects
5 changes: 5 additions & 0 deletions examples/helm3/environments/base.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// this file has the baseline default parameters
{
components: {
},
}
7 changes: 7 additions & 0 deletions examples/helm3/environments/default.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// this file has the param overrides for the default environment
local base = import './base.libsonnet';

base {
components+: {
},
}
9 changes: 9 additions & 0 deletions examples/helm3/params.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// this file returns the params for the current qbec environment
local env = std.extVar('qbec.io/env');
local paramsMap = import 'glob-import:environments/*.libsonnet';
local baseFile = if env == '_' then 'base' else env;
local key = 'environments/%s.libsonnet' % baseFile;

if std.objectHas(paramsMap, key)
then paramsMap[key]
else error 'no param file %s found for environment %s' % [key, env]
22 changes: 22 additions & 0 deletions examples/helm3/qbec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: qbec.io/v1alpha1
kind: App
metadata:
name: helm3
spec:
environments:
default:
defaultNamespace: charts
context: kind
vars:
computed:
- name: helmSetup
code: |
{}
- name: victoria-config
code: |
(import 'components/victoria-metrics/datasource.libsonnet').config
- name: apache-config
code: |
(import 'components/apache/datasource.libsonnet').config
dataSources:
- helm3://helm?configVar=helmSetup
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/google/go-jsonnet v0.18.0
github.com/googleapis/gnostic v0.5.5
github.com/iancoleman/strcase v0.2.0
github.com/jonboulle/clockwork v0.2.2
github.com/mattn/go-isatty v0.0.14
github.com/pkg/errors v0.9.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
8 changes: 1 addition & 7 deletions internal/commands/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package commands

import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -47,13 +46,8 @@ func TestEvalWithDataSources(t *testing.T) {
var data map[string]interface{}
err = s.jsonOutput(&data)
require.NoError(t, err)

a := assert.New(t)
if runtime.GOOS == "windows" {
a.Equal("-n bar\r\n", data["foo"])
} else {
a.Equal("bar", data["foo"])
}
a.Equal("bar", data["foo"])
}

func TestEvalVars(t *testing.T) {
Expand Down
8 changes: 7 additions & 1 deletion site/content/userguide/usage/authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ A component is:
It is valid for a component to return an empty set of objects if runtime parameters determine that
nothing should be installed for a specific target environment.

## Using helm charts and external data sources
## Using external data sources

qbec provides integration to run external commands and consume their output in jsonnet code.
See the [Jsonnet data importer](../../../reference/jsonnet-external-data) for more information on how this works.

Note that the [expandHelmTemplate](../../../reference/jsonnet-native-funcs/#expandhelmtemplate) native function
is now deprecated in favor of the data importer mechanism.

## Native Helm integration

qbec provides native support for Helm3, allowing you to render Helm `values` during runtime via jsonnet. To use this
feature, configure a Helm datasource. See [examples/helm3](https://github.com/splunk/qbec/tree/main/examples/helm3/) for
an example component.

## Using other jsonnet libraries

[k8s-yaml-patch](https://github.com/splunk/k8s-yaml-patch),
Expand Down
2 changes: 1 addition & 1 deletion vm/internal/ds/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ func (d *execSource) Init(p datasource.ConfigProvider) (fErr error) {
if err != nil {
return err
}
c.initDefaults()
err = c.assertValid()
if err != nil {
return err
}
c.initDefaults()
d.runner = newRunner(&c)
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions vm/internal/ds/factory/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pkg/errors"
"github.com/splunk/qbec/vm/internal/ds"
"github.com/splunk/qbec/vm/internal/ds/exec"
"github.com/splunk/qbec/vm/internal/ds/helm3"
)

// Create creates a new data source from the supplied URL.
Expand All @@ -35,6 +36,7 @@ func Create(u string) (ds.DataSourceWithLifecycle, error) {
scheme := parsed.Scheme
switch scheme {
case exec.Scheme:
case helm3.Scheme:
default:
return nil, fmt.Errorf("data source URL '%s', unsupported scheme '%s'", u, scheme)
}
Expand All @@ -52,6 +54,8 @@ func Create(u string) (ds.DataSourceWithLifecycle, error) {
switch scheme {
case exec.Scheme:
return makeLazy(exec.New(name, varName)), nil
case helm3.Scheme:
return makeLazy(helm3.New(name, varName)), nil
default:
return nil, fmt.Errorf("internal error: unable to create a data source for %s", u)
}
Expand Down
Loading
Loading