mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Fix Issue 3489.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package krusty_test
|
package krusty_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
@@ -48,11 +47,46 @@ kind: ServiceAccount
|
|||||||
metadata:
|
metadata:
|
||||||
name: mySvcAcct
|
name: mySvcAcct
|
||||||
`)
|
`)
|
||||||
// TODO(3489): This shouldn't be an error.
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
th.AssertActualEqualsExpected(m, `
|
||||||
if !strings.Contains(err.Error(), "found multiple possible referrals") {
|
apiVersion: apps/v1
|
||||||
t.Fatalf("unexpected error: %q", err)
|
kind: Deployment
|
||||||
}
|
metadata:
|
||||||
|
name: myDep
|
||||||
|
namespace: kube-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: k8s.gcr.io/governmentCheese
|
||||||
|
name: whatever
|
||||||
|
serviceAccountName: mySvcAcct
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: mySvcAcct
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDep-private
|
||||||
|
namespace: kube-system
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: k8s.gcr.io/governmentCheese
|
||||||
|
name: whatever
|
||||||
|
serviceAccountName: mySvcAcct-private
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: mySvcAcct-private
|
||||||
|
namespace: kube-system
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue3489(t *testing.T) {
|
func TestIssue3489(t *testing.T) {
|
||||||
@@ -230,11 +264,234 @@ kind: ServiceAccount
|
|||||||
metadata:
|
metadata:
|
||||||
name: external-dns
|
name: external-dns
|
||||||
`)
|
`)
|
||||||
// TODO(3489): This shouldn't be an error.
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
th.AssertActualEqualsExpected(m, `
|
||||||
if !strings.Contains(err.Error(), "found multiple possible referrals") {
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
t.Fatalf("unexpected error: %q", err)
|
kind: ClusterRole
|
||||||
}
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
name: external-dns
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- endpoints
|
||||||
|
- pods
|
||||||
|
- services
|
||||||
|
- nodes
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- watch
|
||||||
|
- list
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
- networking.k8s.io
|
||||||
|
resources:
|
||||||
|
- ingresses
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- watch
|
||||||
|
- list
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
name: external-dns-viewer
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: external-dns
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: external-dns
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
name: external-dns
|
||||||
|
namespace: kube-system
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- args:
|
||||||
|
- --txt-owner-id="aks"
|
||||||
|
- --txt-prefix=external-dns-
|
||||||
|
- --source=service
|
||||||
|
- --provider=azure
|
||||||
|
- --registry=txt
|
||||||
|
- --domain-filter=dev.company.com
|
||||||
|
image: xxx.azurecr.io/external-dns:v0.7.4_sylr.1
|
||||||
|
name: external-dns
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /etc/kubernetes
|
||||||
|
name: azure-config-file
|
||||||
|
readOnly: true
|
||||||
|
serviceAccountName: external-dns
|
||||||
|
volumes:
|
||||||
|
- name: azure-config-file
|
||||||
|
secret:
|
||||||
|
secretName: azure-config-file-66cc4224mm
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
name: external-dns
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
azure.json: |
|
||||||
|
ewoJInRlbmFudElkIjogIlhYWFhYLVhYWFhYWC1YWFhYWC1YWFhYWFgtWFhYWFhYIiwKCS
|
||||||
|
JzdWJzY3JpcHRpb25JZCI6ICJYWFhYWC1YWFhYWFgtWFhYWFgtWFhYWFhYLVhYWFhYWCIs
|
||||||
|
CgkicmVzb3VyY2VHcm91cCI6ICJETlMtRVVXLVhYWC1SRyIsCgkidXNlTWFuYWdlZElkZW
|
||||||
|
50aXR5RXh0ZW5zaW9uIjogdHJ1ZSwKCSJ1c2VyQXNzaWduZWRJZGVudGl0eUlEIjogIlhY
|
||||||
|
WFhYLVhYWFhYWC1YWFhYWC1YWFhYWFgtWFhYWFhYIgp9Cg==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: public
|
||||||
|
name: azure-config-file-66cc4224mm
|
||||||
|
namespace: kube-system
|
||||||
|
type: Opaque
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
name: external-dns-private
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- endpoints
|
||||||
|
- pods
|
||||||
|
- services
|
||||||
|
- nodes
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- watch
|
||||||
|
- list
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
- networking.k8s.io
|
||||||
|
resources:
|
||||||
|
- ingresses
|
||||||
|
verbs:
|
||||||
|
- get
|
||||||
|
- watch
|
||||||
|
- list
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
name: external-dns-viewer-private
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: external-dns-private
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: external-dns-private
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
name: external-dns-private
|
||||||
|
namespace: kube-system
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
strategy:
|
||||||
|
type: Recreate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- args:
|
||||||
|
- --txt-owner-id="aks"
|
||||||
|
- --txt-prefix=external-dns-private-
|
||||||
|
- --source=service
|
||||||
|
- --provider=azure-private-dns
|
||||||
|
- --registry=txt
|
||||||
|
- --domain-filter=static.company.az
|
||||||
|
image: xxx.azurecr.io/external-dns:v0.7.4_sylr.1
|
||||||
|
name: external-dns
|
||||||
|
resources: {}
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /etc/kubernetes
|
||||||
|
name: azure-config-file
|
||||||
|
readOnly: true
|
||||||
|
serviceAccountName: external-dns-private
|
||||||
|
volumes:
|
||||||
|
- name: azure-config-file
|
||||||
|
secret:
|
||||||
|
secretName: azure-config-file-private-66cc4224mm
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
name: external-dns-private
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
azure.json: |
|
||||||
|
ewoJInRlbmFudElkIjogIlhYWFhYLVhYWFhYWC1YWFhYWC1YWFhYWFgtWFhYWFhYIiwKCS
|
||||||
|
JzdWJzY3JpcHRpb25JZCI6ICJYWFhYWC1YWFhYWFgtWFhYWFgtWFhYWFhYLVhYWFhYWCIs
|
||||||
|
CgkicmVzb3VyY2VHcm91cCI6ICJETlMtRVVXLVhYWC1SRyIsCgkidXNlTWFuYWdlZElkZW
|
||||||
|
50aXR5RXh0ZW5zaW9uIjogdHJ1ZSwKCSJ1c2VyQXNzaWduZWRJZGVudGl0eUlEIjogIlhY
|
||||||
|
WFhYLVhYWFhYWC1YWFhYWC1YWFhYWFgtWFhYWFhYIgp9Cg==
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: external-dns
|
||||||
|
instance: private
|
||||||
|
name: azure-config-file-private-66cc4224mm
|
||||||
|
namespace: kube-system
|
||||||
|
type: Opaque
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyFieldSpecValue(t *testing.T) {
|
func TestEmptyFieldSpecValue(t *testing.T) {
|
||||||
|
|||||||
@@ -143,10 +143,73 @@ resources:
|
|||||||
- ../ov2
|
- ../ov2
|
||||||
- ../ov3
|
- ../ov3
|
||||||
`)
|
`)
|
||||||
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
if err == nil {
|
th.AssertActualEqualsExpected(m, `
|
||||||
t.Fatal("TODO(3489): this should work")
|
apiVersion: v1
|
||||||
}
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: pp-myMap
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
group: apps
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: pp-myDep
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: CM_FOO
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
key: foo
|
||||||
|
name: pp-myMap
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: myMap-ss
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
group: apps
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDep-ss
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: CM_FOO
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
key: foo
|
||||||
|
name: myMap-ss
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: myMap-xx
|
||||||
|
namespace: fred
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
group: apps
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: myDep-xx
|
||||||
|
namespace: fred
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: CM_FOO
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
key: foo
|
||||||
|
name: myMap-xx
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNameAndNsTransformation validates that NamespaceTransformer,
|
// TestNameAndNsTransformation validates that NamespaceTransformer,
|
||||||
|
|||||||
@@ -294,20 +294,16 @@ func (r *Resource) GetOutermostNameSuffix() string {
|
|||||||
return nameSuffixes[len(nameSuffixes)-1]
|
return nameSuffixes[len(nameSuffixes)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func SameEndingSubarray(a, b []string) bool {
|
func SameEndingSubarray(shortest, longest []string) bool {
|
||||||
compareLen := len(b)
|
if len(shortest) > len(longest) {
|
||||||
if len(a) < len(b) {
|
longest, shortest = shortest, longest
|
||||||
compareLen = len(a)
|
|
||||||
}
|
}
|
||||||
|
diff := len(longest) - len(shortest)
|
||||||
if compareLen == 0 {
|
if len(shortest) == 0 {
|
||||||
return true
|
return diff == 0
|
||||||
}
|
}
|
||||||
|
for i := len(shortest) - 1; i >= 0; i-- {
|
||||||
alen := len(a) - 1
|
if longest[i+diff] != shortest[i] {
|
||||||
blen := len(b) - 1
|
|
||||||
for i := 0; i <= compareLen-1; i++ {
|
|
||||||
if a[alen-i] != b[blen-i] {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1196,10 +1196,10 @@ func TestSameEndingSubarray(t *testing.T) {
|
|||||||
b: []string{},
|
b: []string{},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
"no1 - TODO(3489) this should be false": {
|
"no1": {
|
||||||
a: []string{"a"},
|
a: []string{"a"},
|
||||||
b: []string{},
|
b: []string{},
|
||||||
expected: true,
|
expected: false,
|
||||||
},
|
},
|
||||||
"no2": {
|
"no2": {
|
||||||
a: []string{"b", "a"},
|
a: []string{"b", "a"},
|
||||||
|
|||||||
Reference in New Issue
Block a user