Deprecate 'bases:' field.

This commit is contained in:
Jeffrey Regan
2019-06-18 07:28:58 -07:00
parent 0dbe78149d
commit cc531af665
24 changed files with 156 additions and 152 deletions

View File

@@ -86,10 +86,10 @@ func (o *addBaseOptions) RunAddBase(fSys fs.FileSystem) error {
if !fSys.Exists(path) {
return errors.New(path + " does not exist")
}
if kustfile.StringInSlice(path, m.Bases) {
if kustfile.StringInSlice(path, m.Resources) {
return fmt.Errorf("base %s already in kustomization file", path)
}
m.Bases = append(m.Bases, path)
m.Resources = append(m.Resources, path)
}

View File

@@ -133,6 +133,7 @@ func TestPreserveComments(t *testing.T) {
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../namespaces
- pod.yaml
- service.yaml
# something you may want to keep
@@ -144,8 +145,6 @@ vars:
apiVersion: v1
kind: Service
name: my-service
bases:
- ../namespaces
# some descriptions for the patches
patchesStrategicMerge:
- service.yaml
@@ -176,10 +175,11 @@ func TestPreserveCommentsWithAdjust(t *testing.T) {
# shem qing some comments
# Some comments
# This is some comment we should preserve
# don't delete it
resources:
RESOURCES:
- ../namespaces
- pod.yaml
# See which field this comment goes into
- service.yaml
@@ -197,9 +197,6 @@ vars:
kind: Service
name: my-service
BASES:
- ../namespaces
# some descriptions for the patches
patchesStrategicMerge:
@@ -214,11 +211,12 @@ generatorOptions:
# shem qing some comments
# Some comments
# This is some comment we should preserve
# don't delete it
# See which field this comment goes into
resources:
- ../namespaces
- pod.yaml
- service.yaml
@@ -235,9 +233,6 @@ vars:
kind: Service
name: my-service
bases:
- ../namespaces
# some descriptions for the patches
patchesStrategicMerge:
@@ -263,7 +258,9 @@ generatorOptions:
}
bytes, _ := fSys.ReadFile(mf.path)
if !reflect.DeepEqual(expected, bytes) {
t.Fatal("written kustomization with comments is not the same as original one\n", string(bytes))
if string(expected) != string(bytes) {
t.Fatalf(
"expected =\n%s\n\nactual =\n%s\n",
string(expected), string(bytes))
}
}

View File

@@ -210,10 +210,6 @@ func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool {
func (kt *KustTarget) AccumulateTarget() (
ra *accumulator.ResAccumulator, err error) {
ra = accumulator.MakeEmptyAccumulator()
err = kt.accumulateResources(ra, kt.kustomization.Bases)
if err != nil {
return nil, errors.Wrap(err, "accumulating bases")
}
err = kt.accumulateResources(ra, kt.kustomization.Resources)
if err != nil {
return nil, errors.Wrap(err, "accumulating resources")

View File

@@ -97,7 +97,8 @@ type Kustomization struct {
//
// Resources specifies relative paths to files holding YAML representations
// of kubernetes API objects. URLs and globs not supported.
// of kubernetes API objects, or specifcations of other kustomizations
// via relative paths, absolute paths, or URLs.
Resources []string `json:"resources,omitempty" yaml:"resources,omitempty"`
// Crds specifies relative paths to Custom Resource Definition files.
@@ -106,9 +107,9 @@ type Kustomization struct {
// CRDs themselves are not modified.
Crds []string `json:"crds,omitempty" yaml:"crds,omitempty"`
// Bases are relative paths or github repository URLs specifying a
// directory containing a kustomization.yaml file.
// URL format: https://github.com/hashicorp/go-getter#url-format
// Deprecated.
// Anything that would have been specified here should
// be specified in the Resources field instead.
Bases []string `json:"bases,omitempty" yaml:"bases,omitempty"`
//
@@ -180,6 +181,10 @@ func (k *Kustomization) FixKustomizationPostUnmarshalling() {
k.SecretGenerator[i].EnvSource = ""
}
}
for _, b := range k.Bases {
k.Resources = append(k.Resources, b)
}
k.Bases = nil
}
func (k *Kustomization) EnforceFields() []string {