Add cli flags for chart interval and reconcile strategy
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
BIN
cmd/flux/.create_helmrelease.go.swp
Normal file
BIN
cmd/flux/.create_helmrelease.go.swp
Normal file
Binary file not shown.
@@ -21,6 +21,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/internal/flags"
|
"github.com/fluxcd/flux2/internal/flags"
|
||||||
"github.com/fluxcd/flux2/internal/utils"
|
"github.com/fluxcd/flux2/internal/utils"
|
||||||
@@ -108,17 +109,19 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type helmReleaseFlags struct {
|
type helmReleaseFlags struct {
|
||||||
name string
|
name string
|
||||||
source flags.HelmChartSource
|
source flags.HelmChartSource
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
chart string
|
chart string
|
||||||
chartVersion string
|
chartVersion string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
createNamespace bool
|
createNamespace bool
|
||||||
valuesFiles []string
|
valuesFiles []string
|
||||||
valuesFrom flags.HelmReleaseValuesFrom
|
valuesFrom flags.HelmReleaseValuesFrom
|
||||||
saName string
|
saName string
|
||||||
crds flags.CRDsPolicy
|
crds flags.CRDsPolicy
|
||||||
|
reconcileStrategy string
|
||||||
|
chartInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
var helmReleaseArgs helmReleaseFlags
|
var helmReleaseArgs helmReleaseFlags
|
||||||
@@ -132,6 +135,8 @@ func init() {
|
|||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.targetNamespace, "target-namespace", "", "namespace to install this release, defaults to the HelmRelease namespace")
|
||||||
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
|
createHelmReleaseCmd.Flags().BoolVar(&helmReleaseArgs.createNamespace, "create-target-namespace", false, "create the target namespace if it does not exist")
|
||||||
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.saName, "service-account", "", "the name of the service account to impersonate when reconciling this HelmRelease")
|
||||||
|
createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.reconcileStrategy, "reconcile-strategy", "ChartVersion", "the reconcile strategy for helm chart created by the helm release(accepted values: Revision and ChartRevision)")
|
||||||
|
createHelmReleaseCmd.Flags().DurationVarP(&helmReleaseArgs.chartInterval, "chart-interval", "", 0, "the interval of which to check for new chart versions")
|
||||||
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values")
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description())
|
||||||
@@ -154,6 +159,11 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating HelmRelease")
|
logger.Generatef("generating HelmRelease")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !validateStrategy(helmReleaseArgs.reconcileStrategy) {
|
||||||
|
return fmt.Errorf("'%s' is an invalid reconcile strategy(valid: Revision, ChartVersion)",
|
||||||
|
helmReleaseArgs.reconcileStrategy)
|
||||||
|
}
|
||||||
|
|
||||||
helmRelease := helmv2.HelmRelease{
|
helmRelease := helmv2.HelmRelease{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@@ -177,12 +187,19 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
Name: helmReleaseArgs.source.Name,
|
Name: helmReleaseArgs.source.Name,
|
||||||
Namespace: helmReleaseArgs.source.Namespace,
|
Namespace: helmReleaseArgs.source.Namespace,
|
||||||
},
|
},
|
||||||
|
ReconcileStrategy: helmReleaseArgs.reconcileStrategy,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Suspend: false,
|
Suspend: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if helmReleaseArgs.chartInterval != 0 {
|
||||||
|
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
||||||
|
Duration: helmReleaseArgs.chartInterval,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if helmReleaseArgs.createNamespace {
|
if helmReleaseArgs.createNamespace {
|
||||||
if helmRelease.Spec.Install == nil {
|
if helmRelease.Spec.Install == nil {
|
||||||
helmRelease.Spec.Install = &helmv2.Install{}
|
helmRelease.Spec.Install = &helmv2.Install{}
|
||||||
@@ -316,3 +333,15 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client,
|
|||||||
return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil
|
return apimeta.IsStatusConditionTrue(helmRelease.Status.Conditions, meta.ReadyCondition), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateStrategy(input string) bool {
|
||||||
|
allowedStrategy := []string{"Revision", "ChartVersion"}
|
||||||
|
|
||||||
|
for _, strategy := range allowedStrategy {
|
||||||
|
if strategy == input {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user