Skip to content

Commit

Permalink
build: Add option to denote if the reorder flag was set by the user
Browse files Browse the repository at this point in the history
We want to take different actions if the reorder flag was set by the
user or filled by the default value. Thus, we propagate this information
from build to the krusty options.

Signed-off-by: Yannis Zarkadas <[email protected]>
  • Loading branch information
yanniszark committed Oct 17, 2022
1 parent 65c4857 commit 24e0475
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 11 additions & 5 deletions api/krusty/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type Options struct {
// order as specified by the kustomization file(s).
DoLegacyResourceSort bool

// When true, the user has explicitly defined the sort mode as a CLI flag
// (i.e. the value is not simply the default). Used to detect collisions
// between the CLI flag and the sortOrder option in the kustomization.
SortModeSetExplicitly bool

// When true, a label
// app.kubernetes.io/managed-by: kustomize-<version>
// is added to all the resources in the build out.
Expand All @@ -37,11 +42,12 @@ 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(),
DoLegacyResourceSort: false,
SortModeSetExplicitly: false,
AddManagedbyLabel: false,
LoadRestrictions: types.LoadRestrictionsRootOnly,
DoPrune: false,
PluginConfig: types.DisabledPluginConfig(),
}
}

Expand Down
11 changes: 7 additions & 4 deletions kustomize/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ var theFlags struct {
managedByLabel bool
helm bool
}
helmCommand string
loadRestrictor string
reorderOutput string
fnOptions types.FnPluginLoadingOptions
helmCommand string
loadRestrictor string
reorderOutput string
reorderOutputSetExplicitly bool
fnOptions types.FnPluginLoadingOptions
}

type Help struct {
Expand Down Expand Up @@ -74,6 +75,7 @@ func NewCmdBuild(
if err := Validate(args); err != nil {
return err
}
theFlags.reorderOutputSetExplicitly = cmd.Flags().Changed(flagReorderOutputName)
k := krusty.MakeKustomizer(
HonorKustomizeFlags(krusty.MakeDefaultOptions()),
)
Expand Down Expand Up @@ -142,5 +144,6 @@ func HonorKustomizeFlags(kOpts *krusty.Options) *krusty.Options {
}
kOpts.PluginConfig.HelmConfig.Command = theFlags.helmCommand
kOpts.AddManagedbyLabel = isManagedByLabelEnabled()
kOpts.SortModeSetExplicitly = theFlags.reorderOutputSetExplicitly
return kOpts
}

0 comments on commit 24e0475

Please sign in to comment.