Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Deprecate Reorder Flag in Favour of Field #4966

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions api/krusty/kustomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package krusty

import (
"fmt"
"log"

"sigs.k8s.io/kustomize/api/internal/builtins"
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
Expand Down Expand Up @@ -137,27 +136,13 @@ func (b *Kustomizer) applySortOrder(m resmap.ResMap, kt *target.KustTarget) erro

// Case 1: Sort order set in kustomization file.
if kt.Kustomization().SortOptions != nil {
// If set in CLI flag too, warn the user.
if b.options.Reorder != ReorderOptionUnspecified {
log.Println("Warning: Sorting order is set both in 'kustomization.yaml'" +
" ('sortOptions') and in a CLI flag ('--reorder'). Using the" +
" kustomization file over the CLI flag.")
}
pl := &builtins.SortOrderTransformerPlugin{
SortOptions: kt.Kustomization().SortOptions,
}
err := pl.Transform(m)
if err != nil {
return errors.Wrap(err)
}
} else if b.options.Reorder == ReorderOptionLegacy || b.options.Reorder == ReorderOptionUnspecified {
// Case 2: Sort order set in CLI flag only or not at all.
pl := &builtins.SortOrderTransformerPlugin{
SortOptions: &types.SortOptions{
Order: types.LegacySortOrder,
},
}
return errors.Wrap(pl.Transform(m))
}
return nil
}
6 changes: 1 addition & 5 deletions kustomize/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,12 @@ func Validate(args []string) error {
} else {
theArgs.kustomizationPath = args[0]
}
if err := validateFlagLoadRestrictor(); err != nil {
return err
}
return validateFlagReorderOutput()
return validateFlagLoadRestrictor()
}

// HonorKustomizeFlags feeds command line data to the krusty options.
// Flags and such are held in private package variables.
func HonorKustomizeFlags(kOpts *krusty.Options, flags *flag.FlagSet) *krusty.Options {
kOpts.Reorder = getFlagReorderOutput(flags)
kOpts.LoadRestrictions = getFlagLoadRestrictorValue()
if theFlags.enable.plugins {
c := types.EnabledPluginConfig(types.BploUseStaticallyLinked)
Expand Down
39 changes: 4 additions & 35 deletions kustomize/commands/build/reorderoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,16 @@
package build

import (
"fmt"

"github.com/spf13/pflag"
flag "github.com/spf13/pflag"
"sigs.k8s.io/kustomize/api/krusty"
)

const flagReorderOutputName = "reorder"

func AddFlagReorderOutput(set *pflag.FlagSet) {
set.StringVar(
&theFlags.reorderOutput, flagReorderOutputName,
string(krusty.ReorderOptionLegacy),
"Reorder the resources just before output. Use '"+string(krusty.ReorderOptionLegacy)+"' to"+
" apply a legacy reordering (Namespaces first, Webhooks last, etc)."+
" Use '"+string(krusty.ReorderOptionNone)+"' to suppress a final reordering.")
}

func validateFlagReorderOutput() error {
switch theFlags.reorderOutput {
case string(krusty.ReorderOptionNone), string(krusty.ReorderOptionLegacy):
return nil
default:
return fmt.Errorf(
"illegal flag value --%s %s; legal values: %v",
flagReorderOutputName, theFlags.reorderOutput,
[]string{string(krusty.ReorderOptionLegacy), string(krusty.ReorderOptionNone)})
}
}

func getFlagReorderOutput(flags *flag.FlagSet) krusty.ReorderOption {
isReorderSet := flags.Changed(flagReorderOutputName)
if !isReorderSet {
return krusty.ReorderOptionUnspecified
}
switch theFlags.reorderOutput {
case string(krusty.ReorderOptionNone):
return krusty.ReorderOptionNone
case string(krusty.ReorderOptionLegacy):
return krusty.ReorderOptionLegacy
default:
return krusty.ReorderOptionUnspecified
}
&theFlags.reorderOutput,
flagReorderOutputName,
string(krusty.ReorderOptionUnspecified),
"enable adding to the new 'sortOptions' field in kustomization.yaml instead")
}