mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-01 18:26:25 +08:00
Support GitRepository source in HelmRelease cmds
This commit is contained in:
27
.github/workflows/e2e.yaml
vendored
27
.github/workflows/e2e.yaml
vendored
@ -88,32 +88,41 @@ jobs:
|
|||||||
- name: gotk delete kustomization
|
- name: gotk delete kustomization
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk delete kustomization podinfo --silent
|
./bin/gotk delete kustomization podinfo --silent
|
||||||
- name: gotk delete source git
|
|
||||||
run: |
|
|
||||||
./bin/gotk delete source git podinfo --silent
|
|
||||||
- name: gotk create source helm
|
- name: gotk create source helm
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk create source helm podinfo \
|
./bin/gotk create source helm podinfo \
|
||||||
--url https://stefanprodan.github.io/podinfo
|
--url https://stefanprodan.github.io/podinfo
|
||||||
- name: gotk create helmrelease
|
- name: gotk create helmrelease --source=HelmRepository/podinfo
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk create hr podinfo \
|
./bin/gotk create hr podinfo-helm \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=">4.0.0 <5.0.0"
|
--chart-version=">4.0.0 <5.0.0"
|
||||||
|
- name: gotk create helmrelease --source=GitRepository/podinfo
|
||||||
|
run: |
|
||||||
|
./bin/gotk create hr podinfo-git \
|
||||||
|
--target-namespace=default \
|
||||||
|
--source=GitRepository/podinfo \
|
||||||
|
--chart=./charts/podinfo
|
||||||
- name: gotk get helmreleases
|
- name: gotk get helmreleases
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk get helmreleases
|
./bin/gotk get helmreleases
|
||||||
- name: gotk export helmrelease
|
- name: gotk export helmrelease
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk export hr --all
|
./bin/gotk export hr --all
|
||||||
- name: gotk delete helmrelease
|
- name: gotk delete helmrelease podinfo-helm
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk delete hr podinfo --silent
|
./bin/gotk delete hr podinfo-helm --silent
|
||||||
|
- name: gotk delete helmrelease podinfo-git
|
||||||
|
run: |
|
||||||
|
./bin/gotk delete hr podinfo-git --silent
|
||||||
- name: gotk delete source helm
|
- name: gotk delete source helm
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk delete source helm podinfo --silent
|
./bin/gotk delete source helm podinfo --silent
|
||||||
|
- name: gotk delete source git
|
||||||
|
run: |
|
||||||
|
./bin/gotk delete source git podinfo --silent
|
||||||
- name: gotk check
|
- name: gotk check
|
||||||
run: |
|
run: |
|
||||||
./bin/gotk check
|
./bin/gotk check
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -41,28 +42,36 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
Aliases: []string{"hr"},
|
Aliases: []string{"hr"},
|
||||||
Short: "Create or update a HelmRelease resource",
|
Short: "Create or update a HelmRelease resource",
|
||||||
Long: "The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.",
|
Long: "The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.",
|
||||||
Example: ` # Create a HelmRelease from a source
|
Example: ` # Create a HelmRelease from a HelmRepository source
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--interval=10m \
|
--interval=10m \
|
||||||
--release-name=podinfo \
|
--release-name=podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=">4.0.0"
|
--chart-version=">4.0.0"
|
||||||
|
|
||||||
|
# Create a HelmRelease from a GitRepository source
|
||||||
|
gotk create hr podinfo \
|
||||||
|
--interval=10m \
|
||||||
|
--release-name=podinfo \
|
||||||
|
--target-namespace=default \
|
||||||
|
--source=GitRepository/podinfo \
|
||||||
|
--chart=./charts/podinfo
|
||||||
|
|
||||||
# Create a HelmRelease with values for a local YAML file
|
# Create a HelmRelease with values for a local YAML file
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=4.0.5 \
|
--chart-version=4.0.5 \
|
||||||
--values=./my-values.yaml
|
--values=./my-values.yaml
|
||||||
|
|
||||||
# Create a HelmRelease definition on disk without applying it on the cluster
|
# Create a HelmRelease definition on disk without applying it on the cluster
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=4.0.5 \
|
--chart-version=4.0.5 \
|
||||||
--values=./values.yaml \
|
--values=./values.yaml \
|
||||||
--export > podinfo-release.yaml
|
--export > podinfo-release.yaml
|
||||||
@ -74,7 +83,7 @@ var (
|
|||||||
hrName string
|
hrName string
|
||||||
hrSource string
|
hrSource string
|
||||||
hrDependsOn []string
|
hrDependsOn []string
|
||||||
hrChartName string
|
hrChart string
|
||||||
hrChartVersion string
|
hrChartVersion string
|
||||||
hrTargetNamespace string
|
hrTargetNamespace string
|
||||||
hrValuesFile string
|
hrValuesFile string
|
||||||
@ -82,9 +91,9 @@ var (
|
|||||||
|
|
||||||
func init() {
|
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(&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(&hrSource, "source", "", "source that contains the chart (<kind>/<name>)")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&hrChartName, "chart-name", "", "Helm chart name")
|
createHelmReleaseCmd.Flags().StringVar(&hrChart, "chart", "", "Helm chart name or path")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts semver range")
|
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().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(&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")
|
createHelmReleaseCmd.Flags().StringVar(&hrValuesFile, "values", "", "local path to the values.yaml file")
|
||||||
@ -100,11 +109,16 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
if hrSource == "" {
|
if hrSource == "" {
|
||||||
return fmt.Errorf("source is required")
|
return fmt.Errorf("source is required")
|
||||||
}
|
}
|
||||||
if hrChartName == "" {
|
hrSourceElements := strings.Split(hrSource, "/")
|
||||||
return fmt.Errorf("chart name is required")
|
if len(hrSourceElements) != 2 {
|
||||||
|
return fmt.Errorf("source must be in format <kind>/<name>")
|
||||||
}
|
}
|
||||||
if hrChartVersion == "" {
|
hrSourceKind, hrSourceName := hrSourceElements[0], hrSourceElements[1]
|
||||||
return fmt.Errorf("chart version is required")
|
if hrSourceKind != sourcev1.HelmRepositoryKind && hrSourceKind != sourcev1.GitRepositoryKind {
|
||||||
|
return fmt.Errorf("source kind must be one of: %s", []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind})
|
||||||
|
}
|
||||||
|
if hrChart == "" {
|
||||||
|
return fmt.Errorf("chart name or path is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
@ -133,11 +147,11 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
TargetNamespace: hrTargetNamespace,
|
TargetNamespace: hrTargetNamespace,
|
||||||
Chart: helmv2.HelmChartTemplate{
|
Chart: helmv2.HelmChartTemplate{
|
||||||
Spec: helmv2.HelmChartTemplateSpec{
|
Spec: helmv2.HelmChartTemplateSpec{
|
||||||
Chart: hrChartName,
|
Chart: hrChart,
|
||||||
Version: hrChartVersion,
|
Version: hrChartVersion,
|
||||||
SourceRef: helmv2.CrossNamespaceObjectReference{
|
SourceRef: helmv2.CrossNamespaceObjectReference{
|
||||||
Kind: sourcev1.HelmRepositoryKind,
|
Kind: hrSourceKind,
|
||||||
Name: hrSource,
|
Name: hrSourceName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -81,7 +82,12 @@ func reconcileHrCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if syncHrWithSource {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,28 +13,36 @@ gotk create helmrelease [name] [flags]
|
|||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```
|
```
|
||||||
# Create a HelmRelease from a source
|
# Create a HelmRelease from a HelmRepository source
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--interval=10m \
|
--interval=10m \
|
||||||
--release-name=podinfo \
|
--release-name=podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=">4.0.0"
|
--chart-version=">4.0.0"
|
||||||
|
|
||||||
|
# Create a HelmRelease from a GitRepository source
|
||||||
|
gotk create hr podinfo \
|
||||||
|
--interval=10m \
|
||||||
|
--release-name=podinfo \
|
||||||
|
--target-namespace=default \
|
||||||
|
--source=GitRepository/podinfo \
|
||||||
|
--chart=./charts/podinfo
|
||||||
|
|
||||||
# Create a HelmRelease with values for a local YAML file
|
# Create a HelmRelease with values for a local YAML file
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=4.0.5 \
|
--chart-version=4.0.5 \
|
||||||
--values=./my-values.yaml
|
--values=./my-values.yaml
|
||||||
|
|
||||||
# Create a HelmRelease definition on disk without applying it on the cluster
|
# Create a HelmRelease definition on disk without applying it on the cluster
|
||||||
gotk create hr podinfo \
|
gotk create hr podinfo \
|
||||||
--target-namespace=default \
|
--target-namespace=default \
|
||||||
--source=podinfo \
|
--source=HelmRepository/podinfo \
|
||||||
--chart-name=podinfo \
|
--chart=podinfo \
|
||||||
--chart-version=4.0.5 \
|
--chart-version=4.0.5 \
|
||||||
--values=./values.yaml \
|
--values=./values.yaml \
|
||||||
--export > podinfo-release.yaml
|
--export > podinfo-release.yaml
|
||||||
@ -44,12 +52,12 @@ gotk create helmrelease [name] [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--chart-name string Helm chart name
|
--chart string Helm chart name or path
|
||||||
--chart-version string Helm chart version, accepts semver range
|
--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
|
--depends-on stringArray HelmReleases that must be ready before this release can be installed
|
||||||
-h, --help help for helmrelease
|
-h, --help help for helmrelease
|
||||||
--release-name string name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'
|
--release-name string name used for the Helm release, defaults to a composition of '<target-namespace>-<hr-name>'
|
||||||
--source string HelmRepository name
|
--source string source that contains the chart (<kind>/<name>)
|
||||||
--target-namespace string namespace to install this release, defaults to the HelmRelease namespace
|
--target-namespace string namespace to install this release, defaults to the HelmRelease namespace
|
||||||
--values string local path to the values.yaml file
|
--values string local path to the values.yaml file
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user