Start api directory, which will become a module.

This commit is contained in:
Jeffrey Regan
2019-10-17 11:36:34 -07:00
parent 180429774a
commit e5c8b5ec8f
226 changed files with 623 additions and 689 deletions

View File

@@ -8,11 +8,11 @@ import (
"log"
"strings"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/types"
)
// ResAccumulator accumulates resources and the rules

View File

@@ -10,14 +10,14 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
. "sigs.k8s.io/kustomize/v3/pkg/accumulator"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/types"
)
func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory) {
@@ -75,13 +75,13 @@ func TestResolveVarsHappy(t *testing.T) {
{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"},
},
{
Name: "SERVICE_TWO",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendTwo"},
},
})
@@ -104,13 +104,13 @@ func TestResolveVarsOneUnused(t *testing.T) {
{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"},
},
{
Name: "SERVICE_UNUSED",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendTwo"},
},
})
@@ -165,7 +165,7 @@ func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne",
},
},
@@ -204,7 +204,7 @@ func makeVarToNamepaceAndPath(
return types.Var{
Name: name,
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"},
Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"},
Name: "environment",
Namespace: namespace,
},
@@ -266,7 +266,7 @@ func TestResolveVarsGoodResIdBadField(t *testing.T) {
{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"},
FieldRef: types.FieldSelector{FieldPath: "nope_nope_nope"},
},
@@ -291,7 +291,7 @@ func TestResolveVarsUnmappableVar(t *testing.T) {
{
Name: "SERVICE_THREE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "doesNotExist"},
},
})
@@ -315,7 +315,7 @@ func TestResolveVarsWithNoambiguation(t *testing.T) {
{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne",
},
},
@@ -370,7 +370,7 @@ func TestResolveVarsWithNoambiguation(t *testing.T) {
{
Name: "SUB_SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne",
},
},

View File

@@ -9,7 +9,7 @@ import (
"os/exec"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
)
// Cloner is a function that can clone a git repo.

View File

@@ -9,7 +9,7 @@ import (
"regexp"
"strings"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
)
// Used as a temporary non-empty occupant of the cloneDir

View File

@@ -1,200 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package gvk
import (
"strings"
)
// Gvk identifies a Kubernetes API type.
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type Gvk struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
}
// FromKind makes a Gvk with only the kind specified.
func FromKind(k string) Gvk {
return Gvk{
Kind: k,
}
}
// FromString makes a Gvk with a string,
// which is constructed by String() function
func FromString(s string) Gvk {
values := strings.Split(s, separator)
g := values[0]
if g == noGroup {
g = ""
}
v := values[1]
if v == noVersion {
v = ""
}
k := values[2]
if k == noKind {
k = ""
}
return Gvk{
Group: g,
Version: v,
Kind: k,
}
}
// Values that are brief but meaningful in logs.
const (
noGroup = "~G"
noVersion = "~V"
noKind = "~K"
separator = "_"
)
// String returns a string representation of the GVK.
func (x Gvk) String() string {
g := x.Group
if g == "" {
g = noGroup
}
v := x.Version
if v == "" {
v = noVersion
}
k := x.Kind
if k == "" {
k = noKind
}
return strings.Join([]string{g, v, k}, separator)
}
// Equals returns true if the Gvk's have equal fields.
func (x Gvk) Equals(o Gvk) bool {
return x.Group == o.Group && x.Version == o.Version && x.Kind == o.Kind
}
// An attempt to order things to help k8s, e.g.
// a Service should come before things that refer to it.
// Namespace should be first.
// In some cases order just specified to provide determinism.
var orderFirst = []string{
"Namespace",
"ResourceQuota",
"StorageClass",
"CustomResourceDefinition",
"MutatingWebhookConfiguration",
"ServiceAccount",
"PodSecurityPolicy",
"Role",
"ClusterRole",
"RoleBinding",
"ClusterRoleBinding",
"ConfigMap",
"Secret",
"Service",
"LimitRange",
"PriorityClass",
"Deployment",
"StatefulSet",
"CronJob",
"PodDisruptionBudget",
}
var orderLast = []string{
"ValidatingWebhookConfiguration",
}
var typeOrders = func() map[string]int {
m := map[string]int{}
for i, n := range orderFirst {
m[n] = -len(orderFirst) + i
}
for i, n := range orderLast {
m[n] = 1 + i
}
return m
}()
// IsLessThan returns true if self is less than the argument.
func (x Gvk) IsLessThan(o Gvk) bool {
indexI := typeOrders[x.Kind]
indexJ := typeOrders[o.Kind]
if indexI != indexJ {
return indexI < indexJ
}
return x.String() < o.String()
}
// IsSelected returns true if `selector` selects `x`; otherwise, false.
// If `selector` and `x` are the same, return true.
// If `selector` is nil, it is considered a wildcard match, returning true.
// If selector fields are empty, they are considered wildcards matching
// anything in the corresponding fields, e.g.
//
// this item:
// <Group: "extensions", Version: "v1beta1", Kind: "Deployment">
//
// is selected by
// <Group: "", Version: "", Kind: "Deployment">
//
// but rejected by
// <Group: "apps", Version: "", Kind: "Deployment">
//
func (x Gvk) IsSelected(selector *Gvk) bool {
if selector == nil {
return true
}
if len(selector.Group) > 0 {
if x.Group != selector.Group {
return false
}
}
if len(selector.Version) > 0 {
if x.Version != selector.Version {
return false
}
}
if len(selector.Kind) > 0 {
if x.Kind != selector.Kind {
return false
}
}
return true
}
var notNamespaceableKinds = []string{
"APIService",
"CSIDriver",
"CSINode",
"CertificateSigningRequest",
"ClusterRole",
"ClusterRoleBinding",
"ComponentStatus",
"CustomResourceDefinition",
"MutatingWebhookConfiguration",
"Namespace",
"Node",
"PersistentVolume",
"PodSecurityPolicy",
"PodSecurityPolicy",
"PriorityClass",
"RuntimeClass",
"SelfSubjectAccessReview",
"SelfSubjectRulesReview",
"StorageClass",
"SubjectAccessReview",
"TokenReview",
"ValidatingWebhookConfiguration",
"VolumeAttachment",
}
// IsNamespaceableKind returns true if x is a namespaceable Gvk
// Implements https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#not-all-objects-are-in-a-namespace
func (x Gvk) IsNamespaceableKind() bool {
for _, k := range notNamespaceableKinds {
if k == x.Kind {
return false
}
}
return true
}

View File

