Skip to content

Commit c19ee0a

Browse files
authored
Merge pull request #7 from arttor/support-apps
Support apps
2 parents d307e09 + 0a4af05 commit c19ee0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1692
-1015
lines changed

.github/workflows/release.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Release Go Binaries
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
releases-matrix:
9+
name: Release Matrix
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
goos: [ linux, windows, darwin ]
14+
goarch: [ amd64, arm, arm64, 386 ]
15+
exclude:
16+
- goarch: arm
17+
goos: darwin
18+
- goarch: 386
19+
goos: darwin
20+
- goarch: arm
21+
goos: windows
22+
- goarch: arm64
23+
goos: windows
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Set APP_VERSION env
28+
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
29+
- name: Set BUILD_TIME env
30+
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
31+
- name: Environment Printer
32+
uses: managedkaos/[email protected]
33+
34+
- uses: wangyoucao577/[email protected]
35+
with:
36+
github_token: ${{ secrets.RELEASE_TOKEN }}
37+
goos: ${{ matrix.goos }}
38+
goarch: ${{ matrix.goarch }}
39+
goversion: 1.16
40+
project_path: ./cmd/helmify
41+
ldflags: -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}" -X main.gitCommit=${{ github.sha }} -X main.gitRef=${{ github.ref }}

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,44 @@
1010

