Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/internal/localizer/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (lc *localizer) load() (*types.Kustomization, string, error) {
var kust types.Kustomization
err = (&kust).Unmarshal(content)
if err != nil {
return nil, "", errors.WrapPrefixf(err, "invalid kustomization")
return nil, "", errors.Wrap(err)
}

// Localize intentionally does not replace legacy fields to return a localized kustomization
Expand Down
3 changes: 2 additions & 1 deletion api/internal/localizer/localizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ suffix: invalid`,
})

err := Run("/a", "", "", fSysTest)
require.EqualError(t, err, `unable to localize target "/a": invalid kustomization: json: unknown field "suffix"`)
require.EqualError(t, err,
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)

checkFSys(t, fSysExpected, fSysTest)
}
Expand Down
20 changes: 4 additions & 16 deletions api/internal/target/kusttarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ commonLabels:

func TestMakeCustomizedResMap(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/whatever", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
Comment on lines -142 to -144
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove apiVersion: kustomize.config.k8s.io/v1beta1 and kind: Kustomization,
because th.WriteK is always added above two lines.

namePrefix: foo-
th.WriteK("/whatever", `namePrefix: foo-
nameSuffix: -bar
namespace: ns1
commonLabels:
Expand Down Expand Up @@ -301,10 +298,7 @@ metadata:

func TestConfigurationsOverrideDefault(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/merge-config", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
th.WriteK("/merge-config", `namePrefix: foo-
nameSuffix: -bar
namespace: ns1
resources:
Expand Down Expand Up @@ -401,10 +395,7 @@ metadata:

func TestDuplicateExternalGeneratorsForbidden(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/generator", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generators:
th.WriteK("/generator", `generators:
- |-
apiVersion: generators.example/v1
kind: ManifestGenerator
Expand Down Expand Up @@ -437,10 +428,7 @@ generators:

func TestDuplicateExternalTransformersForbidden(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("/transformer", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
th.WriteK("/transformer", `transformers:
- |-
apiVersion: transformers.example.co/v1
kind: ValueAnnotator
Expand Down
5 changes: 1 addition & 4 deletions api/krusty/basic_io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ spec:
// test for https://github.com/kubernetes-sigs/kustomize/issues/3812#issuecomment-862339267
func TestBasicIO3812(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
th.WriteK(".", `resources:
- service.yaml
`)

Expand Down
43 changes: 15 additions & 28 deletions api/krusty/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package krusty_test
import (
"testing"

"github.com/stretchr/testify/assert"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)

Expand Down Expand Up @@ -138,10 +139,10 @@ configMapGenerator:
- name: json
literals:
- 'v2=[{"path": "var/druid/segment-cache"}]'
- >-
druid_segmentCache_locations=[{"path":
"var/druid/segment-cache",
"maxSize": 32000000000,
- >-
druid_segmentCache_locations=[{"path":
"var/druid/segment-cache",
"maxSize": 32000000000,
"freeSpacePercent": 1.0}]
secretGenerator:
- name: bob
Expand Down Expand Up @@ -201,12 +202,12 @@ metadata:
---
apiVersion: v1
data:
druid_segmentCache_locations: '[{"path": "var/druid/segment-cache", "maxSize":
32000000000, "freeSpacePercent": 1.0}]'
druid_segmentCache_locations: '[{"path": "var/druid/segment-cache", "maxSize": 32000000000,
"freeSpacePercent": 1.0}]'
v2: '[{"path": "var/druid/segment-cache"}]'
kind: ConfigMap
metadata:
name: blah-json-5298bc8g99
name: blah-json-m8529t979f
---
apiVersion: v1
data:
Expand All @@ -228,7 +229,6 @@ type: Opaque
`)
}

// TODO: These should be errors instead.
func TestGeneratorRepeatsInKustomization(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
Expand Down Expand Up @@ -261,24 +261,13 @@ krypton
xenon
radon
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
fruit: apple
nobles: |2

helium
neon
argon
krypton
xenon
radon
vegetable: broccoli
kind: ConfigMap
metadata:
name: blah-bob-db529cg5bk
`)
err := th.RunWithErr(".", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("expected an error")
}
assert.Contains(t, err.Error(),
"invalid Kustomization: error converting YAML to JSON: yaml: unmarshal errors:\n"+
" line 13: key \"literals\" already set in map\n line 18: key \"files\" already set in map")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be an error like this TODO comment.

}

func TestIssue3393(t *testing.T) {
Expand Down Expand Up @@ -553,8 +542,6 @@ metadata:
func TestDataEndsWithQuotes(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: test
literals:
Expand Down
6 changes: 0 additions & 6 deletions api/krusty/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

func writeBaseWithCrd(th kusttest_test.Harness) {
th.WriteK("base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
crds:
- mycrd.json

Expand Down Expand Up @@ -259,8 +257,6 @@ func TestCrdWithOverlay(t *testing.T) {
th := kusttest_test.MakeHarness(t)
writeBaseWithCrd(th)
th.WriteK("overlay", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: prod-
resources:
- ../base
Expand Down Expand Up @@ -307,8 +303,6 @@ spec:
func TestCrdWithContainers(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("crd/containers", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- crd.yaml
images:
Expand Down
4 changes: 0 additions & 4 deletions api/krusty/disablenamesuffix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func findSecret(m resmap.ResMap, prefix string) *resource.Resource {
func TestDisableNameSuffixHash(t *testing.T) {
th := kusttest_test.MakeHarness(t)
const kustomizationContent = `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
nameSuffix: -bar
namespace: ns1
Expand Down Expand Up @@ -101,8 +99,6 @@ metadata:
func TestDisableNameSuffixHashPerObject(t *testing.T) {
th := kusttest_test.MakeHarness(t)
const kustomizationContent = `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generatorOptions:
disableNameSuffixHash: false
secretGenerator:
Expand Down
2 changes: 0 additions & 2 deletions api/krusty/generatormergeandreplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
func TestSimpleBase(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: team-foo-
commonLabels:
app: mynginx
Expand Down
4 changes: 0 additions & 4 deletions api/krusty/generatoroptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type: Opaque
func TestGeneratorOptionsWithBases(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
generatorOptions:
disableNameSuffixHash: true
labels:
Expand All @@ -60,8 +58,6 @@ configMapGenerator:
- foo=bar
`)
th.WriteK("overlay", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
generatorOptions:
Expand Down
6 changes: 1 addition & 5 deletions api/krusty/gvknpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ patches:
- path: patch.yaml
target:
kind: Deployment
options:
options:
allowNameChange: true
`)
options := th.MakeDefaultOptions()
Expand Down Expand Up @@ -721,8 +721,6 @@ spec:
name: myvol
`)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: foo-
resources:
- resources.yaml
Expand Down Expand Up @@ -798,8 +796,6 @@ spec:
name: myvol
`)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- statefulset.yaml
patches:
Expand Down
2 changes: 0 additions & 2 deletions api/krusty/inlinepatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ spec:
func TestPathWithCronJobV1(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources.yaml
patches:
Expand Down
4 changes: 1 addition & 3 deletions api/krusty/kustomizationmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ spec:
imagePullSecrets: []`)

th.WriteK("/app", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
annotations:
config.kubernetes.io/local-config: "true"
labels:
foo: bar
name: test_kustomization
resources:
- resources.yaml
- resources.yaml
`)

m := th.Run("/app", th.MakeDefaultOptions())
Expand Down
4 changes: 1 addition & 3 deletions api/krusty/localconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
// See https://github.com/kubernetes-sigs/kustomize/issues/4124 for details.
func TestSKipLocalConfigAfterTransform(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
th.WriteK(".", `resources:
- pod.yaml
- deployment.yaml
transformers:
Expand Down
5 changes: 1 addition & 4 deletions api/krusty/managedbylabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
- port: 7002
`

// This test may failed when running on package tests using the go command because `v444.333.222` is set on makefile.
func TestAddManagedbyLabel(t *testing.T) {
tests := []struct {
kustFile string
Expand All @@ -28,8 +29,6 @@ func TestAddManagedbyLabel(t *testing.T) {
}{
{
kustFile: `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
`,
Expand All @@ -38,8 +37,6 @@ resources:
},
{
kustFile: `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
buildMetadata: [managedByLabel]
Expand Down
2 changes: 0 additions & 2 deletions api/krusty/namespacedgenerators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
func TestNamespacedGenerator(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
- name: the-non-default-namespace-map
namespace: non-default
Expand Down
2 changes: 0 additions & 2 deletions api/krusty/nameupdateinroleref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ fieldSpecs:
`)

th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- workloads.yaml
transformers:
Expand Down
16 changes: 7 additions & 9 deletions api/krusty/originannotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ spec:
- port: 7002
`)
th.WriteK(".", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
buildMetadata: [originAnnotations]
Expand Down Expand Up @@ -175,10 +173,10 @@ configMapGenerator:
- name: json
literals:
- 'v2=[{"path": "var/druid/segment-cache"}]'
- >-
druid_segmentCache_locations=[{"path":
"var/druid/segment-cache",
"maxSize": 32000000000,
- >-
druid_segmentCache_locations=[{"path":
"var/druid/segment-cache",
"maxSize": 32000000000,
"freeSpacePercent": 1.0}]
secretGenerator:
- name: bob
Expand Down Expand Up @@ -245,8 +243,8 @@ metadata:
---
apiVersion: v1
data:
druid_segmentCache_locations: '[{"path": "var/druid/segment-cache", "maxSize":
32000000000, "freeSpacePercent": 1.0}]'
druid_segmentCache_locations: '[{"path": "var/druid/segment-cache", "maxSize": 32000000000,
"freeSpacePercent": 1.0}]'
v2: '[{"path": "var/druid/segment-cache"}]'
kind: ConfigMap
metadata:
Expand All @@ -256,7 +254,7 @@ metadata:
configuredBy:
apiVersion: builtin
kind: ConfigMapGenerator
name: blah-json-5298bc8g99
name: blah-json-m8529t979f
---
apiVersion: v1
data:
Expand Down
Loading