@@ -1,216 +0,0 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gvk
import "testing"
var equalsTests = []struct {
x1 Gvk
x2 Gvk
}{
{Gvk{Group: "a", Version: "b", Kind: "c"},
Gvk{Group: "a", Version: "b", Kind: "c"}},
{Gvk{Version: "b", Kind: "c"},
Gvk{Version: "b", Kind: "c"}},
{Gvk{Kind: "c"},
Gvk{Kind: "c"}},
}
func TestEquals(t *testing.T) {
for _, hey := range equalsTests {
if !hey.x1.Equals(hey.x2) {
t.Fatalf("%v should equal %v", hey.x1, hey.x2)
}
}
}
var lessThanTests = []struct {
x1 Gvk
x2 Gvk
}{
{Gvk{Group: "a", Version: "b", Kind: "CustomResourceDefinition"},
Gvk{Group: "a", Version: "b", Kind: "RoleBinding"}},
{Gvk{Group: "a", Version: "b", Kind: "Namespace"},
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
{Gvk{Group: "a", Version: "b", Kind: "a"},
Gvk{Group: "a", Version: "b", Kind: "b"}},
{Gvk{Group: "a", Version: "b", Kind: "Namespace"},
Gvk{Group: "a", Version: "c", Kind: "Namespace"}},
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
{Gvk{Group: "b", Version: "c", Kind: "Namespace"},
Gvk{Group: "a", Version: "c", Kind: "ClusterRole"}},
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
{Gvk{Group: "a", Version: "d", Kind: "Namespace"},
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
{Gvk{Group: "a", Version: "b", Kind: orderFirst[len(orderFirst)-1]},
Gvk{Group: "a", Version: "b", Kind: orderLast[0]}},
{Gvk{Group: "a", Version: "b", Kind: orderFirst[len(orderFirst)-1]},
Gvk{Group: "a", Version: "b", Kind: "CustomKindX"}},
{Gvk{Group: "a", Version: "b", Kind: "CustomKindX"},
Gvk{Group: "a", Version: "b", Kind: orderLast[0]}},
{Gvk{Group: "a", Version: "b", Kind: "CustomKindA"},
Gvk{Group: "a", Version: "b", Kind: "CustomKindB"}},
{Gvk{Group: "a", Version: "b", Kind: "CustomKindX"},
Gvk{Group: "a", Version: "b", Kind: "ValidatingWebhookConfiguration"}},
{Gvk{Group: "a", Version: "b", Kind: "APIService"},
Gvk{Group: "a", Version: "b", Kind: "ValidatingWebhookConfiguration"}},
{Gvk{Group: "a", Version: "b", Kind: "Service"},
Gvk{Group: "a", Version: "b", Kind: "APIService"}},
}
func TestIsLessThan1(t *testing.T) {
for _, hey := range lessThanTests {
if !hey.x1.IsLessThan(hey.x2) {
t.Fatalf("%v should be less than %v", hey.x1, hey.x2)
}
if hey.x2.IsLessThan(hey.x1) {
t.Fatalf("%v should not be less than %v", hey.x2, hey.x1)
}
}
}
var stringTests = []struct {
x Gvk
s string
}{
{Gvk{}, "~G_~V_~K"},
{Gvk{Kind: "k"}, "~G_~V_k"},
{Gvk{Version: "v"}, "~G_v_~K"},
{Gvk{Version: "v", Kind: "k"}, "~G_v_k"},
{Gvk{Group: "g"}, "g_~V_~K"},
{Gvk{Group: "g", Kind: "k"}, "g_~V_k"},
{Gvk{Group: "g", Version: "v"}, "g_v_~K"},
{Gvk{Group: "g", Version: "v", Kind: "k"}, "g_v_k"},
}
func TestString(t *testing.T) {
for _, hey := range stringTests {
if hey.x.String() != hey.s {
t.Fatalf("bad string for %v '%s'", hey.x, hey.s)
}
}
}
func TestSelectByGVK(t *testing.T) {
type testCase struct {
description string
in Gvk
filter *Gvk
expected bool
}
testCases := []testCase{
{
description: "nil filter",
in: Gvk{},
filter: nil,
expected: true,
},
{
description: "gvk matches",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
expected: true,
},
{
description: "group doesn't matches",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "group2",
Version: "version1",
Kind: "kind1",
},
expected: false,
},
{
description: "version doesn't matches",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "group1",
Version: "version2",
Kind: "kind1",
},
expected: false,
},
{
description: "kind doesn't matches",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "group1",
Version: "version1",
Kind: "kind2",
},
expected: false,
},
{
description: "no version in filter",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "group1",
Version: "",
Kind: "kind1",
},
expected: true,
},
{
description: "only kind is set in filter",
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &Gvk{
Group: "",
Version: "",
Kind: "kind1",
},
expected: true,
},
}
for _, tc := range testCases {
filtered := tc.in.IsSelected(tc.filter)
if filtered != tc.expected {
t.Fatalf("unexpected filter result for test case: %v", tc.description)
}
}
}

View File

