Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from openmeterio/rename-example
Browse files Browse the repository at this point in the history
Rename example
  • Loading branch information
sagikazarmark authored Jan 10, 2024
2 parents 82f90b0 + 35067e9 commit 724e926
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apk add --update --no-cache ca-certificates tzdata bash

SHELL ["/bin/bash", "-c"]

# This is so we can reuse examples in development
# This is so we can reuse presets in development
WORKDIR /etc/benthos

COPY cloudevents.spec.json /etc/benthos/
Expand Down
13 changes: 5 additions & 8 deletions ci/build.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -91,7 +90,7 @@ func (m *Build) binary(platform Platform, version Optional[string]) *File {
}

func (m *Build) HelmChart(version Optional[string]) *File {
chart := m.helmChartDir()
chart := helmChartDir(m.Source)

var opts HelmPackageOpts

Expand All @@ -103,15 +102,13 @@ func (m *Build) HelmChart(version Optional[string]) *File {
return dag.Helm(HelmOpts{Version: helmVersion}).Package(chart, opts)
}

func (m *Build) helmChartDir() *Directory {
chart := dag.Host().Directory(filepath.Join(root(), "deploy/charts/benthos-openmeter"), HostDirectoryOpts{
Exclude: []string{"charts"}, // exclude dependencies
})
func helmChartDir(source *Directory) *Directory {
chart := source.Directory("deploy/charts/benthos-openmeter")

readme := dag.HelmDocs(HelmDocsOpts{Version: helmDocsVersion}).Generate(chart, HelmDocsGenerateOpts{
Templates: []*File{
dag.Host().File(filepath.Join(root(), "deploy/charts/template.md")),
dag.Host().File(filepath.Join(root(), "deploy/charts/benthos-openmeter/README.tmpl.md")),
source.File("deploy/charts/template.md"),
source.File("deploy/charts/benthos-openmeter/README.tmpl.md"),
},
SortValuesOrder: "file",
})
Expand Down
57 changes: 57 additions & 0 deletions ci/lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"context"

"golang.org/x/sync/errgroup"
)

// Run various linters against the source code.
func (m *Ci) Lint() *Lint {
return &Lint{
Source: m.Source,
}
}

type Lint struct {
// +private
Source *Directory
}

func (m *Lint) All(ctx context.Context) error {
var group errgroup.Group

group.Go(func() error {
_, err := m.Go().Sync(ctx)
if err != nil {
return err
}

return nil
})

group.Go(func() error {
_, err := m.Helm().Sync(ctx)
if err != nil {
return err
}

return nil
})

return group.Wait()
}

func (m *Lint) Go() *Container {
return dag.GolangciLint(GolangciLintOpts{
Version: golangciLintVersion,
GoVersion: goVersion,
}).
Run(m.Source, GolangciLintRunOpts{
Verbose: true,
})
}

func (m *Lint) Helm() *Container {
return dag.Helm(HelmOpts{Version: helmVersion}).Lint(helmChartDir(m.Source))
}
14 changes: 1 addition & 13 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ func (m *Ci) Ci(ctx context.Context) error {
})

group.Go(func() error {
_, err := m.Lint().Sync(ctx)

return err
return m.Lint().All(ctx)
})

// TODO: run trivy scan on container(s?)
Expand Down Expand Up @@ -110,16 +108,6 @@ func (m *Ci) Test() *Container {
Exec([]string{"go", "test", "-v", "./..."})
}

func (m *Ci) Lint() *Container {
return dag.GolangciLint(GolangciLintOpts{
Version: golangciLintVersion,
GoVersion: goVersion,
}).
Run(m.Source, GolangciLintRunOpts{
Verbose: true,
})
}

// Build and publish a snapshot of all artifacts from the current development version.
func (m *Ci) Snapshot(ctx context.Context) error {
// TODO: capture branch name and push it as tag/version
Expand Down
1 change: 1 addition & 0 deletions ci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var excludes = []string{
".direnv",
".devenv",
"ci",
"deploy/charts/**/charts",
}

func exclude(paths ...string) []string {
Expand Down
6 changes: 3 additions & 3 deletions deploy/charts/benthos-openmeter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ helm install --generate-name --wait oci://ghcr.io/openmeterio/helm-charts/bentho
| image.tag | string | `""` | Image tag override for the default value (chart appVersion). |
| openmeter.url | string | `"https://openmeter.cloud"` | OpenMeter API URL |
| openmeter.token | string | `""` | OpenMeter token |
| config | object | `{}` | Benthos configuration Takes precedence over `useExistingConfigFile` and `useExample`. |
| useExistingConfigFile | string | `""` | Use an existing config file mounted via `volumes` and `volumeMounts`. Takes precedence over `useExample`. |
| useExample | string | `""` | Use one of the predefined examples. Note: Read the documentation for the specific example to learn about configuration via env vars. |
| config | object | `{}` | Benthos configuration Takes precedence over `configFile` and `preset`. |
| configFile | string | `""` | Use an existing config file mounted via `volumes` and `volumeMounts`. Takes precedence over `preset`. |
| preset | string | `""` | Use one of the predefined presets. Note: Read the documentation for the specific preset (example) to learn about configuration via env vars. |
| imagePullSecrets | list | `[]` | Reference to one or more secrets to be used when [pulling images](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret) (from private registries). |
| nameOverride | string | `""` | A name in place of the chart name for `app:` labels. |
| fullnameOverride | string | `""` | A name to substitute for the full names of resources. |
Expand Down
14 changes: 7 additions & 7 deletions deploy/charts/benthos-openmeter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ Create args for the deployment
{{- define "benthos-openmeter.args" -}}
{{- if .Values.config -}}
["benthos", "-c", "/etc/benthos/config.yaml"]
{{- else if .Values.useExistingConfigFile -}}
["benthos", "-c", "{{ .Values.useExistingConfigFile }}"]
{{- else if .Values.useExample }}
{{- if eq .Values.useExample "http-server" -}}
{{- else if .Values.configFile -}}
["benthos", "-c", "{{ .Values.configFile }}"]
{{- else if .Values.preset }}
{{- if eq .Values.preset "http-server" -}}
["benthos", "streams", "--no-api", "/etc/benthos/examples/http-server/input.yaml", "/etc/benthos/examples/http-server/output.yaml"]
{{- else if eq .Values.useExample "kubernetes-pod-exec-time" -}}
{{- else if eq .Values.preset "kubernetes-pod-exec-time" -}}
["benthos", "-c", "/etc/benthos/examples/kubernetes-pod-exec-time/config.yaml"]
{{- else }}
{{- fail (printf "Invalid example '%s" .Values.useExample) }}
{{- fail (printf "Invalid example '%s" .Values.preset) }}
{{- end }}
{{- else }}
{{- fail "One of 'config', 'useExistingConfigFile' or 'useExample' is required" }}
{{- fail "One of 'config', 'configFile' or 'preset' is required" }}
{{- end }}
{{- end }}
12 changes: 6 additions & 6 deletions deploy/charts/benthos-openmeter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ openmeter:
token: ""

# -- Benthos configuration
# Takes precedence over `useExistingConfigFile` and `useExample`.
# Takes precedence over `configFile` and `preset`.
config: {}

# -- Use an existing config file mounted via `volumes` and `volumeMounts`.
# Takes precedence over `useExample`.
useExistingConfigFile: ""
# Takes precedence over `preset`.
configFile: ""

# -- Use one of the predefined examples.
# Note: Read the documentation for the specific example to learn about configuration via env vars.
useExample: ""
# -- Use one of the predefined presets.
# Note: Read the documentation for the specific preset (example) to learn about configuration via env vars.
preset: ""

# -- Reference to one or more secrets to be used when [pulling images](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret) (from private registries).
imagePullSecrets: []
Expand Down
2 changes: 1 addition & 1 deletion examples/kubernetes-pod-exec-time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ kubectl apply -f seed/pod.yaml
Deploy Benthos to your cluster:

```shell
helm install --wait --namespace benthos --create-namespace --set useExample=kubernetes-pod-exec-time --set openmeter.url=<OPENMETER URL> --set openmeter.token=<OPENMETER_TOKEN> benthos-openmeter oci://ghcr.io/openmeterio/helm-charts/benthos-openmeter
helm install --wait --namespace benthos --create-namespace --set preset=kubernetes-pod-exec-time --set openmeter.url=<OPENMETER URL> --set openmeter.token=<OPENMETER_TOKEN> benthos-openmeter oci://ghcr.io/openmeterio/helm-charts/benthos-openmeter
```

> [!NOTE]
Expand Down

0 comments on commit 724e926

Please sign in to comment.