Skip to content

Commit

Permalink
Deprecate Reorder Flag in Favour of Field
Browse files Browse the repository at this point in the history
  • Loading branch information
Cailyn Edwards committed Jan 9, 2023
1 parent 4456221 commit fe195a3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 55 deletions.
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")
}

0 comments on commit fe195a3

Please sign in to comment.