Skip to content

Commit

Permalink
Merge pull request #30 from jabbukka/helmrelease_type
Browse files Browse the repository at this point in the history
Support HelmRelease's chart source type
  • Loading branch information
intelliguy authored Jun 21, 2021
2 parents 8388750 + 2d51927 commit 6d7131b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 102 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: ${{ github.repository }}/kustomize-helm-transformer
tag_with_sha: true
tag_with_ref: true
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@ Please take a look at the [example](https://github.com/openinfradev/kustomize-he
* go 1.14

## Features
1. Inline value path transform
2. Chart Ref transform
1. Replaced values of HelmRelease CustomResource using inline path
2. Replaced Chart Source of HelmRelease CustomResource

## Example
### Source HelmRelease
```
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: glance
name: prometheus
spec:
chart:
git: https://github.com/openstack/openstack-helm.git
path: glance
ref: master
releaseName: glance
targetNamespace: openstack
repository: https://prometheus-community.github.io/helm-charts
name: kube-prometheus-stack
version: 14.5.0
type: helmrepo
releaseName: prometheus
targetNamespace: lma
values:
conf:
ceph:
admin_keyring: admin_keyring
admin_keyring: TO_BE_FIXED
enabled: false
```
### Transformer Configuration
Expand All @@ -46,8 +47,12 @@ metadata:
global:
docker_registry: registry.cicd.stg.taco
charts:
- chartName: glance
chartRef: taco-k8s-v20.07
- name: prometheus
source:
repository: [email protected]:helm/charts
version: master
name: charts/stable/prometheus-operator
type: git
override:
conf.ceph.admin_keyring: abcde
conf.ceph.enabled: true
Expand All @@ -57,17 +62,18 @@ charts:
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: glance
name: prometheus
spec:
chart:
git: https://github.com/openstack/openstack-helm.git
path: glance
ref: taco-k8s-v20.07
releaseName: glance
targetNamespace: openstack
repository: [email protected]:helm/charts
version: master
name: charts/stable/prometheus-operator
type: git
releaseName: prometheus
targetNamespace: lma
values:
conf:
ceph:
admin_keyring: admin_keyring
admin_keyring: abcde
enabled: true
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type ReplacedChart struct {
}

// ChartSource defines the source of helm chart
// TODO: support to use git source
type ChartSource struct {
Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Version string `json:"version,omitempty" yamal:"version,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
}

//nolint: golint
Expand Down Expand Up @@ -129,6 +129,21 @@ func (p *plugin) replaceChartSource(origin map[string]interface{}, chartSource C
chart["version"] = version
}

if chartSource.Name != "" {
name, err := p.replaceGlobalVar(chartSource.Name)
if err != nil {
return err
}
chart["name"] = name
}

if chartSource.Type != "" {
chartType, err := p.replaceGlobalVar(chartSource.Type)
if err != nil {
return err
}
chart["type"] = chartType
}
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,60 @@ spec:
enabled: false
`)
}

func TestGitChartSource(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
BuildGoPlugin("openinfradev.github.com", "v1", "HelmValuesTransformer")
defer th.Reset()

rm := th.LoadAndRunTransformer(`
apiVersion: openinfradev.github.com/v1
kind: HelmValuesTransformer
metadata:
name: site
charts:
- name: kube-prometheus-stack
source:
repository: [email protected]:helm/charts
version: master
name: charts/stable/prometheus-operator
type: git
`, `
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: kube-prometheus-stack
spec:
chart:
name: TO_BE_FIXED
repository: TO_BE_FIXED
version: TO_BE_FIXED
type: TO_BE_FIXED
releaseName: kube-prometheus-stack
targetNamespace: lma
values:
conf:
ceph:
admin_keyring: abcde
enabled: true
`)
th.AssertActualEqualsExpected(rm, `
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: kube-prometheus-stack
spec:
chart:
name: charts/stable/prometheus-operator
repository: [email protected]:helm/charts
type: git
version: master
releaseName: kube-prometheus-stack
targetNamespace: lma
values:
conf:
ceph:
admin_keyring: abcde
enabled: true
`)
}
11 changes: 9 additions & 2 deletions plugin/openinfradev.github.com/v1/helmvaluestransformer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ module github.com/openinfradev/kustomize-helm-transformer/openinfradev.github.co
go 1.14

require (
github.com/google/go-cmp v0.5.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
k8s.io/client-go v0.18.10 // indirect
sigs.k8s.io/kustomize/api v0.6.5
sigs.k8s.io/kustomize/kustomize/v3 v3.8.7 // indirect
sigs.k8s.io/kustomize/kyaml v0.9.4
sigs.k8s.io/yaml v1.2.0
)
Loading

0 comments on commit 6d7131b

Please sign in to comment.