mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Enforce relocatabile kustomizations.
This commit is contained in:
@@ -94,7 +94,7 @@ func TestConstructConfigMap(t *testing.T) {
|
|||||||
input: types.ConfigMapArgs{
|
input: types.ConfigMapArgs{
|
||||||
Name: "envConfigMap",
|
Name: "envConfigMap",
|
||||||
DataSources: types.DataSources{
|
DataSources: types.DataSources{
|
||||||
EnvSource: "/configmap/app.env",
|
EnvSource: "configmap/app.env",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: nil,
|
options: nil,
|
||||||
@@ -105,7 +105,7 @@ func TestConstructConfigMap(t *testing.T) {
|
|||||||
input: types.ConfigMapArgs{
|
input: types.ConfigMapArgs{
|
||||||
Name: "fileConfigMap",
|
Name: "fileConfigMap",
|
||||||
DataSources: types.DataSources{
|
DataSources: types.DataSources{
|
||||||
FileSources: []string{"/configmap/app-init.ini"},
|
FileSources: []string{"configmap/app-init.ini"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: nil,
|
options: nil,
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enforceRelocatable = false
|
// TODO: 2018/Nov/20 remove this before next release.
|
||||||
|
// Leave only the true path. Retaining only for
|
||||||
|
// quick revert.
|
||||||
|
const enforceRelocatable = true
|
||||||
|
|
||||||
// fileLoader loads files, returning an array of bytes.
|
// fileLoader loads files, returning an array of bytes.
|
||||||
// It also enforces two kustomization requirements:
|
// It also enforces two kustomization requirements:
|
||||||
|
|||||||
@@ -31,19 +31,19 @@ type testData struct {
|
|||||||
|
|
||||||
var testCases = []testData{
|
var testCases = []testData{
|
||||||
{
|
{
|
||||||
path: "/foo/project/fileA.yaml",
|
path: "foo/project/fileA.yaml",
|
||||||
expectedContent: "fileA content",
|
expectedContent: "fileA content",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/foo/project/subdir1/fileB.yaml",
|
path: "foo/project/subdir1/fileB.yaml",
|
||||||
expectedContent: "fileB content",
|
expectedContent: "fileB content",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/foo/project/subdir2/fileC.yaml",
|
path: "foo/project/subdir2/fileC.yaml",
|
||||||
expectedContent: "fileC content",
|
expectedContent: "fileC content",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/foo/project2/fileD.yaml",
|
path: "foo/project/fileD.yaml",
|
||||||
expectedContent: "fileD content",
|
expectedContent: "fileD content",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ var testCases = []testData{
|
|||||||
func MakeFakeFs(td []testData) fs.FileSystem {
|
func MakeFakeFs(td []testData) fs.FileSystem {
|
||||||
fSys := fs.MakeFakeFS()
|
fSys := fs.MakeFakeFS()
|
||||||
for _, x := range td {
|
for _, x := range td {
|
||||||
fSys.WriteFile(x.path, []byte(x.expectedContent))
|
fSys.WriteFile("/"+x.path, []byte(x.expectedContent))
|
||||||
}
|
}
|
||||||
return fSys
|
return fSys
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ func TestLoaderLoad(t *testing.T) {
|
|||||||
t.Fatalf("in load expected %s, but got %s", x.expectedContent, b)
|
t.Fatalf("in load expected %s, but got %s", x.expectedContent, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l2, err := l1.New("/foo/project")
|
l2, err := l1.New("foo/project")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v\n", err)
|
t.Fatalf("unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ func TestLoaderLoad(t *testing.T) {
|
|||||||
t.Fatalf("incorrect root: %s\n", l2.Root())
|
t.Fatalf("incorrect root: %s\n", l2.Root())
|
||||||
}
|
}
|
||||||
for _, x := range testCases {
|
for _, x := range testCases {
|
||||||
b, err := l2.Load(strings.TrimPrefix(x.path, "/foo/project/"))
|
b, err := l2.Load(strings.TrimPrefix(x.path, "foo/project/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected load error %v", err)
|
t.Fatalf("unexpected load error %v", err)
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ func TestLoaderLoad(t *testing.T) {
|
|||||||
t.Fatalf("in load expected %s, but got %s", x.expectedContent, b)
|
t.Fatalf("in load expected %s, but got %s", x.expectedContent, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l2, err = l1.New("/foo/project/") // Assure trailing slash stripped
|
l2, err = l1.New("foo/project/") // Assure trailing slash stripped
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v\n", err)
|
t.Fatalf("unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ func TestLoaderLoad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoaderNewSubDir(t *testing.T) {
|
func TestLoaderNewSubDir(t *testing.T) {
|
||||||
l1, err := NewFileLoaderAtRoot(MakeFakeFs(testCases)).New("/foo/project")
|
l1, err := NewFileLoaderAtRoot(MakeFakeFs(testCases)).New("foo/project")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v\n", err)
|
t.Fatalf("unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ func TestLoaderNewSubDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoaderBadRelative(t *testing.T) {
|
func TestLoaderBadRelative(t *testing.T) {
|
||||||
l1, err := NewFileLoaderAtRoot(MakeFakeFs(testCases)).New("/foo/project/subdir1")
|
l1, err := NewFileLoaderAtRoot(MakeFakeFs(testCases)).New("foo/project/subdir1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected err: %v\n", err)
|
t.Fatalf("unexpected err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func TestNewPatchJson6902FactoryJSON(t *testing.T) {
|
|||||||
target:
|
target:
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
name: some-name
|
name: some-name
|
||||||
path: /testpath/patch.json
|
path: patch.json
|
||||||
`)
|
`)
|
||||||
p := patch.Json6902{}
|
p := patch.Json6902{}
|
||||||
err = yaml.Unmarshal(jsonPatch, &p)
|
err = yaml.Unmarshal(jsonPatch, &p)
|
||||||
@@ -120,7 +120,7 @@ func TestNewPatchJson6902FactoryYAML(t *testing.T) {
|
|||||||
target:
|
target:
|
||||||
name: some-name
|
name: some-name
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
path: /testpath/patch.yaml
|
path: patch.yaml
|
||||||
`)
|
`)
|
||||||
p := patch.Json6902{}
|
p := patch.Json6902{}
|
||||||
err = yaml.Unmarshal(jsonPatch, &p)
|
err = yaml.Unmarshal(jsonPatch, &p)
|
||||||
@@ -162,12 +162,12 @@ func TestNewPatchJson6902FactoryMulti(t *testing.T) {
|
|||||||
- target:
|
- target:
|
||||||
kind: foo
|
kind: foo
|
||||||
name: some-name
|
name: some-name
|
||||||
path: /testpath/patch.json
|
path: patch.json
|
||||||
|
|
||||||
- target:
|
- target:
|
||||||
kind: foo
|
kind: foo
|
||||||
name: some-name
|
name: some-name
|
||||||
path: /testpath/patch.yaml
|
path: patch.yaml
|
||||||
`)
|
`)
|
||||||
var p []patch.Json6902
|
var p []patch.Json6902
|
||||||
err = yaml.Unmarshal(jsonPatches, &p)
|
err = yaml.Unmarshal(jsonPatches, &p)
|
||||||
@@ -276,12 +276,12 @@ func TestNewPatchJson6902FactoryMultiConflict(t *testing.T) {
|
|||||||
- target:
|
- target:
|
||||||
kind: foo
|
kind: foo
|
||||||
name: some-name
|
name: some-name
|
||||||
path: /testpath/patch.json
|
path: patch.json
|
||||||
|
|
||||||
- target:
|
- target:
|
||||||
kind: foo
|
kind: foo
|
||||||
name: some-name
|
name: some-name
|
||||||
path: /testpath/patch.yaml
|
path: patch.yaml
|
||||||
`)
|
`)
|
||||||
var p []patch.Json6902
|
var p []patch.Json6902
|
||||||
err = yaml.Unmarshal(jsonPatches, &p)
|
err = yaml.Unmarshal(jsonPatches, &p)
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ metadata:
|
|||||||
---
|
---
|
||||||
`
|
`
|
||||||
|
|
||||||
l := loadertest.NewFakeLoader("/home/seans/project")
|
l := loadertest.NewFakeLoader("/whatever/project")
|
||||||
if ferr := l.AddFile("/home/seans/project/deployment.yaml", []byte(resourceStr)); ferr != nil {
|
if ferr := l.AddFile("/whatever/project/deployment.yaml", []byte(resourceStr)); ferr != nil {
|
||||||
t.Fatalf("Error adding fake file: %v\n", ferr)
|
t.Fatalf("Error adding fake file: %v\n", ferr)
|
||||||
}
|
}
|
||||||
expected := ResMap{resid.NewResId(deploy, "dply1"): rf.FromMap(
|
expected := ResMap{resid.NewResId(deploy, "dply1"): rf.FromMap(
|
||||||
@@ -85,7 +85,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
m, _ := rmF.FromFiles(
|
m, _ := rmF.FromFiles(
|
||||||
l, []string{"/home/seans/project/deployment.yaml"})
|
l, []string{"deployment.yaml"})
|
||||||
if len(m) != 3 {
|
if len(m) != 3 {
|
||||||
t.Fatalf("%#v should contain 3 appResource, but got %d", m, len(m))
|
t.Fatalf("%#v should contain 3 appResource, but got %d", m, len(m))
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ func TestNewFromConfigMaps(t *testing.T) {
|
|||||||
expected ResMap
|
expected ResMap
|
||||||
}
|
}
|
||||||
|
|
||||||
l := loadertest.NewFakeLoader("/home/seans/project/")
|
l := loadertest.NewFakeLoader("/whatever/project/")
|
||||||
testCases := []testCase{
|
testCases := []testCase{
|
||||||
{
|
{
|
||||||
description: "construct config map from env",
|
description: "construct config map from env",
|
||||||
@@ -157,7 +157,7 @@ func TestNewFromConfigMaps(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
filepath: "/home/seans/project/app.env",
|
filepath: "/whatever/project/app.env",
|
||||||
content: "DB_USERNAME=admin\nDB_PASSWORD=somepw",
|
content: "DB_USERNAME=admin\nDB_PASSWORD=somepw",
|
||||||
expected: ResMap{
|
expected: ResMap{
|
||||||
resid.NewResId(cmap, "envConfigMap"): rf.FromMap(
|
resid.NewResId(cmap, "envConfigMap"): rf.FromMap(
|
||||||
@@ -183,7 +183,7 @@ func TestNewFromConfigMaps(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
filepath: "/home/seans/project/app-init.ini",
|
filepath: "/whatever/project/app-init.ini",
|
||||||
content: "FOO=bar\nBAR=baz\n",
|
content: "FOO=bar\nBAR=baz\n",
|
||||||
expected: ResMap{
|
expected: ResMap{
|
||||||
resid.NewResId(cmap, "fileConfigMap"): rf.FromMap(
|
resid.NewResId(cmap, "fileConfigMap"): rf.FromMap(
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ import (
|
|||||||
|
|
||||||
func TestSliceFromPatches(t *testing.T) {
|
func TestSliceFromPatches(t *testing.T) {
|
||||||
|
|
||||||
patchGood1 := patch.StrategicMerge("/foo/patch1.yaml")
|
patchGood1 := patch.StrategicMerge("patch1.yaml")
|
||||||
patch1 := `
|
patch1 := `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: pooh
|
name: pooh
|
||||||
`
|
`
|
||||||
patchGood2 := patch.StrategicMerge("/foo/patch2.yaml")
|
patchGood2 := patch.StrategicMerge("patch2.yaml")
|
||||||
patch2 := `
|
patch2 := `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
@@ -45,14 +45,14 @@ metadata:
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
`
|
`
|
||||||
patchBad := patch.StrategicMerge("/foo/patch3.yaml")
|
patchBad := patch.StrategicMerge("patch3.yaml")
|
||||||
patch3 := `
|
patch3 := `
|
||||||
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT: woot
|
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT: woot
|
||||||
`
|
`
|
||||||
l := loadertest.NewFakeLoader("/foo")
|
l := loadertest.NewFakeLoader("/")
|
||||||
l.AddFile(string(patchGood1), []byte(patch1))
|
l.AddFile("/"+string(patchGood1), []byte(patch1))
|
||||||
l.AddFile(string(patchGood2), []byte(patch2))
|
l.AddFile("/"+string(patchGood2), []byte(patch2))
|
||||||
l.AddFile(string(patchBad), []byte(patch3))
|
l.AddFile("/"+string(patchBad), []byte(patch3))
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namePrefix:
|
|||||||
|
|
||||||
func TestMakeTransformerConfigFromFiles(t *testing.T) {
|
func TestMakeTransformerConfigFromFiles(t *testing.T) {
|
||||||
ldr, expected, _ := makeFakeLoaderAndOutput()
|
ldr, expected, _ := makeFakeLoaderAndOutput()
|
||||||
tcfg, err := NewFactory(ldr).FromFiles([]string{"/transformerconfig/test/config.yaml"})
|
tcfg, err := NewFactory(ldr).FromFiles([]string{"transformerconfig/test/config.yaml"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,9 +182,11 @@ func TestLoadCRDs(t *testing.T) {
|
|||||||
NameReference: nbrs,
|
NameReference: nbrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
actualTc, _ := NewFactory(makeLoader(t)).LoadCRDs(
|
actualTc, err := NewFactory(makeLoader(t)).LoadCRDs(
|
||||||
[]string{"/testpath/crd.json"})
|
[]string{"crd.json"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error:%v", err)
|
||||||
|
}
|
||||||
if !reflect.DeepEqual(actualTc, expectedTc) {
|
if !reflect.DeepEqual(actualTc, expectedTc) {
|
||||||
t.Fatalf("expected\n %v\n but got\n %v\n", expectedTc, actualTc)
|
t.Fatalf("expected\n %v\n but got\n %v\n", expectedTc, actualTc)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user