mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
move load restrictions
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
"sigs.k8s.io/kustomize/api/target"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
// Kustomizer performs kustomizations. It's meant to behave
|
||||
@@ -55,7 +56,7 @@ func (b *Kustomizer) Run(path string) (resmap.ResMap, error) {
|
||||
kunstruct.NewKunstructuredFactoryImpl()),
|
||||
pf)
|
||||
lr := fLdr.RestrictionNone
|
||||
if b.options.LoadRestrictions == rootOnly {
|
||||
if b.options.LoadRestrictions == types.LoadRestrictionsRootOnly {
|
||||
lr = fLdr.RestrictionRootOnly
|
||||
}
|
||||
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.
|
||||
// See type definition.
|
||||
LoadRestrictions loadRestrictions
|
||||
LoadRestrictions types.LoadRestrictions
|
||||
|
||||
// Create an inventory object for pruning.
|
||||
DoPrune bool
|
||||
@@ -33,7 +33,7 @@ type Options struct {
|
||||
func MakeDefaultOptions() *Options {
|
||||
return &Options{
|
||||
DoLegacyResourceSort: true,
|
||||
LoadRestrictions: rootOnly,
|
||||
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
||||
DoPrune: false,
|
||||
PluginConfig: pgmconfig.DefaultPluginConfig(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user