mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #4700 from KnVerey/ns_transformer_err_on_ambiguous_ns
Correctly detect ambiguity between potential referrers when targeting a name+namespace reference
This commit is contained in:
77
api/krusty/namedspacedserviceaccounts_test.go
Normal file
77
api/krusty/namedspacedserviceaccounts_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2022 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
)
|
||||
|
||||
func TestNamedspacedServiceAccountsWithOverlap(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
|
||||
th.WriteF("a/a.yaml", `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: sa
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: crb-a
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: cr-a
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: sa
|
||||
`)
|
||||
|
||||
th.WriteK("a/", `
|
||||
namespace: a
|
||||
resources:
|
||||
- a.yaml
|
||||
`)
|
||||
|
||||
th.WriteF("b/b.yaml", `
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: sa
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: crb-b
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: cr-b
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: sa
|
||||
`)
|
||||
|
||||
th.WriteK("b/", `
|
||||
namespace: b
|
||||
resources:
|
||||
- b.yaml
|
||||
`)
|
||||
|
||||
th.WriteK(".", `
|
||||
resources:
|
||||
- a
|
||||
- b
|
||||
`)
|
||||
|
||||
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
||||
assert.EqualError(t, err,
|
||||
"updating name reference in 'subjects' field of 'ClusterRoleBinding.v1.rbac.authorization.k8s.io/crb-a.[noNs]': "+
|
||||
"considering field 'subjects' of object ClusterRoleBinding.v1.rbac.authorization.k8s.io/crb-a.[noNs]: "+
|
||||
"found multiple possible referrals: ServiceAccount.v1.[noGrp]/sa.a, ServiceAccount.v1.[noGrp]/sa.b")
|
||||
}
|
||||
Reference in New Issue
Block a user