Skip to content

Commit

Permalink
Support GitRepository source in HelmRelease cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Sep 2, 2020
1 parent 97f9f0a commit 9e668e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ jobs:
run: |
./bin/gotk create source helm podinfo \
--url https://stefanprodan.github.io/podinfo
- name: gotk create helmrelease
- name: gotk create helmrelease from HelmRepository
run: |
./bin/gotk create hr podinfo \
./bin/gotk create hr podinfo-helm \
--target-namespace=default \
--source=podinfo \
--chart-name=podinfo \
--source-kind=HelmRepository \
--source-name=podinfo \
--chart=podinfo \
--chart-version=">4.0.0 <5.0.0"
- name: gotk create helmrelease from GitRepository
run: |
./bin/gotk create hr podinfo-git \
--target-namespace=default \
--source-kind=GitRepository \
--source-name=podinfo \
--chart=./charts/podinfo
- name: gotk get helmreleases
run: |
./bin/gotk get helmreleases
Expand Down
30 changes: 16 additions & 14 deletions cmd/gotk/create_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ var createHelmReleaseCmd = &cobra.Command{

var (
hrName string
hrSource string
hrSourceName string
hrSourceKind string
hrDependsOn []string
hrChartName string
hrChart string
hrChartVersion string
hrTargetNamespace string
hrValuesFile string
)

func init() {
createHelmReleaseCmd.Flags().StringVar(&hrName, "release-name", "", "name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'")
createHelmReleaseCmd.Flags().StringVar(&hrSource, "source", "", "HelmRepository name")
createHelmReleaseCmd.Flags().StringVar(&hrChartName, "chart-name", "", "Helm chart name")
createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts semver range")
createHelmReleaseCmd.Flags().StringVar(&hrSourceKind, "source-kind", "", "name of the source that contains the chart")
createHelmReleaseCmd.Flags().StringVar(&hrSourceName, "source-name", "", "kind of the source that contains the chart (HelmRepository or GitRepository)")
createHelmReleaseCmd.Flags().StringVar(&hrChart, "chart", "", "Helm chart name or path")
createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts semver range (ignored for charts from GitRepository sources)")
createHelmReleaseCmd.Flags().StringArrayVar(&hrDependsOn, "depends-on", nil, "HelmReleases that must be ready before this release can be installed")
createHelmReleaseCmd.Flags().StringVar(&hrTargetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
createHelmReleaseCmd.Flags().StringVar(&hrValuesFile, "values", "", "local path to the values.yaml file")
Expand All @@ -97,14 +99,14 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
}
name := args[0]

if hrSource == "" {
return fmt.Errorf("source is required")
if hrSourceKind != sourcev1.HelmRepositoryKind && hrSourceKind != sourcev1.GitRepositoryKind {
return fmt.Errorf("source kind should be one of: %s", []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind})
}
if hrChartName == "" {
return fmt.Errorf("chart name is required")
if hrSourceName == "" {
return fmt.Errorf("source name is required")
}
if hrChartVersion == "" {
return fmt.Errorf("chart version is required")
if hrChart == "" {
return fmt.Errorf("chart name or path is required")
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
Expand Down Expand Up @@ -133,11 +135,11 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
TargetNamespace: hrTargetNamespace,
Chart: helmv2.HelmChartTemplate{
Spec: helmv2.HelmChartTemplateSpec{
Chart: hrChartName,
Chart: hrChart,
Version: hrChartVersion,
SourceRef: helmv2.CrossNamespaceObjectReference{
Kind: sourcev1.HelmRepositoryKind,
Name: hrSource,
Kind: hrSourceKind,
Name: hrSourceName,
},
},
},
Expand Down
8 changes: 7 additions & 1 deletion cmd/gotk/reconcile_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"time"

sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -81,7 +82,12 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
}

if syncHrWithSource {
err := syncSourceHelmCmdRun(nil, []string{helmRelease.Spec.Chart.Spec.SourceRef.Name})
switch helmRelease.Spec.Chart.Spec.SourceRef.Kind {
case sourcev1.HelmRepositoryKind:
err = syncSourceHelmCmdRun(nil, []string{helmRelease.Spec.Chart.Spec.SourceRef.Name})
case sourcev1.GitRepositoryKind:
err = syncSourceGitCmdRun(nil, []string{helmRelease.Spec.Chart.Spec.SourceRef.Name})
}
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions docs/cmd/gotk_create_helmrelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ gotk create helmrelease [name] [flags]
### Options

```
--chart-name string Helm chart name
--chart-version string Helm chart version, accepts semver range
--chart string Helm chart name or path
--chart-version string Helm chart version, accepts semver range (ignored for charts from GitRepository sources)
--depends-on stringArray HelmReleases that must be ready before this release can be installed
-h, --help help for helmrelease
--release-name string name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'
--source string HelmRepository name
--source-kind string name of the source that contains the chart
--source-name string kind of the source that contains the chart (HelmRepository or GitRepository)
--target-namespace string namespace to install this release, defaults to the HelmRelease namespace
--values string local path to the values.yaml file
```
Expand Down

0 comments on commit 9e668e7

Please sign in to comment.