mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
move load restrictions
This commit is contained in:
@@ -128,6 +128,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59 h1:QjA/9ArTfVTLfEhClDCG7SGrZkZixxWpwNCDiwJfh88=
|
||||||
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/api/target"
|
"sigs.k8s.io/kustomize/api/target"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Kustomizer performs kustomizations. It's meant to behave
|
// Kustomizer performs kustomizations. It's meant to behave
|
||||||
@@ -55,7 +56,7 @@ func (b *Kustomizer) Run(path string) (resmap.ResMap, error) {
|
|||||||
kunstruct.NewKunstructuredFactoryImpl()),
|
kunstruct.NewKunstructuredFactoryImpl()),
|
||||||
pf)
|
pf)
|
||||||
lr := fLdr.RestrictionNone
|
lr := fLdr.RestrictionNone
|
||||||
if b.options.LoadRestrictions == rootOnly {
|
if b.options.LoadRestrictions == types.LoadRestrictionsRootOnly {
|
||||||
lr = fLdr.RestrictionRootOnly
|
lr = fLdr.RestrictionRootOnly
|
||||||
}
|
}
|
||||||
ldr, err := fLdr.NewLoader(lr, path, b.fSys)
|
ldr, err := fLdr.NewLoader(lr, path, b.fSys)
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package krusty
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
|
||||||
|
|
||||||
//go:generate stringer -type=loadRestrictions
|
|
||||||
type loadRestrictions int
|
|
||||||
|
|
||||||
const (
|
|
||||||
unknown loadRestrictions = iota
|
|
||||||
|
|
||||||
// With this restriction, the files referenced by a
|
|
||||||
// kustomization file must be in or under the directory
|
|
||||||
// holding the kustomization file itself.
|
|
||||||
rootOnly
|
|
||||||
|
|
||||||
// The kustomization file may specify absolute or
|
|
||||||
// relative paths to patch or resources files outside
|
|
||||||
// its own tree.
|
|
||||||
none
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
flagName = "load_restrictor"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
flagValue = rootOnly.String()
|
|
||||||
flagHelp = "if set to '" + none.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(
|
|
||||||
&flagValue, flagName,
|
|
||||||
rootOnly.String(), flagHelp)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ValidateFlagLoadRestrictor() error {
|
|
||||||
switch flagValue {
|
|
||||||
case rootOnly.String():
|
|
||||||
return nil
|
|
||||||
case none.String():
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf(
|
|
||||||
"illegal flag value --%s %s; legal values: %v",
|
|
||||||
flagName, flagValue,
|
|
||||||
[]string{rootOnly.String(), none.String()})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetFlagLoadRestrictorValue() loadRestrictions {
|
|
||||||
switch flagValue {
|
|
||||||
case rootOnly.String():
|
|
||||||
return rootOnly
|
|
||||||
case none.String():
|
|
||||||
return none
|
|
||||||
default:
|
|
||||||
return unknown
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// Code generated by "stringer -type=loadRestrictions"; DO NOT EDIT.
|
|
||||||
|
|
||||||
package krusty
|
|
||||||
|
|
||||||
import "strconv"
|
|
||||||
|
|
||||||
func _() {
|
|
||||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
|
||||||
// Re-run the stringer command to generate them again.
|
|
||||||
var x [1]struct{}
|
|
||||||
_ = x[unknown-0]
|
|
||||||
_ = x[rootOnly-1]
|
|
||||||
_ = x[none-2]
|
|
||||||
}
|
|
||||||
|
|
||||||
const _loadRestrictions_name = "unknownrootOnlynone"
|
|
||||||
|
|
||||||
var _loadRestrictions_index = [...]uint8{0, 7, 15, 19}
|
|
||||||
|
|
||||||
func (i loadRestrictions) String() string {
|
|
||||||
if i < 0 || i >= loadRestrictions(len(_loadRestrictions_index)-1) {
|
|
||||||
return "loadRestrictions(" + strconv.FormatInt(int64(i), 10) + ")"
|
|
||||||
}
|
|
||||||
return _loadRestrictions_name[_loadRestrictions_index[i]:_loadRestrictions_index[i+1]]
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ type Options struct {
|
|||||||
|
|
||||||
// Restrictions on what can be loaded from the file system.
|
// Restrictions on what can be loaded from the file system.
|
||||||
// See type definition.
|
// See type definition.
|
||||||
LoadRestrictions loadRestrictions
|
LoadRestrictions types.LoadRestrictions
|
||||||
|
|
||||||
// Create an inventory object for pruning.
|
// Create an inventory object for pruning.
|
||||||
DoPrune bool
|
DoPrune bool
|
||||||
@@ -33,7 +33,7 @@ type Options struct {
|
|||||||
func MakeDefaultOptions() *Options {
|
func MakeDefaultOptions() *Options {
|
||||||
return &Options{
|
return &Options{
|
||||||
DoLegacyResourceSort: true,
|
DoLegacyResourceSort: true,
|
||||||
LoadRestrictions: rootOnly,
|
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
||||||
DoPrune: false,
|
DoPrune: false,
|
||||||
PluginConfig: pgmconfig.DefaultPluginConfig(),
|
PluginConfig: pgmconfig.DefaultPluginConfig(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,10 @@
|
|||||||
package pgmconfig
|
package pgmconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,45 +29,21 @@ const (
|
|||||||
|
|
||||||
// Name of directory housing all plugins.
|
// Name of directory housing all plugins.
|
||||||
PluginRoot = "plugin"
|
PluginRoot = "plugin"
|
||||||
|
|
||||||
flagEnablePluginsName = "enable_alpha_plugins"
|
|
||||||
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
|
||||||
See https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins/README.md
|
|
||||||
`
|
|
||||||
flagErrorFmt = `
|
|
||||||
unable to load external plugin %s because plugins disabled
|
|
||||||
specify the flag
|
|
||||||
--%s
|
|
||||||
to %s`
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ActivePluginConfig() *types.PluginConfig {
|
func ActivePluginConfig() *types.PluginConfig {
|
||||||
pc := DefaultPluginConfig()
|
pc := DefaultPluginConfig()
|
||||||
pc.Enabled = true
|
pc.PluginRestrictions = types.PluginRestrictionsNone
|
||||||
return pc
|
return pc
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultPluginConfig() *types.PluginConfig {
|
func DefaultPluginConfig() *types.PluginConfig {
|
||||||
return &types.PluginConfig{
|
return &types.PluginConfig{
|
||||||
Enabled: false,
|
PluginRestrictions: types.PluginRestrictionsBuiltinsOnly,
|
||||||
DirectoryPath: filepath.Join(configRoot(), PluginRoot),
|
DirectoryPath: filepath.Join(configRoot(), PluginRoot),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NotEnabledErr(name string) error {
|
|
||||||
return fmt.Errorf(
|
|
||||||
flagErrorFmt,
|
|
||||||
name,
|
|
||||||
flagEnablePluginsName,
|
|
||||||
flagEnablePluginsHelp)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddFlagEnablePlugins(set *pflag.FlagSet, v *bool) {
|
|
||||||
set.BoolVar(
|
|
||||||
v, flagEnablePluginsName,
|
|
||||||
false, flagEnablePluginsHelp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use https://github.com/kirsle/configdir instead?
|
// Use https://github.com/kirsle/configdir instead?
|
||||||
func configRoot() string {
|
func configRoot() string {
|
||||||
dir := os.Getenv(XdgConfigHomeEnv)
|
dir := os.Getenv(XdgConfigHomeEnv)
|
||||||
|
|||||||
@@ -114,10 +114,10 @@ func (l *Loader) loadAndConfigurePlugin(
|
|||||||
// function (see "pluginator"). Being able to do this
|
// function (see "pluginator"). Being able to do this
|
||||||
// is what makes a plugin "builtin".
|
// is what makes a plugin "builtin".
|
||||||
c, err = l.makeBuiltinPlugin(res.GetGvk())
|
c, err = l.makeBuiltinPlugin(res.GetGvk())
|
||||||
} else if l.pc.Enabled {
|
} else if l.pc.PluginRestrictions == types.PluginRestrictionsNone {
|
||||||
c, err = l.loadPlugin(res.OrgId())
|
c, err = l.loadPlugin(res.OrgId())
|
||||||
} else {
|
} else {
|
||||||
err = pgmconfig.NotEnabledErr(res.OrgId().Kind)
|
err = types.NewErrOnlyBuiltinPluginsAllowed(res.OrgId().Kind)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
package target_test
|
package target_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeDeployment(th *kusttest_test.KustTestHarness, path string) {
|
func writeDeployment(th *kusttest_test.KustTestHarness, path string) {
|
||||||
@@ -112,7 +112,7 @@ transformers:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error")
|
t.Fatalf("expected error")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "unable to load external plugin StringPrefixer") {
|
if !types.IsErrOnlyBuiltinPluginsAllowed(err) {
|
||||||
t.Fatalf("unexpected err: %v", err)
|
t.Fatalf("unexpected err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
api/types/erronlybuiltinpluginsallowed.go
Normal file
32
api/types/erronlybuiltinpluginsallowed.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type errOnlyBuiltinPluginsAllowed struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *errOnlyBuiltinPluginsAllowed) Error() string {
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"external plugins disabled; unable to load external plugin '%s'",
|
||||||
|
e.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewErrOnlyBuiltinPluginsAllowed(n string) *errOnlyBuiltinPluginsAllowed {
|
||||||
|
return &errOnlyBuiltinPluginsAllowed{name: n}
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsErrOnlyBuiltinPluginsAllowed(err error) bool {
|
||||||
|
_, ok := err.(*errOnlyBuiltinPluginsAllowed)
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
_, ok = errors.Cause(err).(*errOnlyBuiltinPluginsAllowed)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
24
api/types/loadrestrictions.go
Normal file
24
api/types/loadrestrictions.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
// Restrictions on what things can be referred to
|
||||||
|
// in a kustomization file.
|
||||||
|
//
|
||||||
|
//go:generate stringer -type=LoadRestrictions
|
||||||
|
type LoadRestrictions int
|
||||||
|
|
||||||
|
const (
|
||||||
|
LoadRestrictionsUnknown LoadRestrictions = iota
|
||||||
|
|
||||||
|
// Files referenced by a kustomization file must be in
|
||||||
|
// or under the directory holding the kustomization
|
||||||
|
// file itself.
|
||||||
|
LoadRestrictionsRootOnly
|
||||||
|
|
||||||
|
// The kustomization file may specify absolute or
|
||||||
|
// relative paths to patch or resources files outside
|
||||||
|
// its own tree.
|
||||||
|
LoadRestrictionsNone
|
||||||
|
)
|
||||||
25
api/types/loadrestrictions_string.go
Normal file
25
api/types/loadrestrictions_string.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Code generated by "stringer -type=LoadRestrictions"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[LoadRestrictionsUnknown-0]
|
||||||
|
_ = x[LoadRestrictionsRootOnly-1]
|
||||||
|
_ = x[LoadRestrictionsNone-2]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _LoadRestrictions_name = "LoadRestrictionsUnknownLoadRestrictionsRootOnlyLoadRestrictionsNone"
|
||||||
|
|
||||||
|
var _LoadRestrictions_index = [...]uint8{0, 23, 47, 67}
|
||||||
|
|
||||||
|
func (i LoadRestrictions) String() string {
|
||||||
|
if i < 0 || i >= LoadRestrictions(len(_LoadRestrictions_index)-1) {
|
||||||
|
return "LoadRestrictions(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _LoadRestrictions_name[_LoadRestrictions_index[i]:_LoadRestrictions_index[i+1]]
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ type PluginConfig struct {
|
|||||||
// further categorizing plugins.
|
// further categorizing plugins.
|
||||||
DirectoryPath string
|
DirectoryPath string
|
||||||
|
|
||||||
// Enabled is true if plugins are enabled.
|
// PluginRestrictions defines the plugin restriction state.
|
||||||
Enabled bool
|
// See type for more information.
|
||||||
|
PluginRestrictions PluginRestrictions
|
||||||
}
|
}
|
||||||
|
|||||||
28
api/types/pluginrestrictions.go
Normal file
28
api/types/pluginrestrictions.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
// Some plugin classes
|
||||||
|
// - builtin: plugins defined in the kustomize repo.
|
||||||
|
// May be freely used and re-configured.
|
||||||
|
// - local: plugins that aren't builtin but are
|
||||||
|
// locally defined (presumably by the user), meaning
|
||||||
|
// the kustomization refers to them via a relative
|
||||||
|
// file path, not a URL.
|
||||||
|
// - remote: require a build-time download to obtain.
|
||||||
|
// Unadvised, unless one controls the
|
||||||
|
// serving site.
|
||||||
|
//
|
||||||
|
//go:generate stringer -type=PluginRestrictions
|
||||||
|
type PluginRestrictions int
|
||||||
|
|
||||||
|
const (
|
||||||
|
PluginRestrictionsUnknown PluginRestrictions = iota
|
||||||
|
|
||||||
|
// Non-builtin plugins completely disabled.
|
||||||
|
PluginRestrictionsBuiltinsOnly
|
||||||
|
|
||||||
|
// No restrictions, do whatever you want.
|
||||||
|
PluginRestrictionsNone
|
||||||
|
)
|
||||||
25
api/types/pluginrestrictions_string.go
Normal file
25
api/types/pluginrestrictions_string.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Code generated by "stringer -type=PluginRestrictions"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[PluginRestrictionsUnknown-0]
|
||||||
|
_ = x[PluginRestrictionsBuiltinsOnly-1]
|
||||||
|
_ = x[PluginRestrictionsNone-2]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _PluginRestrictions_name = "PluginRestrictionsUnknownPluginRestrictionsBuiltinsOnlyPluginRestrictionsNone"
|
||||||
|
|
||||||
|
var _PluginRestrictions_index = [...]uint8{0, 25, 55, 77}
|
||||||
|
|
||||||
|
func (i PluginRestrictions) String() string {
|
||||||
|
if i < 0 || i >= PluginRestrictions(len(_PluginRestrictions_index)-1) {
|
||||||
|
return "PluginRestrictions(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _PluginRestrictions_name[_PluginRestrictions_index[i]:_PluginRestrictions_index[i+1]]
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/pgmconfig"
|
"sigs.k8s.io/kustomize/api/pgmconfig"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +24,6 @@ type Options struct {
|
|||||||
kustomizationPath string
|
kustomizationPath string
|
||||||
outputPath string
|
outputPath string
|
||||||
outOrder reorderOutput
|
outOrder reorderOutput
|
||||||
pluginsEnabled bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOptions creates a Options object
|
// NewOptions creates a Options object
|
||||||
@@ -73,9 +73,8 @@ func NewCmdBuild(out io.Writer) *cobra.Command {
|
|||||||
&o.outputPath,
|
&o.outputPath,
|
||||||
"output", "o", "",
|
"output", "o", "",
|
||||||
"If specified, write the build output to this path.")
|
"If specified, write the build output to this path.")
|
||||||
krusty.AddFlagLoadRestrictor(cmd.Flags())
|
addFlagLoadRestrictor(cmd.Flags())
|
||||||
pgmconfig.AddFlagEnablePlugins(
|
addFlagEnablePlugins(cmd.Flags())
|
||||||
cmd.Flags(), &o.pluginsEnabled)
|
|
||||||
addFlagReorderOutput(cmd.Flags())
|
addFlagReorderOutput(cmd.Flags())
|
||||||
cmd.AddCommand(NewCmdBuildPrune(out))
|
cmd.AddCommand(NewCmdBuildPrune(out))
|
||||||
return cmd
|
return cmd
|
||||||
@@ -95,7 +94,7 @@ func (o *Options) Validate(args []string) (err error) {
|
|||||||
} else {
|
} else {
|
||||||
o.kustomizationPath = args[0]
|
o.kustomizationPath = args[0]
|
||||||
}
|
}
|
||||||
err = krusty.ValidateFlagLoadRestrictor()
|
err = validateFlagLoadRestrictor()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,9 +104,12 @@ func (o *Options) Validate(args []string) (err error) {
|
|||||||
|
|
||||||
func (o *Options) makeOptions() *krusty.Options {
|
func (o *Options) makeOptions() *krusty.Options {
|
||||||
opts := krusty.MakeDefaultOptions()
|
opts := krusty.MakeDefaultOptions()
|
||||||
opts.LoadRestrictions = krusty.GetFlagLoadRestrictorValue()
|
opts.LoadRestrictions = getFlagLoadRestrictorValue()
|
||||||
opts.DoLegacyResourceSort = o.outOrder == legacy
|
opts.DoLegacyResourceSort = o.outOrder == legacy
|
||||||
opts.PluginConfig.Enabled = o.pluginsEnabled
|
opts.PluginConfig.PluginRestrictions = types.PluginRestrictionsBuiltinsOnly
|
||||||
|
if isFlagEnablePluginsSet() {
|
||||||
|
opts.PluginConfig.PluginRestrictions = types.PluginRestrictionsNone
|
||||||
|
}
|
||||||
return opts
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,10 @@ function removeBin {
|
|||||||
/bin/rm -f $d
|
/bin/rm -f $d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: go install golang.org/x/tools/cmd/stringer
|
||||||
|
# TODO: kubeval?
|
||||||
|
# TODO: helm? no. except then we should not requirekubeval either,
|
||||||
|
# since they're both only used in demo (non-builtin) plugins.
|
||||||
function installTools {
|
function installTools {
|
||||||
# TODO(2019/Oct/19): After the API is in place, and
|
# TODO(2019/Oct/19): After the API is in place, and
|
||||||
# there's a new pluginator compiled against that API,
|
# there's a new pluginator compiled against that API,
|
||||||
|
|||||||
Reference in New Issue
Block a user