feat: mark deprecated args and cmd for v1 (#628)

* feat: mark deprecated args and cmd for v1

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2023-01-14 23:43:05 +08:00 committed by GitHub
parent db5c2a52d6
commit 8d96bbb0e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 65 additions and 25 deletions

View File

@ -42,8 +42,8 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
f.BoolVar(&applyOptions.DetailedExitcode, "detailed-exitcode", false, "return a non-zero exit code 2 instead of 0 when there were changes detected AND the changes are synced successfully")
f.StringVar(&globalCfg.GlobalOptions.Args, "args", "", "pass args to helm exec")
if !runtime.V1Mode {
// TODO: Remove this function once Helmfile v0.x
f.BoolVar(&applyOptions.RetainValuesFiles, "retain-values-files", false, "DEPRECATED: Use skip-cleanup instead")
// mark retain-values-files as deprecated, but keep it for backward compatibility, will be removed in the future
_ = f.MarkDeprecated("retain-values-files", "Use skip-cleanup instead")
}

View File

@ -1,3 +1,4 @@
// TODO: Remove this function once Helmfile v0.x
package cmd
import (

View File

@ -1,3 +1,4 @@
// TODO: Remove this function once Helmfile v0.x
package cmd
import (

View File

@ -103,6 +103,7 @@ func NewRootCmd(globalConfig *config.GlobalOptions) (*cobra.Command, error) {
),
)
// TODO: Remove this function once Helmfile v0.x
if !runtime.V1Mode {
cmd.AddCommand(
NewChartsCmd(globalImpl),

View File

@ -132,6 +132,7 @@ func (a *App) Repos(c ReposConfigProvider) error {
}, c.IncludeTransitiveNeeds(), SetFilter(true))
}
// TODO: Remove this function once Helmfile v0.x
func (a *App) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) error {
return a.ForEachState(func(run *Run) (_ bool, errs []error) {
err := run.withPreparedCharts("charts", state.ChartPrepareOptions{
@ -457,6 +458,7 @@ func (a *App) Status(c StatusesConfigProvider) error {
}, false, SetFilter(true))
}
// TODO: Remove this function once Helmfile v0.x
func (a *App) Delete(c DeleteConfigProvider) error {
return a.ForEachState(func(run *Run) (ok bool, errs []error) {
err := run.withPreparedCharts("delete", state.ChartPrepareOptions{
@ -1166,6 +1168,8 @@ func (a *App) findDesiredStateFiles(specifiedPath string, opts LoadOpts) ([]stri
var defaultFile string
if a.fs.FileExistsAt(DefaultHelmfile) {
defaultFile = DefaultHelmfile
// TODO: Remove this function once Helmfile v0.x
} else if a.fs.FileExistsAt(DeprecatedHelmfile) {
log.Printf(
"warn: %s is being loaded: %s is deprecated in favor of %s. See https://github.com/roboll/helmfile/issues/25 for more information",

View File

@ -2310,9 +2310,12 @@ func (c configImpl) PostRenderer() string {
}
type applyConfig struct {
args string
values []string
retainValuesFiles bool
args string
values []string
// TODO: Remove this function once Helmfile v0.x
retainValuesFiles bool
set []string
validate bool
skipCleanup bool
@ -2450,6 +2453,7 @@ func (a applyConfig) Logger() *zap.SugaredLogger {
return a.logger
}
// TODO: Remove this function once Helmfile v0.x
func (a applyConfig) RetainValuesFiles() bool {
return a.retainValuesFiles
}

View File

@ -19,6 +19,7 @@ type ConfigProvider interface {
loggingConfig
}
// TODO: Remove this function once Helmfile v0.x
type DeprecatedChartsConfigProvider interface {
Values() []string
@ -66,7 +67,9 @@ type ApplyConfigProvider interface {
Context() int
DiffOutput() string
// TODO: Remove this function once Helmfile v0.x
RetainValuesFiles() bool
Validate() bool
SkipCleanup() bool
SkipDiffOnInstall() bool
@ -133,6 +136,7 @@ type DiffConfigProvider interface {
valuesControlMode
}
// TODO: Remove this function once Helmfile v0.x
type DeleteConfigProvider interface {
Args() string

View File

@ -8,8 +8,10 @@ import (
)
const (
DefaultHelmfile = "helmfile.yaml"
DeprecatedHelmfile = "charts.yaml"
DefaultHelmfile = "helmfile.yaml"
// TODO: Remove this function once Helmfile v0.x
DeprecatedHelmfile = "charts.yaml"
DefaultHelmfileDirectory = "helmfile.d"
ExperimentalSelectorExplicit = "explicit-selector-inheritance" // value to remove default selector inheritance to sub-helmfiles and use the explicit one
)

View File

@ -112,6 +112,7 @@ func (r *Run) Repos(c ReposConfigProvider) error {
return r.ctx.SyncReposOnce(r.state, r.helm)
}
// TODO: Remove this function once Helmfile v0.x
func (r *Run) DeprecatedSyncCharts(c DeprecatedChartsConfigProvider) []error {
st := r.state
helm := r.helm

View File

@ -16,8 +16,11 @@ type ApplyOptions struct {
Output string
// DetailedExitcode is true if the exit code should be 2 instead of 0 if there were changes detected and the changes were synced successfully
DetailedExitcode bool
// TODO: Remove this function once Helmfile v0.x
// DEPRECATED: Use skip-cleanup instead
RetainValuesFiles bool
// SkipCleanup is true if the cleanup of temporary values files should be skipped
SkipCleanup bool
// SkipCRDs is true if the CRDs should be skipped
@ -113,6 +116,7 @@ func (a *ApplyImpl) IncludeTransitiveNeeds() bool {
return a.ApplyOptions.IncludeTransitiveNeeds
}
// TODO: Remove this function once Helmfile v0.x
// RetainValuesFiles returns the retain values files.
func (a *ApplyImpl) RetainValuesFiles() bool {
return a.ApplyOptions.RetainValuesFiles

View File

@ -1,3 +1,4 @@
// TODO: Remove this function once Helmfile v0.x
package config
// ChartsOptions is the options for the build command

View File

@ -1,3 +1,4 @@
// TODO: Remove this function once Helmfile v0.x
package config
// DeleteOptions is the options for the build command

View File

@ -108,6 +108,7 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState,
}
}
// TODO: Remove this function once Helmfile v0.x
if len(state.DeprecatedReleases) > 0 {
if len(state.Releases) > 0 {
return nil, fmt.Errorf("failed to parse %s: you can't specify both `charts` and `releases` sections", file)
@ -116,6 +117,7 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState,
state.DeprecatedReleases = []ReleaseSpec{}
}
// TODO: Remove this function once Helmfile v0.x
if state.DeprecatedContext != "" && state.HelmDefaults.KubeContext == "" {
state.HelmDefaults.KubeContext = state.DeprecatedContext
}

View File

@ -279,6 +279,7 @@ func TestReadFromYaml_StrictUnmarshalling(t *testing.T) {
}
}
// TODO: Remove this function once Helmfile v0.x
func TestReadFromYaml_DeprecatedReleaseReferences(t *testing.T) {
yamlFile := "example/path/to/yaml/file"
yamlContent := []byte(`charts:

View File

@ -49,11 +49,14 @@ type ReleaseSetSpec struct {
Environments map[string]EnvironmentSpec `yaml:"environments,omitempty"`
Bases []string `yaml:"bases,omitempty"`
HelmDefaults HelmSpec `yaml:"helmDefaults,omitempty"`
Helmfiles []SubHelmfileSpec `yaml:"helmfiles,omitempty"`
DeprecatedContext string `yaml:"context,omitempty"`
DeprecatedReleases []ReleaseSpec `yaml:"charts,omitempty"`
Bases []string `yaml:"bases,omitempty"`
HelmDefaults HelmSpec `yaml:"helmDefaults,omitempty"`
Helmfiles []SubHelmfileSpec `yaml:"helmfiles,omitempty"`
// TODO: Remove this function once Helmfile v0.x
DeprecatedContext string `yaml:"context,omitempty"`
DeprecatedReleases []ReleaseSpec `yaml:"charts,omitempty"`
OverrideKubeContext string `yaml:"kubeContext,omitempty"`
OverrideNamespace string `yaml:"namespace,omitempty"`
OverrideChart string `yaml:"chart,omitempty"`

View File

@ -54,12 +54,15 @@ func TestLabelParsing(t *testing.T) {
func TestHelmState_applyDefaultsTo(t *testing.T) {
type fields struct {
BaseChartPath string
Context string
BaseChartPath string
Context string
// TODO: Remove this function once Helmfile v0.x
DeprecatedReleases []ReleaseSpec
Namespace string
Repositories []RepositorySpec
Releases []ReleaseSpec
Namespace string
Repositories []RepositorySpec
Releases []ReleaseSpec
}
type args struct {
spec ReleaseSpec
@ -82,11 +85,14 @@ func TestHelmState_applyDefaultsTo(t *testing.T) {
specWithNamespaceFromFields.Namespace = "test-namespace-field"
fieldsWithNamespace := fields{
BaseChartPath: ".",
Context: "test_context",
BaseChartPath: ".",
Context: "test_context",
// TODO: Remove this function once Helmfile v0.x
DeprecatedReleases: nil,
Namespace: specWithNamespaceFromFields.Namespace,
Repositories: nil,
Namespace: specWithNamespaceFromFields.Namespace,
Repositories: nil,
Releases: []ReleaseSpec{
specWithNamespace,
},
@ -140,11 +146,13 @@ func TestHelmState_applyDefaultsTo(t *testing.T) {
state := &HelmState{
basePath: tt.fields.BaseChartPath,
ReleaseSetSpec: ReleaseSetSpec{
// TODO: Remove this function once Helmfile v0.x
DeprecatedContext: tt.fields.Context,
DeprecatedReleases: tt.fields.DeprecatedReleases,
OverrideNamespace: tt.fields.Namespace,
Repositories: tt.fields.Repositories,
Releases: tt.fields.Releases,
OverrideNamespace: tt.fields.Namespace,
Repositories: tt.fields.Repositories,
Releases: tt.fields.Releases,
},
}
if state.ApplyOverrides(&tt.args.spec); !reflect.DeepEqual(tt.args.spec, tt.want) {
@ -768,9 +776,11 @@ func TestHelmState_flagsForUpgrade(t *testing.T) {
state := &HelmState{
basePath: "./",
ReleaseSetSpec: ReleaseSetSpec{
// TODO: Remove this function once Helmfile v0.x
DeprecatedContext: "default",
Releases: []ReleaseSpec{*tt.release},
HelmDefaults: tt.defaults,
Releases: []ReleaseSpec{*tt.release},
HelmDefaults: tt.defaults,
},
valsRuntime: valsRuntime,
}