@@ -5,8 +5,8 @@
package ifc
import (
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
)
// Validator provides functions to validate annotations and labels
@@ -55,8 +55,8 @@ type Kunstructured interface {
GetMap(path string) (map[string]interface{}, error)
MarshalJSON() ([]byte, error)
UnmarshalJSON([]byte) error
GetGvk() gvk.Gvk
SetGvk(gvk.Gvk)
GetGvk() resid.Gvk
SetGvk(resid.Gvk)
GetKind() string
GetName() string
SetName(string)

View File

@@ -6,7 +6,7 @@ package inventory
import (
"encoding/json"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
)
//Refs is a reference map. Each key is the id

View File

@@ -19,7 +19,7 @@ package inventory
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
)
func makeRefs() (Refs, Refs) {

View File

@@ -1,257 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package kusttest_test
import (
"fmt"
"path/filepath"
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer"
"sigs.k8s.io/kustomize/v3/pkg/loader"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/target"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"sigs.k8s.io/kustomize/v3/types"
)
// KustTestHarness helps test kustomization generation and transformation.
type KustTestHarness struct {
t *testing.T
rf *resmap.Factory
ldr loadertest.FakeLoader
pl *plugins.Loader
}
func NewKustTestHarness(t *testing.T, path string) *KustTestHarness {
return NewKustTestHarnessFull(
t, path, loader.RestrictionRootOnly, plugins.DefaultPluginConfig())
}
func NewKustTestPluginHarness(t *testing.T, path string) *KustTestHarness {
return NewKustTestHarnessFull(
t, path, loader.RestrictionRootOnly, plugins.ActivePluginConfig())
}
func NewKustTestNoLoadRestrictorHarness(t *testing.T, path string) *KustTestHarness {
return NewKustTestHarnessFull(
t, path, loader.RestrictionNone, plugins.DefaultPluginConfig())
}
func NewKustTestHarnessFull(
t *testing.T, path string,
lr loader.LoadRestrictorFunc, pc *types.PluginConfig) *KustTestHarness {
rf := resmap.NewFactory(resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl()), transformer.NewFactoryImpl())
return &KustTestHarness{
t: t,
rf: rf,
ldr: loadertest.NewFakeLoaderWithRestrictor(lr, path),
pl: plugins.NewLoader(pc, rf)}
}
func (th *KustTestHarness) MakeKustTarget() *target.KustTarget {
kt, err := target.NewKustTarget(
th.ldr, validators.MakeFakeValidator(), th.rf,
transformer.NewFactoryImpl(), th.pl)
if err != nil {
th.t.Fatalf("Unexpected construction error %v", err)
}
return kt
}
func (th *KustTestHarness) WriteF(dir string, content string) {
err := th.ldr.AddFile(dir, []byte(content))
if err != nil {
th.t.Fatalf("failed write to %s; %v", dir, err)
}
}
func (th *KustTestHarness) WriteK(dir string, content string) {
th.WriteF(
filepath.Join(
dir,
pgmconfig.DefaultKustomizationFileName()), `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
`+content)
}
func (th *KustTestHarness) RF() *resource.Factory {
return th.rf.RF()
}
func (th *KustTestHarness) FromMap(m map[string]interface{}) *resource.Resource {
return th.rf.RF().FromMap(m)
}
func (th *KustTestHarness) FromMapAndOption(m map[string]interface{}, args *types.GeneratorArgs, option *types.GeneratorOptions) *resource.Resource {
return th.rf.RF().FromMapAndOption(m, args, option)
}
func (th *KustTestHarness) WriteDefaultConfigs(fName string) {
m := defaultconfig.GetDefaultFieldSpecsAsMap()
var content []byte
for _, tCfg := range m {
content = append(content, []byte(tCfg)...)
}
err := th.ldr.AddFile(fName, content)
if err != nil {
th.t.Fatalf("unable to add file %s", fName)
}
}
func (th *KustTestHarness) LoadAndRunGenerator(
config string) resmap.ResMap {
res, err := th.rf.RF().FromBytes([]byte(config))
if err != nil {
th.t.Fatalf("Err: %v", err)
}
g, err := th.pl.LoadGenerator(
th.ldr, validators.MakeFakeValidator(), res)
if err != nil {
th.t.Fatalf("Err: %v", err)
}
rm, err := g.Generate()
if err != nil {
th.t.Fatalf("Err: %v", err)
}
return rm
}
func (th *KustTestHarness) LoadAndRunTransformer(
config, input string) resmap.ResMap {
resMap, err := th.RunTransformer(config, input)
if err != nil {
th.t.Fatalf("Err: %v", err)
}
return resMap
}
func (th *KustTestHarness) ErrorFromLoadAndRunTransformer(
config, input string) error {
_, err := th.RunTransformer(config, input)
return err
}
func (th *KustTestHarness) RunTransformer(
config, input string) (resmap.ResMap, error) {
resMap, err := th.rf.NewResMapFromBytes([]byte(input))
if err != nil {
th.t.Fatalf("Err: %v", err)
}
return th.RunTransformerFromResMap(config, resMap)
}
func (th *KustTestHarness) RunTransformerFromResMap(
config string, resMap resmap.ResMap) (resmap.ResMap, error) {
transConfig, err := th.rf.RF().FromBytes([]byte(config))
if err != nil {
th.t.Fatalf("Err: %v", err)
}
g, err := th.pl.LoadTransformer(
th.ldr, validators.MakeFakeValidator(), transConfig)
if err != nil {
return nil, err
}
err = g.Transform(resMap)
return resMap, err
}
func tabToSpace(input string) string {
var result []string
for _, i := range input {
if i == 9 {
result = append(result, " ")
} else {
result = append(result, string(i))
}
}
return strings.Join(result, "")
}
func convertToArray(x string) ([]string, int) {
a := strings.Split(strings.TrimSuffix(x, "\n"), "\n")
maxLen := 0
for i, v := range a {
z := tabToSpace(v)
if len(z) > maxLen {
maxLen = len(z)
}
a[i] = z
}
return a, maxLen
}
func hint(a, b string) string {
if a == b {
return " "
}
return "X"
}
func (th *KustTestHarness) AssertActualEqualsExpected(
m resmap.ResMap, expected string) {
th.AssertActualEqualsExpectedWithTweak(m, nil, expected)
}
func (th *KustTestHarness) AssertActualEqualsExpectedWithTweak(
m resmap.ResMap, tweaker func([]byte) []byte, expected string) {
if m == nil {
th.t.Fatalf("Map should not be nil.")
}
// Ignore leading linefeed in expected value
// to ease readability of tests.
if len(expected) > 0 && expected[0] == 10 {
expected = expected[1:]
}
actual, err := m.AsYaml()
if err != nil {
th.t.Fatalf("Unexpected err: %v", err)
}
if tweaker != nil {
actual = tweaker(actual)
}
if string(actual) != expected {
th.reportDiffAndFail(actual, expected)
}
}
// Pretty printing of file differences.
func (th *KustTestHarness) reportDiffAndFail(actual []byte, expected string) {
sE, maxLen := convertToArray(expected)
sA, _ := convertToArray(string(actual))
fmt.Println("===== ACTUAL BEGIN ========================================")
fmt.Print(string(actual))
fmt.Println("===== ACTUAL END ==========================================")
format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4)
limit := 0
if len(sE) < len(sA) {
limit = len(sE)
} else {
limit = len(sA)
}
fmt.Printf(format, " ", "EXPECTED", "ACTUAL")
fmt.Printf(format, " ", "--------", "------")
for i := 0; i < limit; i++ {
fmt.Printf(format, hint(sE[i], sA[i]), sE[i], sA[i])
}
if len(sE) < len(sA) {
for i := len(sE); i < len(sA); i++ {
fmt.Printf(format, "X", "", sA[i])
}
} else {
for i := len(sA); i < len(sE); i++ {
fmt.Printf(format, "X", sE[i], "")
}
}
th.t.Fatalf("Expected not equal to actual")
}

View File

@@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
)

View File

@@ -25,7 +25,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"

View File

@@ -5,7 +5,7 @@
package loader
import (
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
)

View File

@@ -7,7 +7,7 @@ import (
"fmt"
"github.com/spf13/pflag"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
)
//go:generate stringer -type=loadRestrictions

View File

