mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
@@ -7,13 +7,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/namespace"
|
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/transform"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,8 +22,9 @@ type NamespaceTransformerPlugin struct {
|
|||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
|
|
||||||
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
||||||
// kunstruct transformer
|
// kunstruct transformer.
|
||||||
YAMLSupport bool
|
// TODO: change the default to use kyaml when it is stable
|
||||||
|
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NamespaceTransformerPlugin) Config(
|
func (p *NamespaceTransformerPlugin) Config(
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/namespace"
|
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
"sigs.k8s.io/kustomize/api/transform"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,8 +23,9 @@ type plugin struct {
|
|||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
|
|
||||||
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
||||||
// kunstruct transformer
|
// kunstruct transformer.
|
||||||
YAMLSupport bool
|
// TODO: change the default to use kyaml when it is stable
|
||||||
|
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -11,16 +12,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespaceTransformer1(t *testing.T) {
|
func TestNamespaceTransformer1(t *testing.T) {
|
||||||
|
for _, b := range []bool{true, false} {
|
||||||
|
t.Run(fmt.Sprintf("yaml-%v", b), func(t *testing.T) {
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
PrepBuiltin("NamespaceTransformer")
|
PrepBuiltin("NamespaceTransformer")
|
||||||
defer th.Reset()
|
defer th.Reset()
|
||||||
|
rm := th.LoadAndRunTransformer(fmt.Sprintf(`
|
||||||
rm := th.LoadAndRunTransformer(`
|
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: NamespaceTransformer
|
kind: NamespaceTransformer
|
||||||
metadata:
|
metadata:
|
||||||
name: notImportantHere
|
name: notImportantHere
|
||||||
namespace: test
|
namespace: test
|
||||||
|
yamlSupport: %v
|
||||||
fieldSpecs:
|
fieldSpecs:
|
||||||
- path: metadata/namespace
|
- path: metadata/namespace
|
||||||
create: true
|
create: true
|
||||||
@@ -30,7 +33,7 @@ fieldSpecs:
|
|||||||
- path: subjects
|
- path: subjects
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
group: rbac.authorization.k8s.io
|
group: rbac.authorization.k8s.io
|
||||||
`, `
|
`, b), `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
@@ -182,9 +185,13 @@ kind: CustomResourceDefinition
|
|||||||
metadata:
|
metadata:
|
||||||
name: crd
|
name: crd
|
||||||
`)
|
`)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNamespaceTransformerClusterLevelKinds(t *testing.T) {
|
func TestNamespaceTransformerClusterLevelKinds(t *testing.T) {
|
||||||
|
for _, b := range []bool{true, false} {
|
||||||
|
t.Run(fmt.Sprintf("yaml-%v", b), func(t *testing.T) {
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
PrepBuiltin("NamespaceTransformer")
|
PrepBuiltin("NamespaceTransformer")
|
||||||
defer th.Reset()
|
defer th.Reset()
|
||||||
@@ -211,12 +218,13 @@ kind: PersistentVolume
|
|||||||
metadata:
|
metadata:
|
||||||
name: pv1
|
name: pv1
|
||||||
`
|
`
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(fmt.Sprintf(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: NamespaceTransformer
|
kind: NamespaceTransformer
|
||||||
metadata:
|
metadata:
|
||||||
name: notImportantHere
|
name: notImportantHere
|
||||||
namespace: test
|
namespace: test
|
||||||
|
yamlSupport: %v
|
||||||
fieldSpecs:
|
fieldSpecs:
|
||||||
- path: metadata/namespace
|
- path: metadata/namespace
|
||||||
create: true
|
create: true
|
||||||
@@ -226,26 +234,32 @@ fieldSpecs:
|
|||||||
- path: subjects
|
- path: subjects
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
group: rbac.authorization.k8s.io
|
group: rbac.authorization.k8s.io
|
||||||
`, noChangeExpected)
|
`, b), noChangeExpected)
|
||||||
|
|
||||||
th.AssertActualEqualsExpected(rm, noChangeExpected)
|
th.AssertActualEqualsExpected(rm, noChangeExpected)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNamespaceTransformerObjectConflict(t *testing.T) {
|
func TestNamespaceTransformerObjectConflict(t *testing.T) {
|
||||||
|
for _, b := range []bool{true, false} {
|
||||||
|
t.Run(fmt.Sprintf("yaml-%v", b), func(t *testing.T) {
|
||||||
|
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
PrepBuiltin("NamespaceTransformer")
|
PrepBuiltin("NamespaceTransformer")
|
||||||
defer th.Reset()
|
defer th.Reset()
|
||||||
|
|
||||||
err := th.ErrorFromLoadAndRunTransformer(`
|
err := th.ErrorFromLoadAndRunTransformer(fmt.Sprintf(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: NamespaceTransformer
|
kind: NamespaceTransformer
|
||||||
metadata:
|
metadata:
|
||||||
name: notImportantHere
|
name: notImportantHere
|
||||||
namespace: test
|
namespace: test
|
||||||
|
yamlSupport: %v
|
||||||
fieldSpecs:
|
fieldSpecs:
|
||||||
- path: metadata/namespace
|
- path: metadata/namespace
|
||||||
create: true
|
create: true
|
||||||
`, `
|
`, b), `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
@@ -265,4 +279,6 @@ metadata:
|
|||||||
if !strings.Contains(err.Error(), "ID conflict") {
|
if !strings.Contains(err.Error(), "ID conflict") {
|
||||||
t.Fatalf("unexpected error: %s", err.Error())
|
t.Fatalf("unexpected error: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user