1111
CLI that creates [Helm](https://github.com/helm/helm) charts from kubernetes yamls.
1212

13-
Helmify reads a list of [supported k8s objects](#status) from stdin and converts it to a helm chart. Main [use-case](#integrate-to-your-operator-sdkkubebuilder-project) is to generate Helm charts for kubernetes operators build with
14-
[Operator-SDK](https://github.com/operator-framework/operator-sdk) or [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder). Submit issue if some features missing for your use-case.
13+
Helmify reads a list of [supported k8s objects](#status) from stdin and converts it to a helm chart.
14+
[One of use-cases](#integrate-to-your-operator-sdkkubebuilder-project) is to generate Helm charts for kubernetes operators build with
15+
[Operator-SDK](https://github.com/operator-framework/operator-sdk) or [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder).
1516

16-
## Run
17-
Clone repo and execute command:
17+
Submit issue if some features missing for your use-case.
1818

19-
```shell
20-
cat test_data/kustomize.output | go run cmd/helmify/main.go mychart
21-
```
19+
## Usage
2220

23-
Will generate `mychart` Helm chart form file `test_data/kustomize.output` representing typical operator
24-
[kustomize](https://github.com/kubernetes-sigs/kustomize) output.
21+
Example 1: `cat my-app.yaml | helmify mychart`
22+
- will create 'mychart' directory with Helm chart from yaml file with k8s objects.
23+
24+
Example 2: `awk 'FNR==1 && NR!=1 {print "---"}{print}' /<my_directory>/*.yaml | helmify mychart`
25+
- will create 'mychart' directory with Helm chart from all yaml files in `<my_directory> `directory.
2526

26-
## Integrate to your Operator-SDK/Kubebuilder project
27+
Example 3: `kustomize build <kustomize_dir> | helmify mychart`
28+
- will create 'mychart' directory with Helm chart from kustomize output.
29+
30+
### Integrate to your Operator-SDK/Kubebuilder project
2731
Tested with operator-sdk version: "v1.8.0".
2832
1. Open `Makefile` in your operator project generated by
2933
[Operator-SDK](https://github.com/operator-framework/operator-sdk) or [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder).
3034
2. Add these lines to `Makefile`:
3135
```makefile
3236
HELMIFY = $(shell pwd)/bin/helmify
3337
helmify:
34-
$(call go-get-tool,$(HELMIFY),github.com/arttor/helmify/cmd/helmify@v0.2.2)
38+
$(call go-get-tool,$(HELMIFY),github.com/arttor/helmify/cmd/helmify@v0.3.0)
3539

3640
helm: manifests kustomize helmify
3741
$(KUSTOMIZE) build config/default | $(HELMIFY)
3842
```
3943
3. Run `make helm` in project root. It will generate helm chart with name 'chart' in 'chart' directory.
4044

45+
## Install
46+
47+
Download suitable for your system binary from [the Releases page](https://github.com/arttor/helmify/releases/latest).
48+
49+
Unpack the helmify binary and add it to your PATH and you are good to go!
50+
4151
## Available options
4252
Helmify takes a chart name for an argument.
4353
Usage:
@@ -49,6 +59,7 @@ Usage:
4959
| -h -help | Prints help | `helmify -h`|
5060
| -v | Enable verbose output. Prints WARN and INFO. | `helmify -v`|
5161
| -vv | Enable very verbose output. Also prints DEBUG. | `helmify -vv`|
62+
| -version | Print helmify version. | `helmify -version`|
5263

5364
## Status
5465
Supported default operator resources:
@@ -75,10 +86,21 @@ examples for most k8s objects.
7586
2. Register your processor in the `pkg/app/app.go`
7687
3. Add relevant input sample to `test_data/kustomize.output`.
7788

89+
90+
### Run
91+
Clone repo and execute command:
92+
93+
```shell
94+
cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify mychart
95+
```
96+
97+
Will generate `mychart` Helm chart form file `test_data/k8s-operator-kustomize.output` representing typical operator
98+
[kustomize](https://github.com/kubernetes-sigs/kustomize) output.
99+
78100
### Test
79101
For manual testing, run program with debug output:
80102
```shell
81-
cat test_data/kustomize.output | go run cmd/helmify/main.go -vv mychart
103+
cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify -vv mychart
82104
```
83105
Then inspect logs and generated chart in `./mychart` directory.
84106

@@ -87,5 +109,5 @@ To execute tests, run:
87109
go test ./...
88110
```
89111
Beside unit-tests, project contains e2e test `pkg/app/app_e2e_test.go`.
90-
It's a go test, which uses `test_data/kustomize.output` to generate a chart in temporary directory.
112+
It's a go test, which uses `test_data/*` to generate a chart in temporary directory.
91113
Then runs `helm lint --strict` to check if generated chart is valid.
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
package flags
1+
package main
22

33
import (
44
"flag"
55
"fmt"
6-
"github.com/arttor/helmify/pkg/config"
76
"os"
7+
8+
"github.com/arttor/helmify/pkg/config"
89
)
910

1011
const helpText = `Helmify parses kubernetes resources from std.in and converts it to a Helm chart.
11-
Use this command as a pipe for 'kustomize build' command output.
1212
13-
Example: 'kustomize build <kustomize_dir> | helmify mychart'
14-
- will create 'mychart' directory with Helm chart.
13+
Example 1: 'kustomize build <kustomize_dir> | helmify mychart'
14+
- will create 'mychart' directory with Helm chart from kustomize output.
15+
16+
Example 2: 'cat my-app.yaml | helmify mychart'
17+
- will create 'mychart' directory with Helm chart from yaml file.
18+
19+
Example 3: 'awk 'FNR==1 && NR!=1 {print "---"}{print}' /my_directory/*.yaml | helmify mychart'
20+
- will create 'mychart' directory with Helm chart from all yaml files in my_directory directory.
1521
1622
Usage:
1723
helmify [flags] CHART_NAME - CHART_NAME is optional. Default is 'chart'.
1824
1925
Flags:
2026
`
2127

22-
// Read command-line flags into app config.
23-
func Read() config.Config {
28+
// ReadFlags command-line flags into app config.
29+
func ReadFlags() config.Config {
2430
result := config.Config{}
25-
var h, help bool
31+
var h, help, version bool
2632
flag.BoolVar(&h, "h", false, "Print help. Example: helmify -h")
2733
flag.BoolVar(&help, "help", false, "Print help. Example: helmify -help")
34+
flag.BoolVar(&version, "version", false, "Print helmify version. Example: helmify -version")
2835
flag.BoolVar(&result.Verbose, "v", false, "Enable verbose output (print WARN & INFO). Example: helmify -v")
2936
flag.BoolVar(&result.VeryVerbose, "vv", false, "Enable very verbose output. Same as verbose but with DEBUG. Example: helmify -vv")
3037
flag.Parse()
@@ -33,9 +40,10 @@ func Read() config.Config {
3340
flag.PrintDefaults()
3441
os.Exit(0)
3542
}
36-
result.ChartName = flag.Arg(0)
37-
if result.ChartName == "" {
38-
result.ChartName = config.DefaultChartName
43+
if version {
44+
printVersion()
45+
os.Exit(0)
3946
}
47+
result.ChartName = flag.Arg(0)
4048
return result
4149
}

cmd/helmify/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package main
22

33
import (
4+
"os"
5+
46
"github.com/arttor/helmify/pkg/app"
5-
"github.com/arttor/helmify/pkg/flags"
67
"github.com/sirupsen/logrus"
7-
"os"
88
)
99

1010
func main() {
11-
conf := flags.Read()
11+
conf := ReadFlags()
1212
stat, err := os.Stdin.Stat()
1313
if err != nil {
1414
logrus.WithError(err).Error("stdin error")

cmd/helmify/version.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"helm.sh/helm/v3/pkg/time"
7+
)
8+
9+
// these information will be collected when build, by `-ldflags "-X main.appVersion=0.1"`.
10+
var (
11+
appVersion = "development"
12+
buildTime = time.Now().Format("2006 Jan 02 15:04:05")
13+
gitCommit = "not set"
14+
gitRef = "not set"
15+
)
16+
17+
func printVersion() {
18+
fmt.Printf("Version: %s\n", appVersion)
19+
fmt.Printf("Build Time: %s\n", buildTime)
20+
fmt.Printf("Git Commit: %s\n", gitCommit)
21+
fmt.Printf("Git Ref: %s\n", gitRef)
22+
}

internal/test_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ metadata:
1515
TestNsName = "my-operator-system"
1616
)
1717

18-
// TestNs k8s namespace object example
18+
// TestNs k8s namespace object example.
1919
var TestNs = GenerateObj(nsYaml)
2020

2121
// GenerateObj generates unstructured form yaml string.

pkg/app/app.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ package app
22

33
import (
44
"context"
5+
"github.com/arttor/helmify/pkg/processor"
6+
"io"
7+
"os"
8+
"os/signal"
9+
"syscall"
10+
511
"github.com/arttor/helmify/pkg/config"
612
"github.com/arttor/helmify/pkg/decoder"
713
"github.com/arttor/helmify/pkg/helm"
8-
"github.com/arttor/helmify/pkg/helmify"
914
"github.com/arttor/helmify/pkg/processor/configmap"
1015
"github.com/arttor/helmify/pkg/processor/crd"
1116
"github.com/arttor/helmify/pkg/processor/deployment"
@@ -14,14 +19,14 @@ import (
1419
"github.com/arttor/helmify/pkg/processor/service"
1520
"github.com/arttor/helmify/pkg/processor/webhook"
1621
"github.com/sirupsen/logrus"
17-
"io"
18-
"os"
19-
"os/signal"
20-
"syscall"
2122
)
2223

2324
// Start - application entrypoint for processing input to a Helm chart.
2425
func Start(input io.Reader, config config.Config) error {
26+
err := config.Validate()
27+
if err != nil {
28+
return err
29+
}
2530
setLogLevel(config)
2631
ctx, cancelFunc := context.WithCancel(context.Background())
2732
defer cancelFunc()
@@ -33,25 +38,23 @@ func Start(input io.Reader, config config.Config) error {
3338
cancelFunc()
3439
}()
3540
objects := decoder.Decode(ctx.Done(), input)
36-
helmifyContext := &helmify.Context{}
37-
helmifyContext = helmifyContext.WithConfig(config).WithProcessors(configmap.New(),
41+
appCtx := New(config, helm.NewOutput())
42+
appCtx = appCtx.WithProcessors(configmap.New(),
3843
crd.New(),
3944
deployment.New(),
4045
service.New(),
41-
rbac.ClusterRole(),
4246
rbac.ClusterRoleBinding(),
4347
rbac.Role(),
4448
rbac.RoleBinding(),
4549
rbac.ServiceAccount(),
4650
secret.New(),
4751
webhook.Issuer(),
4852
webhook.Certificate(),
49-
webhook.Webhook()).WithOutput(helm.NewOutput())
50-
53+
webhook.Webhook()).WithDefaultProcessor(processor.Default())
5154
for obj := range objects {
52-
helmifyContext.Add(obj)
55+
appCtx.Add(obj)
5356
}
54-
return helmifyContext.CreateHelm(ctx.Done())
57+
return appCtx.CreateHelm(ctx.Done())
5558
}
5659

5760
func setLogLevel(config config.Config) {

pkg/app/app_e2e_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,58 @@ package app
22

33
import (
44
"bufio"
5+
"os"
6+
"testing"
7+
58
"github.com/arttor/helmify/pkg/config"
69
"github.com/stretchr/testify/assert"
710
"helm.sh/helm/v3/pkg/action"
8-
"os"
9-
"testing"
1011
)
1112

1213
const (
13-
chartName = "my_test_chart"
14+
operatorChartName = "test-operator"
15+
appChartName = "test-app"
1416
)
1517

16-
func TestStart(t *testing.T) {
17-
file, err := os.Open("../../test_data/kustomize.output")
18+
func TestOperator(t *testing.T) {
19+
file, err := os.Open("../../test_data/k8s-operator-kustomize.output")
20+
assert.NoError(t, err)
21+
22+
objects := bufio.NewReader(file)
23+
err = Start(objects, config.Config{ChartName: operatorChartName})
24+
assert.NoError(t, err)
25+
26+
t.Cleanup(func() {
27+
err = os.RemoveAll(operatorChartName)
28+
assert.NoError(t, err)
29+
})
30+
31+
helmLint := action.NewLint()
32+
helmLint.Strict = true
33+
helmLint.Namespace = "test-ns"
34+
result := helmLint.Run([]string{operatorChartName}, nil)
35+
for _, err = range result.Errors {
36+
assert.NoError(t, err)
37+
}
38+
}
39+
40+
func TestApp(t *testing.T) {
41+
file, err := os.Open("../../test_data/sample-app.yaml")
1842
assert.NoError(t, err)
1943

2044
objects := bufio.NewReader(file)
21-
err = Start(objects, config.Config{ChartName: chartName})
45+
err = Start(objects, config.Config{ChartName: appChartName})
2246
assert.NoError(t, err)
2347

2448
t.Cleanup(func() {
25-
err = os.RemoveAll(chartName)
49+
err = os.RemoveAll(appChartName)
2650
assert.NoError(t, err)
2751
})
2852

2953
helmLint := action.NewLint()
3054
helmLint.Strict = true
3155
helmLint.Namespace = "test-ns"
32-
result := helmLint.Run([]string{chartName}, nil)
56+
result := helmLint.Run([]string{appChartName}, nil)
3357
for _, err = range result.Errors {
3458
assert.NoError(t, err)
3559
}

0 commit comments

Comments
 (0)