mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #4344 from natasha41575/ResIdStr
improve gvk and resid strings for error messages
This commit is contained in:
@@ -172,7 +172,7 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err
|
||||
return nil, err
|
||||
}
|
||||
if rn.IsNilOrEmpty() {
|
||||
return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source)
|
||||
return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source.ResId)
|
||||
}
|
||||
|
||||
return getRefinedValue(r.Source.Options, rn)
|
||||
|
||||
@@ -269,7 +269,7 @@ spec:
|
||||
- select:
|
||||
kind: Deployment
|
||||
`,
|
||||
expectedErr: "multiple matches for selector ~G_~V_Deployment|~X|~N",
|
||||
expectedErr: "multiple matches for selector Deployment.[noVer].[noGrp]/[noName].[noNs]",
|
||||
},
|
||||
"replacement has no source": {
|
||||
input: `apiVersion: v1
|
||||
@@ -1586,7 +1586,7 @@ data:
|
||||
options:
|
||||
create: true
|
||||
`,
|
||||
expectedErr: "fieldPath `data.httpPort` is missing for replacement source ~G_~V_ConfigMap|~X|ports-from:data.httpPort",
|
||||
expectedErr: "fieldPath `data.httpPort` is missing for replacement source ConfigMap.[noVer].[noGrp]/ports-from.[noNs]",
|
||||
},
|
||||
"annotationSelector": {
|
||||
input: `apiVersion: v1
|
||||
|
||||
@@ -521,7 +521,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
|
||||
},
|
||||
}).ResMap(),
|
||||
expectedErr: `updating name reference in 'rules/resourceNames' field of ` +
|
||||
`'rbac.authorization.k8s.io_v1_ClusterRole|~X|cr'` +
|
||||
`'ClusterRole.v1.rbac.authorization.k8s.io/cr.[noNs]'` +
|
||||
`: considering field 'rules/resourceNames' of object
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
|
||||
@@ -368,7 +368,7 @@ resources:
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") {
|
||||
err.Error(), "already registered id: StatefulSet.v1.apps/my-sts.[noNs]") {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -459,7 +459,7 @@ resources:
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(), "already registered id: apps_v1_StatefulSet|~X|my-sts") {
|
||||
err.Error(), "already registered id: StatefulSet.v1.apps/my-sts.[noNs]") {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ components:
|
||||
- ../comp-b`),
|
||||
},
|
||||
runPath: "prod",
|
||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
||||
expectedError: "may not add resource with an already registered id: Deployment.v1.[noGrp]/proxy.[noNs]",
|
||||
},
|
||||
"components-cannot-add-the-same-base": {
|
||||
input: []FileGen{writeTestBase,
|
||||
@@ -608,7 +608,7 @@ components:
|
||||
- ../comp-b`),
|
||||
},
|
||||
runPath: "prod",
|
||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|storefront",
|
||||
expectedError: "may not add resource with an already registered id: Deployment.v1.[noGrp]/storefront.[noNs]",
|
||||
},
|
||||
"components-cannot-add-bases-containing-the-same-resource": {
|
||||
input: []FileGen{writeTestBase,
|
||||
@@ -639,7 +639,7 @@ components:
|
||||
- ../comp-b`),
|
||||
},
|
||||
runPath: "prod",
|
||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
||||
expectedError: "may not add resource with an already registered id: Deployment.v1.[noGrp]/proxy.[noNs]",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ resources:
|
||||
t.Fatalf("Expected resource accumulation error")
|
||||
}
|
||||
if !strings.Contains(
|
||||
err.Error(), "already registered id: apps_v1_Deployment|~X|my-deployment") {
|
||||
err.Error(), "already registered id: Deployment.v1.apps/my-deployment.[noNs]") {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ spec:
|
||||
|
||||
err := th.RunWithErr("mango", th.MakeDefaultOptions())
|
||||
if !strings.Contains(
|
||||
err.Error(), "multiple matches for Id apps_v1_Deployment|~X|banana; failed to find unique target for patch") {
|
||||
err.Error(), "multiple matches for Id Deployment.v1.apps/banana.[noNs]; failed to find unique target for patch Deployment.v1.apps/banana.[noNs]") {
|
||||
t.Fatalf("Unexpected err: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ func (m *resWrangler) GetById(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"%s; failed to find unique target for patch %s",
|
||||
err.Error(), id.GvknString())
|
||||
err.Error(), id.String())
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -1377,7 +1377,7 @@ spec:
|
||||
numReplicas: 1
|
||||
`))
|
||||
assert.NoError(t, err)
|
||||
r.SetGvk(resid.GvkFromString("grp_ver_knd"))
|
||||
r.SetGvk(resid.GvkFromString("knd.ver.grp"))
|
||||
gvk := r.GetGvk()
|
||||
if expected, actual := "grp", gvk.Group; expected != actual {
|
||||
t.Fatalf("expected '%s', got '%s'", expected, actual)
|
||||
@@ -1400,30 +1400,30 @@ spec:
|
||||
numReplicas: 1
|
||||
`))
|
||||
assert.NoError(t, err)
|
||||
r.AppendRefBy(resid.FromString("gr1_ver1_knd1|ns1|name1"))
|
||||
r.AppendRefBy(resid.FromString("knd1.ver1.gr1/name1.ns1"))
|
||||
assert.Equal(t, r.RNode.MustString(), `apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: clown
|
||||
annotations:
|
||||
internal.config.kubernetes.io/refBy: gr1_ver1_knd1|ns1|name1
|
||||
internal.config.kubernetes.io/refBy: knd1.ver1.gr1/name1.ns1
|
||||
spec:
|
||||
numReplicas: 1
|
||||
`)
|
||||
assert.Equal(t, r.GetRefBy(), []resid.ResId{resid.FromString("gr1_ver1_knd1|ns1|name1")})
|
||||
assert.Equal(t, r.GetRefBy(), []resid.ResId{resid.FromString("knd1.ver1.gr1/name1.ns1")})
|
||||
|
||||
r.AppendRefBy(resid.FromString("gr2_ver2_knd2|ns2|name2"))
|
||||
r.AppendRefBy(resid.FromString("knd2.ver2.gr2/name2.ns2"))
|
||||
assert.Equal(t, r.RNode.MustString(), `apiVersion: v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: clown
|
||||
annotations:
|
||||
internal.config.kubernetes.io/refBy: gr1_ver1_knd1|ns1|name1,gr2_ver2_knd2|ns2|name2
|
||||
internal.config.kubernetes.io/refBy: knd1.ver1.gr1/name1.ns1,knd2.ver2.gr2/name2.ns2
|
||||
spec:
|
||||
numReplicas: 1
|
||||
`)
|
||||
assert.Equal(t, r.GetRefBy(), []resid.ResId{
|
||||
resid.FromString("gr1_ver1_knd1|ns1|name1"),
|
||||
resid.FromString("gr2_ver2_knd2|ns2|name2"),
|
||||
resid.FromString("knd1.ver1.gr1/name1.ns1"),
|
||||
resid.FromString("knd2.ver2.gr2/name2.ns2"),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user