Break the dep between fs and pgmconfig.

This commit is contained in:
Jeffrey Regan
2019-10-02 12:01:45 -07:00
parent 5372fc6f6c
commit 2d58f8b81c
46 changed files with 600 additions and 419 deletions

View File

@@ -64,7 +64,7 @@ const metaNamespace = "metadata/namespace"
// that don't exist in a namespace (the Namespace
// object itself doesn't live in a namespace).
func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec {
res := []config.FieldSpec{}
var res []config.FieldSpec
for _, fs := range p.FieldSpecs {
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
res = append(res, fs)
@@ -73,14 +73,14 @@ func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []conf
return res
}
func (o *NamespaceTransformerPlugin) changeNamespace(
func (p *NamespaceTransformerPlugin) changeNamespace(
referrer *resource.Resource) func(in interface{}) (interface{}, error) {
return func(in interface{}) (interface{}, error) {
switch in.(type) {
case string:
// will happen when the metadata/namespace
// value is replaced
return o.Namespace, nil
return p.Namespace, nil
case []interface{}:
l, _ := in.([]interface{})
for idx, item := range l {
@@ -102,7 +102,7 @@ func (o *NamespaceTransformerPlugin) changeNamespace(
if name != "default" {
continue
}
inMap["namespace"] = o.Namespace
inMap["namespace"] = p.Namespace
l[idx] = inMap
default:
// nothing to do for right now
@@ -115,7 +115,7 @@ func (o *NamespaceTransformerPlugin) changeNamespace(
// object
inMap := in.(map[string]interface{})
if len(inMap) == 0 {
return o.Namespace, nil
return p.Namespace, nil
} else {
return in, nil
}

View File

@@ -52,7 +52,7 @@ func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
for i, replicaSpec := range p.FieldSpecs {
gvks[i] = replicaSpec.Gvk.String()
}
return fmt.Errorf("Resource with name %s does not match a config with the following GVK %v",
return fmt.Errorf("resource with name %s does not match a config with the following GVK %v",
p.Replica.Name, gvks)
}

View File

@@ -70,7 +70,7 @@ const metaNamespace = "metadata/namespace"
// that don't exist in a namespace (the Namespace
// object itself doesn't live in a namespace).
func (p *plugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec {
res := []config.FieldSpec{}
var res []config.FieldSpec
for _, fs := range p.FieldSpecs {
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
res = append(res, fs)
@@ -79,14 +79,14 @@ func (p *plugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec {
return res
}
func (o *plugin) changeNamespace(
func (p *plugin) changeNamespace(
referrer *resource.Resource) func(in interface{}) (interface{}, error) {
return func(in interface{}) (interface{}, error) {
switch in.(type) {
case string:
// will happen when the metadata/namespace
// value is replaced
return o.Namespace, nil
return p.Namespace, nil
case []interface{}:
l, _ := in.([]interface{})
for idx, item := range l {
@@ -108,7 +108,7 @@ func (o *plugin) changeNamespace(
if name != "default" {
continue
}
inMap["namespace"] = o.Namespace
inMap["namespace"] = p.Namespace
l[idx] = inMap
default:
// nothing to do for right now
@@ -121,7 +121,7 @@ func (o *plugin) changeNamespace(
// object
inMap := in.(map[string]interface{})
if len(inMap) == 0 {
return o.Namespace, nil
return p.Namespace, nil
} else {
return in, nil
}

View File

@@ -600,11 +600,6 @@ func addNamespace(namespace string, base string) string {
return res
}
// unExpectedError function handles unexpected error
func unExpectedError(t *testing.T, name string, err error) {
t.Fatalf("%q; - unexpected error %v", name, err)
}
// compareExpectedError compares the expectedError and the actualError return by GetFieldValue
func compareExpectedError(t *testing.T, name string, err error, errorMsg string) {
if err == nil {
@@ -854,7 +849,7 @@ metadata:
name: notImportantHere
paths:
`
for idx, _ := range patches {
for idx := range patches {
config = fmt.Sprintf("%s\n- ./patch%d.yaml", config, idx)
}

View File

@@ -58,7 +58,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
for i, replicaSpec := range p.FieldSpecs {
gvks[i] = replicaSpec.Gvk.String()
}
return fmt.Errorf("Resource with name %s does not match a config with the following GVK %v",
return fmt.Errorf("resource with name %s does not match a config with the following GVK %v",
p.Replica.Name, gvks)
}

View File

@@ -229,7 +229,7 @@ spec:
t.Fatalf("No match should return an error")
}
if err.Error() !=
"Resource with name service does not match a config with the following GVK [~G_~V_Deployment]" {
"resource with name service does not match a config with the following GVK [~G_~V_Deployment]" {
t.Fatalf("Unexpected error: %v", err)
}
}