diff --git a/api/krusty/legacy_order_test.go b/api/krusty/legacy_order_test.go index 64662da1e40..6315fbc6155 100644 --- a/api/krusty/legacy_order_test.go +++ b/api/krusty/legacy_order_test.go @@ -6,6 +6,7 @@ package krusty_test import ( "testing" + "sigs.k8s.io/kustomize/api/krusty" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) @@ -38,7 +39,7 @@ data: key: value `) opts := th.MakeDefaultOptions() - opts.DoLegacyResourceSort = true + opts.Reorder = krusty.ReorderOptionLegacy m := th.Run(".", opts) th.AssertActualEqualsExpected(m, ` apiVersion: v1 diff --git a/api/krusty/options.go b/api/krusty/options.go index 438f6c10290..d6dcdd72b0e 100644 --- a/api/krusty/options.go +++ b/api/krusty/options.go @@ -8,6 +8,14 @@ import ( "sigs.k8s.io/kustomize/api/types" ) +type ReorderOption string + +const ( + ReorderOptionLegacy ReorderOption = "legacy" + ReorderOptionNone ReorderOption = "none" + ReorderOptionUnspecified ReorderOption = "unspecified" +) + // Options holds high-level kustomize configuration options, // e.g. are plugins enabled, should the loader be restricted // to the kustomization root, etc. @@ -16,7 +24,15 @@ type Options struct { // per a particular sort order. When false, don't do the // sort, and instead respect the depth-first resource input // order as specified by the kustomization file(s). - DoLegacyResourceSort bool + + // Sort the resources before emitting them. Possible values: + // - "legacy": Use a fixed order that kustomize provides for backwards + // compatibility. + // - "none": Respect the depth-first resource input order as specified by the + // kustomization file. + // - "unspecified": The user didn't specify any preference. Kustomize will + // select the appropriate default. + Reorder ReorderOption // When true, a label // app.kubernetes.io/managed-by: kustomize- @@ -37,11 +53,11 @@ type Options struct { // MakeDefaultOptions returns a default instance of Options. func MakeDefaultOptions() *Options { return &Options{ - DoLegacyResourceSort: false, - AddManagedbyLabel: false, - LoadRestrictions: types.LoadRestrictionsRootOnly, - DoPrune: false, - PluginConfig: types.DisabledPluginConfig(), + Reorder: ReorderOptionNone, + AddManagedbyLabel: false, + LoadRestrictions: types.LoadRestrictionsRootOnly, + DoPrune: false, + PluginConfig: types.DisabledPluginConfig(), } } diff --git a/kustomize/commands/build/build.go b/kustomize/commands/build/build.go index a62b39f7bef..95d92cea625 100644 --- a/kustomize/commands/build/build.go +++ b/kustomize/commands/build/build.go @@ -104,6 +104,8 @@ func NewCmdBuild( AddFlagEnablePlugins(cmd.Flags()) AddFlagReorderOutput(cmd.Flags()) AddFlagEnableManagedbyLabel(cmd.Flags()) + cmd.Flags().MarkDeprecated(flagReorderOutputName, + "The flag `reorder` has been deprecated. Use the new 'sortOptions' field in kustomization.yaml instead.") cmd.Flags().MarkDeprecated(managedByFlag, "The flag `enable-managedby-label` has been deprecated. Use the `managedByLabel` option in the `buildMetadata` field instead.") AddFlagEnableHelm(cmd.Flags()) @@ -131,7 +133,7 @@ func Validate(args []string) error { // HonorKustomizeFlags feeds command line data to the krusty options. // Flags and such are held in private package variables. func HonorKustomizeFlags(kOpts *krusty.Options) *krusty.Options { - kOpts.DoLegacyResourceSort = getFlagReorderOutput() == legacy + kOpts.Reorder = getFlagReorderOutput() kOpts.LoadRestrictions = getFlagLoadRestrictorValue() if theFlags.enable.plugins { c := types.EnabledPluginConfig(types.BploUseStaticallyLinked)