@@ -20,7 +20,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
)
func TestRestrictionNone(t *testing.T) {

View File

@@ -16,7 +16,7 @@ limitations under the License.
package patch
import "sigs.k8s.io/kustomize/v3/types"
import "sigs.k8s.io/kustomize/v3/api/types"
// Append appends a slice of patch paths to a PatchStrategicMerge slice
func Append(patches []types.PatchStrategicMerge, paths ...string) []types.PatchStrategicMerge {

View File

@@ -6,7 +6,7 @@ package patch
import (
"testing"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/kustomize/v3/api/types"
)
func buildPatchStrategicMergeSlice(patchStrings []string) []types.PatchStrategicMerge {

View File

@@ -10,8 +10,8 @@ import (
"runtime"
"github.com/spf13/pflag"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
"sigs.k8s.io/kustomize/v3/types"
)
const (

View File

@@ -13,9 +13,9 @@ import (
"strings"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/yaml"
)

View File

@@ -8,12 +8,12 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"sigs.k8s.io/kustomize/v3/types"
)
func TestExecPluginConfig(t *testing.T) {

View File

@@ -11,12 +11,11 @@ import (
"strings"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
)
type Loader struct {
@@ -131,7 +130,7 @@ func (l *Loader) loadAndConfigurePlugin(
return c, nil
}
func (l *Loader) makeBuiltinPlugin(r gvk.Gvk) (resmap.Configurable, error) {
func (l *Loader) makeBuiltinPlugin(r resid.Gvk) (resmap.Configurable, error) {
bpt := GetBuiltinPluginType(r.Kind)
if f, ok := GeneratorFactories[bpt]; ok {
return f(), nil

View File

@@ -4,6 +4,7 @@
package plugins_test
import (
"sigs.k8s.io/kustomize/v3/api/kusttest"
"testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
@@ -12,7 +13,6 @@ import (
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"sigs.k8s.io/kustomize/v3/pluglib"
)
const (
@@ -43,7 +43,7 @@ port: "12345"
)
func TestLoader(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(

View File

@@ -1,129 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package resid
import (
"strings"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
// ResId is an identifier of a k8s resource object.
type ResId struct {
// Gvk of the resource.
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
// Name of the resource before transformation.
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Namespace the resource belongs to.
// An untransformed resource has no namespace.
// A fully transformed resource has the namespace
// from the top most overlay.
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}
// NewResIdWithNamespace creates new ResId
// in a given namespace.
func NewResIdWithNamespace(k gvk.Gvk, n, ns string) ResId {
return ResId{Gvk: k, Name: n, Namespace: ns}
}
// NewResId creates new ResId.
func NewResId(k gvk.Gvk, n string) ResId {
return ResId{Gvk: k, Name: n}
}
// NewResIdKindOnly creates a new ResId.
func NewResIdKindOnly(k string, n string) ResId {
return ResId{Gvk: gvk.FromKind(k), Name: n}
}
const (
noNamespace = "~X"
noName = "~N"
separator = "|"
TotallyNotANamespace = "_non_namespaceable_"
DefaultNamespace = "default"
)
// String of ResId based on GVK, name and prefix
func (id ResId) String() string {
ns := id.Namespace
if ns == "" {
ns = noNamespace
}
nm := id.Name
if nm == "" {
nm = noName
}
return strings.Join(
[]string{id.Gvk.String(), ns, nm}, separator)
}
func FromString(s string) ResId {
values := strings.Split(s, separator)
g := gvk.FromString(values[0])
ns := values[1]
if ns == noNamespace {
ns = ""
}
nm := values[2]
if nm == noName {
nm = ""
}
return ResId{
Gvk: g,
Namespace: ns,
Name: nm,
}
}
// GvknString of ResId based on GVK and name
func (id ResId) GvknString() string {
return id.Gvk.String() + separator + id.Name
}
// GvknEquals returns true if the other id matches
// Group/Version/Kind/name.
func (id ResId) GvknEquals(o ResId) bool {
return id.Name == o.Name && id.Gvk.Equals(o.Gvk)
}
// Equals returns true if the other id matches
// namespace/Group/Version/Kind/name.
func (id ResId) Equals(o ResId) bool {
return id.IsNsEquals(o) && id.GvknEquals(o)
}
// IsNsEquals returns true if the id is in
// the same effective namespace.
func (id ResId) IsNsEquals(o ResId) bool {
return id.EffectiveNamespace() == o.EffectiveNamespace()
}
// IsInDefaultNs returns true if id is a namespaceable
// ResId and the Namespace is either not set or set
// to DefaultNamespace.
func (id ResId) IsInDefaultNs() bool {
return id.IsNamespaceableKind() && id.isPutativelyDefaultNs()
}
func (id ResId) isPutativelyDefaultNs() bool {
return id.Namespace == "" || id.Namespace == DefaultNamespace
}
// EffectiveNamespace returns a non-ambiguous, non-empty
// namespace for use in reporting and equality tests.
func (id ResId) EffectiveNamespace() string {
// The order of these checks matters.
if !id.IsNamespaceableKind() {
return TotallyNotANamespace
}
if id.isPutativelyDefaultNs() {
return DefaultNamespace
}
return id.Namespace
}

View File

@@ -1,425 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package resid
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
var stringTests = []struct {
x ResId
s string
}{
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
"g_v_k|ns|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
Name: "nm",
},
"~G_v_k|ns|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
"~G_~V_k|ns|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|ns|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|~X|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|~X|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
},
"~G_~V_~K|~X|~N",
},
{
ResId{
Gvk: gvk.Gvk{},
},
"~G_~V_~K|~X|~N",
},
{
ResId{},
"~G_~V_~K|~X|~N",
},
}
func TestString(t *testing.T) {
for _, hey := range stringTests {
if hey.x.String() != hey.s {
t.Fatalf("Actual: %v, Expected: '%s'", hey.x, hey.s)
}
}
}
var gvknStringTests = []struct {
x ResId
s string
}{
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
"g_v_k|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
Name: "nm",
},
"~G_v_k|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
"~G_~V_k|nm",
},
{
ResId{
Namespace: "ns",
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
Name: "nm",
},
"~G_~V_~K|nm",
},
{
ResId{
Gvk: gvk.Gvk{},
},
"~G_~V_~K|",
},
{
ResId{
Gvk: gvk.Gvk{},
},
"~G_~V_~K|",
},
{
ResId{},
"~G_~V_~K|",
},
}
func TestGvknString(t *testing.T) {
for _, hey := range gvknStringTests {
if hey.x.GvknString() != hey.s {
t.Fatalf("Actual: %s, Expected: '%s'", hey.x.GvknString(), hey.s)
}
}
}
func TestEquals(t *testing.T) {
var GvknEqualsTest = []struct {
id1 ResId
id2 ResId
gVknResult bool
nsEquals bool
equals bool
}{
{
id1: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
id2: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
gVknResult: true,
nsEquals: true,
equals: true,
},
{
id1: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
id2: ResId{
Namespace: "Z",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
gVknResult: true,
nsEquals: false,
equals: false,
},
{
id1: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
id2: ResId{
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
gVknResult: true,
nsEquals: false,
equals: false,
},
{
id1: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
Name: "nm",
},
id2: ResId{
Namespace: "Z",
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
Name: "nm",
},
gVknResult: true,
nsEquals: false,
equals: false,
},
{
id1: ResId{
Namespace: "X",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
id2: ResId{
Namespace: "Z",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
gVknResult: true,
nsEquals: false,
equals: false,
},
{
id1: ResId{
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
id2: ResId{
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm2",
},
gVknResult: false,
nsEquals: true,
equals: false,
},
{
id1: ResId{
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
id2: ResId{
Gvk: gvk.Gvk{Kind: "Node"},
Name: "nm",
},
gVknResult: false,
nsEquals: false,
equals: false,
},
{
id1: ResId{
Gvk: gvk.Gvk{Kind: "Node"},
Name: "nm1",
},
id2: ResId{
Gvk: gvk.Gvk{Kind: "Node"},
Name: "nm2",
},
gVknResult: false,
nsEquals: true,
equals: false,
},
{
id1: ResId{
Namespace: "default",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm1",
},
id2: ResId{
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm2",
},
gVknResult: false,
nsEquals: true,
equals: false,
},
{
id1: ResId{
Namespace: "X",
Name: "nm",
},
id2: ResId{
Namespace: "Z",
Name: "nm",
},
gVknResult: true,
nsEquals: false,
equals: false,
},
}
for _, tst := range GvknEqualsTest {
if tst.id1.GvknEquals(tst.id2) != tst.gVknResult {
t.Fatalf("GvknEquals(\n%v,\n%v\n) should be %v",
tst.id1, tst.id2, tst.gVknResult)
}
if tst.id1.IsNsEquals(tst.id2) != tst.nsEquals {
t.Fatalf("IsNsEquals(\n%v,\n%v\n) should be %v",
tst.id1, tst.id2, tst.equals)
}
if tst.id1.Equals(tst.id2) != tst.equals {
t.Fatalf("Equals(\n%v,\n%v\n) should be %v",
tst.id1, tst.id2, tst.equals)
}
}
}
var ids = []ResId{
{
Namespace: "ns",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
{
Namespace: "ns",
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
Name: "nm",
},
{
Namespace: "ns",
Gvk: gvk.Gvk{Kind: "k"},
Name: "nm",
},
{
Namespace: "ns",
Gvk: gvk.Gvk{},
Name: "nm",
},
{
Gvk: gvk.Gvk{},
Name: "nm",
},
{
Gvk: gvk.Gvk{},
Name: "nm",
},
{
Gvk: gvk.Gvk{},
},
}
func TestFromString(t *testing.T) {
for _, id := range ids {
newId := FromString(id.String())
if newId != id {
t.Fatalf("Actual: %v, Expected: '%s'", newId, id)
}
}
}
func TestEffectiveNamespace(t *testing.T) {
var test = []struct {
id ResId
expected string
}{
{
id: ResId{
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "Node"},
Name: "nm",
},
expected: TotallyNotANamespace,
},
{
id: ResId{
Namespace: "foo",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "Node"},
Name: "nm",
},
expected: TotallyNotANamespace,
},
{
id: ResId{
Namespace: "foo",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
expected: "foo",
},
{
id: ResId{
Namespace: "",
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
expected: DefaultNamespace,
},
{
id: ResId{
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
Name: "nm",
},
expected: DefaultNamespace,
},
}
for _, tst := range test {
if actual := tst.id.EffectiveNamespace(); actual != tst.expected {
t.Fatalf("EffectiveNamespace was %s, expected %s",
actual, tst.expected)
}
}
}

View File

@@ -5,10 +5,10 @@ package resmap
import (
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/kusterr"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
)
// Factory makes instances of ResMap.

View File

@@ -6,18 +6,18 @@ package resmap_test
import (
"encoding/base64"
"reflect"
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
"sigs.k8s.io/kustomize/v3/api/kv"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/kv"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/loader"
. "sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"sigs.k8s.io/kustomize/v3/types"
)
func TestFromFile(t *testing.T) {
@@ -108,7 +108,7 @@ metadata:
}
}
var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
var cmap = resid.Gvk{Version: "v1", Kind: "ConfigMap"}
func TestNewFromConfigMaps(t *testing.T) {
type testCase struct {

View File

@@ -19,7 +19,7 @@ package resmap
import (
"sort"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
)
// IdSlice implements the sort interface.

View File

@@ -21,7 +21,7 @@ import (
"sort"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
)
func TestLess(t *testing.T) {

View File

@@ -11,10 +11,10 @@ import (
"regexp"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/yaml"
)

View File

@@ -9,12 +9,12 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/resid"
. "sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
)
var rf = resource.NewFactory(

View File

@@ -4,11 +4,11 @@
package resmap_test
import (
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/types"
)
func setupRMForPatchTargets(t *testing.T) resmap.ResMap {
@@ -81,7 +81,7 @@ func TestFindPatchTargets(t *testing.T) {
},
{
target: types.Selector{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Kind1",
},
Name: "name.*",
@@ -116,7 +116,7 @@ func TestFindPatchTargets(t *testing.T) {
target: types.Selector{
Namespace: "default",
Name: "name.*",
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Kind1",
},
},

View File

@@ -6,7 +6,7 @@ package resmaptest_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
)

View File

@@ -9,9 +9,9 @@ import (
"log"
"strings"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/kusterr"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/types"
)
// Factory makes instances of Resource.

View File

@@ -20,9 +20,9 @@ import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
. "sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
)
func TestSliceFromPatches(t *testing.T) {

View File

@@ -8,9 +8,9 @@ import (
"reflect"
"strings"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/yaml"
)

View File

@@ -20,11 +20,10 @@ import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resid"
. "sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/types"
)
var factory = NewFactory(
@@ -99,11 +98,11 @@ func TestResourceId(t *testing.T) {
{
in: testConfigMap,
id: resid.NewResIdWithNamespace(
gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, "winnie", "hundred-acre-wood"),
resid.Gvk{Version: "v1", Kind: "ConfigMap"}, "winnie", "hundred-acre-wood"),
},
{
in: testDeployment,
id: resid.NewResId(gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}, "pooh"),
id: resid.NewResId(resid.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}, "pooh"),
},
}
for _, test := range tests {
@@ -122,12 +121,12 @@ func TestDeepCopy(t *testing.T) {
"name": "pooh",
},
})
r.AppendRefBy(resid.NewResId(gvk.Gvk{Group: "somegroup", Kind: "MyKind"}, "random"))
r.AppendRefBy(resid.NewResId(resid.Gvk{Group: "somegroup", Kind: "MyKind"}, "random"))
var1 := types.Var{
Name: "SERVICE_ONE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"},
}
r.AppendRefVarName(var1)

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func writeMediumBase(th *kusttest_test.KustTestHarness) {

View File

@@ -20,7 +20,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/loader"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
)

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
// Here is a structure of a kustomization of two components, component1

View File

@@ -11,9 +11,7 @@ import (
"regexp"
"testing"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
// This is an example of using a helm chart as a base,
@@ -30,13 +28,13 @@ import (
// TODO: Download and inflate the chart, and check that
// in for the test.
func TestChartInflatorPlugin(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildExecPlugin(
"someteam.example.com", "v1", "ChartInflator")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
th.WriteK("/app", `
generators:
- chartInflator.yaml

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
const httpsService = `
@@ -303,7 +303,7 @@ func writePatchingTransformersRaw(th *kusttest_test.KustTestHarness) {
// respect to the overlays, and avoids the need to relax load
// restrictions on file paths reaching outside the `dev` and
// `prod` kustomization roots. I.e. with bases tests can use
// NewKustTestHarness instead of NewKustTestNoLoadRestrictorHarness.
// NewKustTestHarness instead of NewKustTestHarnessNoLoadRestrictor.
//
// Using transformer plugins from _bases_ means the plugin config
// must be self-contained, i.e. the config may not have fields that
@@ -404,7 +404,7 @@ metadata:
`
func TestComplexComposition_Dev_SuccessWithRawTransformers(t *testing.T) {
th := kusttest_test.NewKustTestNoLoadRestrictorHarness(t, "/app/dev")
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/dev")
writeStatefulSetBase(th)
writePatchingTransformersRaw(th)
th.WriteK("/app/dev", `
@@ -513,7 +513,7 @@ metadata:
`
func TestComplexComposition_Prod_SuccessWithRawTransformers(t *testing.T) {
th := kusttest_test.NewKustTestNoLoadRestrictorHarness(t, "/app/prod")
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/prod")
writeStatefulSetBase(th)
writePatchingTransformersRaw(th)
th.WriteK("/app/prod", `

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
// Generate a Secret and a ConfigMap from the same data

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func writeBaseWithCrd(th *kusttest_test.KustTestHarness) {

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeBaseReferencingCustomConfig(th *kusttest_test.KustTestHarness) {

View File

@@ -6,21 +6,20 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
// Demo custom configuration of a builtin transformation.
// This is a NamePrefixer that only touches Deployments
// and Services.
func TestCustomNamePrefixer(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
"builtin", "", "PrefixSuffixTransformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
th.WriteK("/app", `
resources:
@@ -103,7 +102,7 @@ metadata:
// Demo custom configuration as a base.
func TestReusableCustomNamePrefixer(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -111,7 +110,7 @@ func TestReusableCustomNamePrefixer(t *testing.T) {
tc.BuildGoPlugin(
"builtin", "", "LabelTransformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app/foo")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/foo")
// This kustomization file contains resources that
// all happen to be plugin configurations. This makes

View File

@@ -9,8 +9,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
const patchAddProbe = `
@@ -232,7 +231,7 @@ func definePatchDirStructure(th *kusttest_test.KustTestHarness) {
// Fails due to file load restrictor.
func TestIssue1251_Patches_ProdVsDev_Failure(t *testing.T) {
th := kusttest_test.NewKustTestPluginHarness(t, "/app/prod")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/prod")
definePatchDirStructure(th)
th.WriteK("/app/prod", `
@@ -305,7 +304,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.NewKustTestNoLoadRestrictorHarness(t, "/app/prod")
th := kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/prod")
definePatchDirStructure(th)
th.WriteK("/app/prod", `
@@ -321,7 +320,7 @@ patchesStrategicMerge:
}
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
th = kusttest_test.NewKustTestNoLoadRestrictorHarness(t, "/app/dev")
th = kusttest_test.NewKustTestHarnessNoLoadRestrictor(t, "/app/dev")
definePatchDirStructure(th)
th.WriteK("/app/dev", `
@@ -340,13 +339,13 @@ patchesStrategicMerge:
}
func TestIssue1251_Plugins_ProdVsDev(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
"builtin", "", "PatchJson6902Transformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app/prod")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/prod")
defineTransformerDirStructure(th)
th.WriteK("/app/prod", `
resources:
@@ -362,7 +361,7 @@ transformers:
}
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
th = kusttest_test.NewKustTestPluginHarness(t, "/app/dev")
th = kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/dev")
defineTransformerDirStructure(th)
th.WriteK("/app/dev", `
resources:
@@ -380,13 +379,13 @@ transformers:
}
func TestIssue1251_Plugins_Local(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
"builtin", "", "PatchJson6902Transformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app/composite")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/composite")
writeDeploymentBase(th)
writeJsonTransformerPluginConfig(
@@ -430,13 +429,13 @@ jsonOp: '%s'
// Remote in the sense that they are bundled in a different kustomization.
func TestIssue1251_Plugins_Bundled(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
"builtin", "", "PatchJson6902Transformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app/composite")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/composite")
writeDeploymentBase(th)
th.WriteK("/app/patches", `

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
// Here's a structure of two kustomizations,

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeCommonFileForExtendedPatchTest(th *kusttest_test.KustTestHarness) {

View File

@@ -20,7 +20,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestSimpleBase(t *testing.T) {

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestSecretGenerator(t *testing.T) {

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeResourcesForPatchTest(th *kusttest_test.KustTestHarness) {

View File

@@ -13,6 +13,7 @@ import (
"strings"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/accumulator"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
@@ -21,7 +22,6 @@ import (
"sigs.k8s.io/kustomize/v3/pkg/transformers"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/plugin/builtin"
"sigs.k8s.io/kustomize/v3/types"
"sigs.k8s.io/yaml"
)

View File

@@ -4,10 +4,10 @@
package target
import (
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/types"
)
// Functions dedicated to configuring the builtin

View File

@@ -9,15 +9,15 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/api/kusttest"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/api/types"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource"
. "sigs.k8s.io/kustomize/v3/pkg/target"
"sigs.k8s.io/kustomize/v3/pkg/validators"
"sigs.k8s.io/kustomize/v3/types"
)
const (
@@ -281,7 +281,7 @@ var someVars = []types.Var{
Name: "AWARD",
ObjRef: types.Target{
APIVersion: "v7",
Gvk: gvk.Gvk{Kind: "Service"},
Gvk: resid.Gvk{Kind: "Service"},
Name: "nobelPrize"},
FieldRef: types.FieldSelector{FieldPath: "some.arbitrary.path"},
},
@@ -289,21 +289,21 @@ var someVars = []types.Var{
Name: "BIRD",
ObjRef: types.Target{
APIVersion: "v300",
Gvk: gvk.Gvk{Kind: "Service"},
Gvk: resid.Gvk{Kind: "Service"},
Name: "heron"},
FieldRef: types.FieldSelector{FieldPath: "metadata.name"},
},
{
Name: "FRUIT",
ObjRef: types.Target{
Gvk: gvk.Gvk{Kind: "Service"},
Gvk: resid.Gvk{Kind: "Service"},
Name: "apple"},
FieldRef: types.FieldSelector{FieldPath: "metadata.name"},
},
{
Name: "VEGETABLE",
ObjRef: types.Target{
Gvk: gvk.Gvk{Kind: "Leafy"},
Gvk: resid.Gvk{Kind: "Leafy"},
Name: "kale"},
FieldRef: types.FieldSelector{FieldPath: "metadata.name"},
},

View File

@@ -20,7 +20,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeCommonFileForMultiplePatchTest(th *kusttest_test.KustTestHarness) {

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestNamespacedGenerator(t *testing.T) {

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestNamespacedSecrets(t *testing.T) {

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestNullValues(t *testing.T) {

View File

@@ -9,12 +9,10 @@ import (
"path/filepath"
"testing"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/filesys"
"sigs.k8s.io/kustomize/v3/api/filesys"
"sigs.k8s.io/kustomize/v3/api/kusttest"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/loader"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
@@ -24,7 +22,7 @@ import (
)
func TestPluginDir(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildExecPlugin(

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestPruneConfigMap(t *testing.T) {

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func writeBase(th *kusttest_test.KustTestHarness) {

View File

@@ -7,8 +7,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pluglib"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func writeDeployment(th *kusttest_test.KustTestHarness, path string) {
@@ -50,7 +49,7 @@ metadata:
}
func TestOrderedTransformers(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -59,7 +58,7 @@ func TestOrderedTransformers(t *testing.T) {
tc.BuildGoPlugin(
"someteam.example.com", "v1", "DatePrefixer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
th.WriteK("/app", `
resources:
- deployment.yaml
@@ -96,7 +95,7 @@ spec:
}
func TestPluginsNotEnabled(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -119,13 +118,13 @@ transformers:
}
func TestSedTransformer(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildExecPlugin(
"someteam.example.com", "v1", "SedTransformer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
th.WriteK("/app", `
resources:
- configmap.yaml
@@ -187,7 +186,7 @@ metadata:
}
func TestTransformedTransformers(t *testing.T) {
tc := pluglib.NewEnvForTest(t).Set()
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
@@ -196,7 +195,7 @@ func TestTransformedTransformers(t *testing.T) {
tc.BuildGoPlugin(
"someteam.example.com", "v1", "DatePrefixer")
th := kusttest_test.NewKustTestPluginHarness(t, "/app/overlay")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/overlay")
th.WriteK("/app/base", `
resources:

View File

@@ -6,7 +6,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeStatefulSetKustomization(th *kusttest_test.KustTestHarness) {

View File

@@ -19,7 +19,7 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func makeTransfomersImageBase(th *kusttest_test.KustTestHarness) {

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/api/kusttest"
)
func TestBasicVariableRef(t *testing.T) {

View File

@@ -5,10 +5,10 @@ package config
import (
"reflect"
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
func TestMakeDefaultConfig(t *testing.T) {
@@ -31,7 +31,7 @@ namePrefix:
expected := &TransformerConfig{
NamePrefix: []FieldSpec{
{
Gvk: gvk.Gvk{Kind: "SomeKind"},
Gvk: resid.Gvk{Kind: "SomeKind"},
Path: "nameprefix/path",
},
},

View File

@@ -18,12 +18,12 @@ package config
import (
"encoding/json"
"sigs.k8s.io/kustomize/v3/api/resid"
"strings"
"github.com/go-openapi/spec"
"github.com/pkg/errors"
"k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/yaml"
)
@@ -88,10 +88,10 @@ func makeConfigFromApiMap(m nameToApiMap) (*TransformerConfig, error) {
// TODO: Get Group and Version for CRD from the
// openAPI definition once
// "x-kubernetes-group-version-kind" is available in CRD
func makeGvkFromTypeName(n string) gvk.Gvk {
func makeGvkFromTypeName(n string) resid.Gvk {
names := strings.Split(n, ".")
kind := names[len(names)-1]
return gvk.Gvk{Kind: kind}
return resid.Gvk{Kind: kind}
}
func looksLikeAk8sType(properties myProperties) bool {
@@ -133,7 +133,7 @@ const (
// loadCrdIntoConfig loads a CRD spec into a TransformerConfig
func loadCrdIntoConfig(
theConfig *TransformerConfig, theGvk gvk.Gvk, theMap nameToApiMap,
theConfig *TransformerConfig, theGvk resid.Gvk, theMap nameToApiMap,
typeName string, path []string) (err error) {
api, ok := theMap[typeName]
if !ok {
@@ -174,7 +174,7 @@ func loadCrdIntoConfig(
}
err = theConfig.AddNamereferenceFieldSpec(
NameBackReferences{
Gvk: gvk.Gvk{Kind: kind, Version: version},
Gvk: resid.Gvk{Kind: kind, Version: version},
FieldSpecs: []FieldSpec{
makeFs(theGvk, append(path, propName, nameKey))},
})
@@ -192,7 +192,7 @@ func loadCrdIntoConfig(
return nil
}
func makeFs(in gvk.Gvk, path []string) FieldSpec {
func makeFs(in resid.Gvk, path []string) FieldSpec {
return FieldSpec{
CreateIfNotPresent: false,
Gvk: in,

View File

@@ -18,10 +18,10 @@ package config
import (
"reflect"
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
)
@@ -157,21 +157,21 @@ func makeLoader(t *testing.T) ifc.Loader {
func TestLoadCRDs(t *testing.T) {
nbrs := []NameBackReferences{
{
Gvk: gvk.Gvk{Kind: "Secret", Version: "v1"},
Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
FieldSpecs: []FieldSpec{
{
CreateIfNotPresent: false,
Gvk: gvk.Gvk{Kind: "MyKind"},
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/secretRef/name",
},
},
},
{
Gvk: gvk.Gvk{Kind: "Bee", Version: "v1beta1"},
Gvk: resid.Gvk{Kind: "Bee", Version: "v1beta1"},
FieldSpecs: []FieldSpec{
{
CreateIfNotPresent: false,
Gvk: gvk.Gvk{Kind: "MyKind"},
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/beeRef/name",
},
},

View File

@@ -18,9 +18,8 @@ package config
import (
"fmt"
"sigs.k8s.io/kustomize/v3/api/resid"
"strings"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
// FieldSpec completely specifies a kustomizable field in
@@ -42,7 +41,7 @@ import (
// create: true
// }
type FieldSpec struct {
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
resid.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
CreateIfNotPresent bool `json:"create,omitempty" yaml:"create,omitempty"`
}

View File

@@ -1,18 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package config
@@ -22,7 +9,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/api/resid"
)
func TestPathSlice(t *testing.T) {
@@ -61,19 +48,19 @@ var mergeTests = []struct {
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "pear"},
Gvk: resid.Gvk{Group: "pear"},
CreateIfNotPresent: false,
},
},
fsSlice{
{
Path: "home",
Gvk: gvk.Gvk{Group: "beans"},
Gvk: resid.Gvk{Group: "beans"},
CreateIfNotPresent: false,
},
},
@@ -81,17 +68,17 @@ var mergeTests = []struct {
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "pear"},
Gvk: resid.Gvk{Group: "pear"},
CreateIfNotPresent: false,
},
{
Path: "home",
Gvk: gvk.Gvk{Group: "beans"},
Gvk: resid.Gvk{Group: "beans"},
CreateIfNotPresent: false,
},
},
@@ -101,19 +88,19 @@ var mergeTests = []struct {
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "pear"},
Gvk: resid.Gvk{Group: "pear"},
CreateIfNotPresent: false,
},
},
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
},
@@ -121,12 +108,12 @@ var mergeTests = []struct {
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "pear"},
Gvk: resid.Gvk{Group: "pear"},
CreateIfNotPresent: false,
},
},
@@ -136,19 +123,19 @@ var mergeTests = []struct {
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: false,
},
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "pear"},
Gvk: resid.Gvk{Group: "pear"},
CreateIfNotPresent: false,
},
},
fsSlice{
{
Path: "whatever",
Gvk: gvk.Gvk{Group: "apple"},
Gvk: resid.Gvk{Group: "apple"},
CreateIfNotPresent: true,
},
},

View File

@@ -17,9 +17,8 @@ limitations under the License.
package config
import (
"sigs.k8s.io/kustomize/v3/api/resid"
"strings"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
// NameBackReferences is an association between a gvk.GVK and a list
@@ -51,7 +50,7 @@ import (
// (etc.)
// }
type NameBackReferences struct {
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
resid.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
FieldSpecs fsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"`
}

View File

@@ -18,22 +18,21 @@ package config
import (
"reflect"
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
func TestMergeAll(t *testing.T) {
fsSlice1 := []FieldSpec{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Pod",
},
Path: "path/to/a/name",
CreateIfNotPresent: false,
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Deployment",
},
Path: "another/path/to/some/name",
@@ -42,14 +41,14 @@ func TestMergeAll(t *testing.T) {
}
fsSlice2 := []FieldSpec{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Job",
},
Path: "morepath/to/name",
CreateIfNotPresent: false,
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "StatefulSet",
},
Path: "yet/another/path/to/a/name",
@@ -59,13 +58,13 @@ func TestMergeAll(t *testing.T) {
nbrsSlice1 := nbrSlice{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "ConfigMap",
},
FieldSpecs: fsSlice1,
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Secret",
},
FieldSpecs: fsSlice2,
@@ -73,13 +72,13 @@ func TestMergeAll(t *testing.T) {
}
nbrsSlice2 := nbrSlice{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "ConfigMap",
},
FieldSpecs: fsSlice1,
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Secret",
},
FieldSpecs: fsSlice2,
@@ -87,13 +86,13 @@ func TestMergeAll(t *testing.T) {
}
expected := nbrSlice{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "ConfigMap",
},
FieldSpecs: fsSlice1,
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "Secret",
},
FieldSpecs: fsSlice2,

View File

@@ -17,23 +17,22 @@ limitations under the License.
package config
import (
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"reflect"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
)
func TestAddNamereferenceFieldSpec(t *testing.T) {
cfg := &TransformerConfig{}
nbrs := NameBackReferences{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindA",
},
FieldSpecs: []FieldSpec{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindB",
},
Path: "path/to/a/field",
@@ -55,7 +54,7 @@ func TestAddFieldSpecs(t *testing.T) {
cfg := &TransformerConfig{}
fieldSpec := FieldSpec{
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindB"},
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
Path: "path/to/a/field",
CreateIfNotPresent: true,
}
@@ -93,12 +92,12 @@ func TestAddFieldSpecs(t *testing.T) {
func TestMerge(t *testing.T) {
nameReference := []NameBackReferences{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindA",
},
FieldSpecs: []FieldSpec{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindB",
},
Path: "path/to/a/field",
@@ -107,12 +106,12 @@ func TestMerge(t *testing.T) {
},
},
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindA",
},
FieldSpecs: []FieldSpec{
{
Gvk: gvk.Gvk{
Gvk: resid.Gvk{
Kind: "KindC",
},
Path: "path/to/a/field",
@@ -123,12 +122,12 @@ func TestMerge(t *testing.T) {
}
fieldSpecs := []FieldSpec{
{
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindB"},
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
Path: "path/to/a/field",
CreateIfNotPresent: true,
},
{
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindC"},
Gvk: resid.Gvk{Group: "GroupA", Kind: "KindC"},
Path: "path/to/a/field",
CreateIfNotPresent: true,
},

View File

@@ -6,10 +6,10 @@ package transformers
import (
"fmt"
"log"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resource"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
)
@@ -115,7 +115,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
func (o *nameReferenceTransformer) selectReferral(
oldName string,
referrer *resource.Resource,
target gvk.Gvk,
target resid.Gvk,
referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource) (interface{}, interface{}, error) {
@@ -146,7 +146,7 @@ func (o *nameReferenceTransformer) selectReferral(
func (o *nameReferenceTransformer) getSimpleNameField(
oldName string,
referrer *resource.Resource,
target gvk.Gvk,
target resid.Gvk,
referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource) (interface{}, error) {
@@ -161,7 +161,7 @@ func (o *nameReferenceTransformer) getSimpleNameField(
func (o *nameReferenceTransformer) getNameAndNsStruct(
inMap map[string]interface{},
referrer *resource.Resource,
target gvk.Gvk,
target resid.Gvk,
referralCandidates resmap.ResMap) (interface{}, error) {
// Example:
@@ -209,7 +209,7 @@ func (o *nameReferenceTransformer) getNameAndNsStruct(
func (o *nameReferenceTransformer) getNewNameFunc(
referrer *resource.Resource,
target gvk.Gvk,
target resid.Gvk,
referralCandidates resmap.ResMap) func(in interface{}) (interface{}, error) {
return func(in interface{}) (interface{}, error) {
switch in.(type) {

View File

@@ -7,9 +7,8 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/api/resid"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/resource"
@@ -877,9 +876,9 @@ func TestNameReferenceClusterWide(t *testing.T) {
}).ResMap()
clusterRoleId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
clusterRoleBindingId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId)
@@ -1005,9 +1004,9 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
}).ResMap()
clusterRoleId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
clusterRoleBindingId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId)

View File

@@ -5,9 +5,9 @@ package transformers
import (
"reflect"
"sigs.k8s.io/kustomize/v3/api/resid"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
@@ -38,11 +38,11 @@ func TestVarRef(t *testing.T) {
"BOO": true,
},
fs: []config.FieldSpec{
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
},
res: resmaptest_test.NewRmBuilder(t, rf).
Add(map[string]interface{}{