mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 10:20:35 +00:00
move load restrictions
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,6 @@ type Options struct {
|
||||
kustomizationPath string
|
||||
outputPath string
|
||||
outOrder reorderOutput
|
||||
pluginsEnabled bool
|
||||
}
|
||||
|
||||
// NewOptions creates a Options object
|
||||
@@ -73,9 +73,8 @@ func NewCmdBuild(out io.Writer) *cobra.Command {
|
||||
&o.outputPath,
|
||||
"output", "o", "",
|
||||
"If specified, write the build output to this path.")
|
||||
krusty.AddFlagLoadRestrictor(cmd.Flags())
|
||||
pgmconfig.AddFlagEnablePlugins(
|
||||
cmd.Flags(), &o.pluginsEnabled)
|
||||
addFlagLoadRestrictor(cmd.Flags())
|
||||
addFlagEnablePlugins(cmd.Flags())
|
||||
addFlagReorderOutput(cmd.Flags())
|
||||
cmd.AddCommand(NewCmdBuildPrune(out))
|
||||
return cmd
|
||||
@@ -95,7 +94,7 @@ func (o *Options) Validate(args []string) (err error) {
|
||||
} else {
|
||||
o.kustomizationPath = args[0]
|
||||
}
|
||||
err = krusty.ValidateFlagLoadRestrictor()
|
||||
err = validateFlagLoadRestrictor()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -105,9 +104,12 @@ func (o *Options) Validate(args []string) (err error) {
|
||||
|
||||
func (o *Options) makeOptions() *krusty.Options {
|
||||
opts := krusty.MakeDefaultOptions()
|
||||
opts.LoadRestrictions = krusty.GetFlagLoadRestrictorValue()
|
||||
opts.LoadRestrictions = getFlagLoadRestrictorValue()
|
||||
opts.DoLegacyResourceSort = o.outOrder == legacy
|
||||
opts.PluginConfig.Enabled = o.pluginsEnabled
|
||||
opts.PluginConfig.PluginRestrictions = types.PluginRestrictionsBuiltinsOnly
|
||||
if isFlagEnablePluginsSet() {
|
||||
opts.PluginConfig.PluginRestrictions = types.PluginRestrictionsNone
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
|
||||
29
kustomize/internal/commands/build/flagenableplugins.go
Normal file
29
kustomize/internal/commands/build/flagenableplugins.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const (
|
||||
flagEnablePluginsName = "enable_alpha_plugins"
|
||||
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
||||
See https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins/README.md
|
||||
`
|
||||
)
|
||||
|
||||
var (
|
||||
flagPluginsEnabledValue = false
|
||||
)
|
||||
|
||||
func addFlagEnablePlugins(set *pflag.FlagSet) {
|
||||
set.BoolVar(
|
||||
&flagPluginsEnabledValue, flagEnablePluginsName,
|
||||
false, flagEnablePluginsHelp)
|
||||
}
|
||||
|
||||
func isFlagEnablePluginsSet() bool {
|
||||
return flagPluginsEnabledValue
|
||||
}
|
||||
51
kustomize/internal/commands/build/flagloadrestrictor.go
Normal file
51
kustomize/internal/commands/build/flagloadrestrictor.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
const (
|
||||
flagName = "load_restrictor"
|
||||
)
|
||||
|
||||
var (
|
||||
flagLrValue = types.LoadRestrictionsRootOnly.String()
|
||||
flagLrHelp = "if set to '" + types.LoadRestrictionsNone.String() +
|
||||
"', local kustomizations may load files from outside their root. " +
|
||||
"This does, however, break the relocatability of the kustomization."
|
||||
)
|
||||
|
||||
func addFlagLoadRestrictor(set *pflag.FlagSet) {
|
||||
set.StringVar(
|
||||
&flagLrValue, flagName,
|
||||
types.LoadRestrictionsRootOnly.String(), flagLrHelp)
|
||||
}
|
||||
|
||||
func validateFlagLoadRestrictor() error {
|
||||
switch getFlagLoadRestrictorValue() {
|
||||
case types.LoadRestrictionsRootOnly, types.LoadRestrictionsNone:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
"illegal flag value --%s %s; legal values: %v",
|
||||
flagName, flagLrValue,
|
||||
[]string{types.LoadRestrictionsRootOnly.String(), types.LoadRestrictionsNone.String()})
|
||||
}
|
||||
}
|
||||
|
||||
func getFlagLoadRestrictorValue() types.LoadRestrictions {
|
||||
switch flagLrValue {
|
||||
case types.LoadRestrictionsRootOnly.String(), "rootOnly":
|
||||
return types.LoadRestrictionsRootOnly
|
||||
case types.LoadRestrictionsNone.String(), "none":
|
||||
return types.LoadRestrictionsNone
|
||||
default:
|
||||
return types.LoadRestrictionsUnknown
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user