mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-22 06:47:00 +00:00
@@ -1,13 +1,14 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package target_test
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
. "sigs.k8s.io/kustomize/api/krusty"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
const httpsService = `
|
||||
@@ -24,7 +25,7 @@ spec:
|
||||
app: my-app
|
||||
`
|
||||
|
||||
func writeStatefulSetBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeStatefulSetBase(th testingHarness) {
|
||||
th.WriteK("/app/base", `
|
||||
resources:
|
||||
- statefulset.yaml
|
||||
@@ -53,7 +54,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeHTTPSOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeHTTPSOverlay(th testingHarness) {
|
||||
th.WriteK("/app/https", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -72,7 +73,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeHTTPSTransformerRaw(th *kusttest_test.KustTestHarness) {
|
||||
func writeHTTPSTransformerRaw(th testingHarness) {
|
||||
th.WriteF("/app/https/service/https-svc.yaml", httpsService)
|
||||
th.WriteF("/app/https/transformer/transformer.yaml", `
|
||||
apiVersion: builtin
|
||||
@@ -94,7 +95,7 @@ patch: |-
|
||||
`)
|
||||
}
|
||||
|
||||
func writeHTTPSTransformerBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeHTTPSTransformerBase(th testingHarness) {
|
||||
th.WriteK("/app/https/service", `
|
||||
resources:
|
||||
- https-svc.yaml
|
||||
@@ -106,7 +107,7 @@ resources:
|
||||
writeHTTPSTransformerRaw(th)
|
||||
}
|
||||
|
||||
func writeConfigFromEnvOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeConfigFromEnvOverlay(th testingHarness) {
|
||||
th.WriteK("/app/config", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -135,7 +136,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeConfigFromEnvTransformerRaw(th *kusttest_test.KustTestHarness) {
|
||||
func writeConfigFromEnvTransformerRaw(th testingHarness) {
|
||||
th.WriteF("/app/config/map/generator.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: ConfigMapGenerator
|
||||
@@ -170,7 +171,7 @@ patch: |-
|
||||
name: my-config
|
||||
`)
|
||||
}
|
||||
func writeConfigFromEnvTransformerBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeConfigFromEnvTransformerBase(th testingHarness) {
|
||||
th.WriteK("/app/config/map", `
|
||||
resources:
|
||||
- generator.yaml
|
||||
@@ -182,7 +183,7 @@ resources:
|
||||
writeConfigFromEnvTransformerRaw(th)
|
||||
}
|
||||
|
||||
func writeTolerationsOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeTolerationsOverlay(th testingHarness) {
|
||||
th.WriteK("/app/tolerations", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -204,7 +205,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeTolerationsTransformerRaw(th *kusttest_test.KustTestHarness) {
|
||||
func writeTolerationsTransformerRaw(th testingHarness) {
|
||||
th.WriteF("/app/tolerations/transformer.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: PatchTransformer
|
||||
@@ -230,7 +231,7 @@ patch: |-
|
||||
`)
|
||||
}
|
||||
|
||||
func writeTolerationsTransformerBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeTolerationsTransformerBase(th testingHarness) {
|
||||
th.WriteK("/app/tolerations", `
|
||||
resources:
|
||||
- transformer.yaml
|
||||
@@ -238,7 +239,7 @@ resources:
|
||||
writeTolerationsTransformerRaw(th)
|
||||
}
|
||||
|
||||
func writeStorageOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeStorageOverlay(th testingHarness) {
|
||||
th.WriteK("/app/storage", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -255,7 +256,7 @@ patchesJson6902:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeStorageTransformerRaw(th *kusttest_test.KustTestHarness) {
|
||||
func writeStorageTransformerRaw(th testingHarness) {
|
||||
th.WriteF("/app/storage/transformer.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: PatchTransformer
|
||||
@@ -271,7 +272,7 @@ patch: |-
|
||||
`)
|
||||
}
|
||||
|
||||
func writeStorageTransformerBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeStorageTransformerBase(th testingHarness) {
|
||||
th.WriteK("/app/storage", `
|
||||
resources:
|
||||
- transformer.yaml
|
||||
@@ -279,14 +280,14 @@ resources:
|
||||
writeStorageTransformerRaw(th)
|
||||
}
|
||||
|
||||
func writePatchingOverlays(th *kusttest_test.KustTestHarness) {
|
||||
func writePatchingOverlays(th testingHarness) {
|
||||
writeStorageOverlay(th)
|
||||
writeConfigFromEnvOverlay(th)
|
||||
writeTolerationsOverlay(th)
|
||||
writeHTTPSOverlay(th)
|
||||
}
|
||||
|
||||
func writePatchingTransformersRaw(th *kusttest_test.KustTestHarness) {
|
||||
func writePatchingTransformersRaw(th testingHarness) {
|
||||
writeStorageTransformerRaw(th)
|
||||
writeConfigFromEnvTransformerRaw(th)
|
||||
writeTolerationsTransformerRaw(th)
|
||||
@@ -309,7 +310,7 @@ func writePatchingTransformersRaw(th *kusttest_test.KustTestHarness) {
|
||||
// must be self-contained, i.e. the config may not have fields that
|
||||
// refer to local files, since those files won't be present when
|
||||
// the plugin is instantiated and used.
|
||||
func writePatchingTransformerBases(th *kusttest_test.KustTestHarness) {
|
||||
func writePatchingTransformerBases(th testingHarness) {
|
||||
writeStorageTransformerBase(th)
|
||||
writeConfigFromEnvTransformerBase(th)
|
||||
writeTolerationsTransformerBase(th)
|
||||
@@ -352,7 +353,7 @@ func writePatchingTransformerBases(th *kusttest_test.KustTestHarness) {
|
||||
// - prod: Combines the config, tolerations and https intermediate overlays.
|
||||
|
||||
func TestComplexComposition_Dev_Failure(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/dev")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingOverlays(th)
|
||||
th.WriteK("/app/dev", `
|
||||
@@ -360,7 +361,7 @@ resources:
|
||||
- ../storage
|
||||
- ../config
|
||||
`)
|
||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
err := th.RunWithErr("/app/dev", th.MakeDefaultOptions())
|
||||
if err == nil {
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
@@ -404,7 +405,7 @@ metadata:
|
||||
`
|
||||
|
||||
func TestComplexComposition_Dev_SuccessWithRawTransformers(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/dev")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingTransformersRaw(th)
|
||||
th.WriteK("/app/dev", `
|
||||
@@ -416,15 +417,16 @@ transformers:
|
||||
- ../config/transformer/transformer.yaml
|
||||
- ../storage/transformer.yaml
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/dev", func() Options {
|
||||
o := th.MakeDefaultOptions()
|
||||
o.LoadRestrictions = types.LoadRestrictionsNone
|
||||
return o
|
||||
}())
|
||||
th.AssertActualEqualsExpected(m, devDesiredResult)
|
||||
}
|
||||
|
||||
func TestComplexComposition_Dev_SuccessWithBaseTransformers(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/dev")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingTransformerBases(th)
|
||||
th.WriteK("/app/dev", `
|
||||
@@ -436,15 +438,12 @@ transformers:
|
||||
- ../config/transformer
|
||||
- ../storage
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/dev", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, devDesiredResult)
|
||||
}
|
||||
|
||||
func TestComplexComposition_Prod_Failure(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingOverlays(th)
|
||||
th.WriteK("/app/prod", `
|
||||
@@ -453,7 +452,7 @@ resources:
|
||||
- ../tolerations
|
||||
- ../https
|
||||
`)
|
||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
err := th.RunWithErr("/app/prod", th.MakeDefaultOptions())
|
||||
if err == nil {
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
@@ -513,7 +512,7 @@ metadata:
|
||||
`
|
||||
|
||||
func TestComplexComposition_Prod_SuccessWithRawTransformers(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingTransformersRaw(th)
|
||||
th.WriteK("/app/prod", `
|
||||
@@ -527,15 +526,16 @@ transformers:
|
||||
- ../https/transformer/transformer.yaml
|
||||
- ../tolerations/transformer.yaml
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/prod", func() Options {
|
||||
o := th.MakeDefaultOptions()
|
||||
o.LoadRestrictions = types.LoadRestrictionsNone
|
||||
return o
|
||||
}())
|
||||
th.AssertActualEqualsExpected(m, prodDesiredResult)
|
||||
}
|
||||
|
||||
func TestComplexComposition_Prod_SuccessWithBaseTransformers(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
writeStatefulSetBase(th)
|
||||
writePatchingTransformerBases(th)
|
||||
th.WriteK("/app/prod", `
|
||||
@@ -549,9 +549,6 @@ transformers:
|
||||
- ../https/transformer
|
||||
- ../tolerations
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/prod", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, prodDesiredResult)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package target_test
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -19,8 +19,7 @@ func TestCustomNamePrefixer(t *testing.T) {
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PrefixSuffixTransformer")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
||||
|
||||
th := makeTestHarness(t)
|
||||
th.WriteK("/app", `
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -69,10 +68,7 @@ metadata:
|
||||
name: myService
|
||||
`)
|
||||
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package target_test
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -24,7 +24,7 @@ func TestReusableCustomTransformers(t *testing.T) {
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "LabelTransformer")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/staging")
|
||||
th := makeTestHarness(t)
|
||||
|
||||
// First write three custom configurations for builtin plugins.
|
||||
|
||||
@@ -138,10 +138,7 @@ metadata:
|
||||
name: myService
|
||||
`)
|
||||
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/staging", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package target_test
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
const patchAddProbe = `
|
||||
@@ -57,7 +58,7 @@ spec:
|
||||
`
|
||||
const patchJsonRestartPolicy = `[{"op": "add", "path": "/spec/template/spec/restartPolicy", "value": "Always"}]`
|
||||
|
||||
func writeDeploymentBase(th *kusttest_test.KustTestHarness) {
|
||||
func writeDeploymentBase(th testingHarness) {
|
||||
th.WriteK("/app/base", `
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -78,7 +79,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeProbeOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeProbeOverlay(th testingHarness) {
|
||||
th.WriteK("/app/probe", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -88,7 +89,7 @@ patchesStrategicMerge:
|
||||
th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe)
|
||||
}
|
||||
|
||||
func writeDNSOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeDNSOverlay(th testingHarness) {
|
||||
th.WriteK("/app/dns", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -98,7 +99,7 @@ patchesStrategicMerge:
|
||||
th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy)
|
||||
}
|
||||
|
||||
func writeRestartOverlay(th *kusttest_test.KustTestHarness) {
|
||||
func writeRestartOverlay(th testingHarness) {
|
||||
th.WriteK("/app/restart", `
|
||||
resources:
|
||||
- ../base
|
||||
@@ -122,7 +123,7 @@ patchesStrategicMerge:
|
||||
// base
|
||||
//
|
||||
func TestIssue1251_CompositeDiamond_Failure(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
|
||||
th := makeTestHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
writeProbeOverlay(th)
|
||||
writeDNSOverlay(th)
|
||||
@@ -135,7 +136,7 @@ resources:
|
||||
- ../restart
|
||||
`)
|
||||
|
||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
err := th.RunWithErr("/app/composite", th.MakeDefaultOptions())
|
||||
if err == nil {
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
@@ -167,7 +168,7 @@ spec:
|
||||
// This test reuses some methods from TestIssue1251_CompositeDiamond,
|
||||
// but overwrites the kustomization files in the overlays.
|
||||
func TestIssue1251_Patches_Overlayed(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/restart")
|
||||
th := makeTestHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
|
||||
// probe overlays base.
|
||||
@@ -191,15 +192,12 @@ patchesStrategicMerge:
|
||||
- dep-patch.yaml
|
||||
`)
|
||||
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/restart", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||
}
|
||||
|
||||
func TestIssue1251_Patches_Local(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/composite")
|
||||
th := makeTestHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
|
||||
th.WriteK("/app/composite", `
|
||||
@@ -214,14 +212,11 @@ patchesStrategicMerge:
|
||||
th.WriteF("/app/composite/patchDnsPolicy.yaml", patchDnsPolicy)
|
||||
th.WriteF("/app/composite/patchAddProbe.yaml", patchAddProbe)
|
||||
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/composite", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||
}
|
||||
|
||||
func definePatchDirStructure(th *kusttest_test.KustTestHarness) {
|
||||
func definePatchDirStructure(th testingHarness) {
|
||||
writeDeploymentBase(th)
|
||||
|
||||
th.WriteF("/app/patches/patchRestartPolicy.yaml", patchRestartPolicy)
|
||||
@@ -231,7 +226,7 @@ func definePatchDirStructure(th *kusttest_test.KustTestHarness) {
|
||||
|
||||
// Fails due to file load restrictor.
|
||||
func TestIssue1251_Patches_ProdVsDev_Failure(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
definePatchDirStructure(th)
|
||||
|
||||
th.WriteK("/app/prod", `
|
||||
@@ -242,7 +237,7 @@ patchesStrategicMerge:
|
||||
- ../patches/patchDnsPolicy.yaml
|
||||
`)
|
||||
|
||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
err := th.RunWithErr("/app/prod", th.MakeDefaultOptions())
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
}
|
||||
@@ -304,7 +299,7 @@ spec:
|
||||
// the kustomization root), opening the user to whatever
|
||||
// threat the load restrictor was meant to address.
|
||||
func TestIssue1251_Patches_ProdVsDev(t *testing.T) {
|
||||
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
definePatchDirStructure(th)
|
||||
|
||||
th.WriteK("/app/prod", `
|
||||
@@ -314,13 +309,13 @@ patchesStrategicMerge:
|
||||
- ../patches/patchAddProbe.yaml
|
||||
- ../patches/patchDnsPolicy.yaml
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
opts := th.MakeDefaultOptions()
|
||||
opts.LoadRestrictions = types.LoadRestrictionsNone
|
||||
|
||||
m := th.Run("/app/prod", opts)
|
||||
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
|
||||
|
||||
th = kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/dev")
|
||||
th = makeTestHarness(t)
|
||||
definePatchDirStructure(th)
|
||||
|
||||
th.WriteK("/app/dev", `
|
||||
@@ -331,10 +326,7 @@ patchesStrategicMerge:
|
||||
- ../patches/patchRestartPolicy.yaml
|
||||
`)
|
||||
|
||||
m, err = th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m = th.Run("/app/dev", opts)
|
||||
th.AssertActualEqualsExpected(m, prodDevMergeResult2)
|
||||
}
|
||||
|
||||
@@ -345,7 +337,7 @@ func TestIssue1251_Plugins_ProdVsDev(t *testing.T) {
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/prod")
|
||||
th := makeTestHarness(t)
|
||||
defineTransformerDirStructure(th)
|
||||
th.WriteK("/app/prod", `
|
||||
resources:
|
||||
@@ -355,13 +347,9 @@ transformers:
|
||||
- ../patches/addDnsPolicy
|
||||
`)
|
||||
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/prod", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
|
||||
|
||||
th = kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/dev")
|
||||
defineTransformerDirStructure(th)
|
||||
th.WriteK("/app/dev", `
|
||||
resources:
|
||||
@@ -371,10 +359,7 @@ transformers:
|
||||
- ../patches/addDnsPolicy
|
||||
`)
|
||||
|
||||
m, err = th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m = th.Run("/app/dev", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, prodDevMergeResult2)
|
||||
}
|
||||
|
||||
@@ -385,7 +370,7 @@ func TestIssue1251_Plugins_Local(t *testing.T) {
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/composite")
|
||||
th := makeTestHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
|
||||
writeJsonTransformerPluginConfig(
|
||||
@@ -403,15 +388,12 @@ transformers:
|
||||
- addRestartPolicyConfig.yaml
|
||||
- addProbeConfig.yaml
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/composite", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||
}
|
||||
|
||||
func writeJsonTransformerPluginConfig(
|
||||
th *kusttest_test.KustTestHarness, path, name, patch string) {
|
||||
th testingHarness, path, name, patch string) {
|
||||
th.WriteF(filepath.Join(path, name+"Config.yaml"),
|
||||
fmt.Sprintf(`
|
||||
apiVersion: builtin
|
||||
@@ -435,7 +417,7 @@ func TestIssue1251_Plugins_Bundled(t *testing.T) {
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/composite")
|
||||
th := makeTestHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
|
||||
th.WriteK("/app/patches", `
|
||||
@@ -457,14 +439,11 @@ resources:
|
||||
transformers:
|
||||
- ../patches
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
m := th.Run("/app/composite", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||
}
|
||||
|
||||
func defineTransformerDirStructure(th *kusttest_test.KustTestHarness) {
|
||||
func defineTransformerDirStructure(th testingHarness) {
|
||||
writeDeploymentBase(th)
|
||||
|
||||
th.WriteK("/app/patches/addDnsPolicy", `
|
||||
@@ -47,6 +47,7 @@ func (th testingHarness) MakeDefaultOptions() Options {
|
||||
return th.MakeOptionsPluginsDisabled()
|
||||
}
|
||||
|
||||
// This has no impact on Builtin plugins, as they are always enabled.
|
||||
func (th testingHarness) MakeOptionsPluginsDisabled() Options {
|
||||
return Options{
|
||||
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
||||
@@ -54,6 +55,7 @@ func (th testingHarness) MakeOptionsPluginsDisabled() Options {
|
||||
}
|
||||
}
|
||||
|
||||
// Enables use of non-builtin plugins.
|
||||
func (th testingHarness) MakeOptionsPluginsEnabled() Options {
|
||||
c, err := konfig.EnabledPluginConfig()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user