...

Source file src/sigs.k8s.io/kustomize/api/krusty/namedspacedserviceaccounts_test.go

Documentation: sigs.k8s.io/kustomize/api/krusty

     1  // Copyright 2022 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package krusty_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
    11  )
    12  
    13  func TestNamedspacedServiceAccountsWithOverlap(t *testing.T) {
    14  	th := kusttest_test.MakeHarness(t)
    15  
    16  	th.WriteF("a/a.yaml", `
    17  apiVersion: v1
    18  kind: ServiceAccount
    19  metadata:
    20    name: sa
    21  ---
    22  apiVersion: rbac.authorization.k8s.io/v1
    23  kind: ClusterRoleBinding
    24  metadata:
    25    name: crb-a
    26  roleRef:
    27    apiGroup: rbac.authorization.k8s.io
    28    kind: ClusterRole
    29    name: cr-a
    30  subjects:
    31    - kind: ServiceAccount
    32      name: sa
    33  `)
    34  
    35  	th.WriteK("a/", `
    36  namespace: a
    37  resources:
    38  - a.yaml
    39  `)
    40  
    41  	th.WriteF("b/b.yaml", `
    42  apiVersion: v1
    43  kind: ServiceAccount
    44  metadata:
    45    name: sa
    46  ---
    47  apiVersion: rbac.authorization.k8s.io/v1
    48  kind: ClusterRoleBinding
    49  metadata:
    50    name: crb-b
    51  roleRef:
    52    apiGroup: rbac.authorization.k8s.io
    53    kind: ClusterRole
    54    name: cr-b
    55  subjects:
    56    - kind: ServiceAccount
    57      name: sa
    58  `)
    59  
    60  	th.WriteK("b/", `
    61  namespace: b
    62  resources:
    63  - b.yaml
    64  `)
    65  
    66  	th.WriteK(".", `
    67  resources:
    68  - a
    69  - b
    70  `)
    71  
    72  	err := th.RunWithErr(".", th.MakeDefaultOptions())
    73  	assert.Contains(t, err.Error(), "found multiple possible referrals: ServiceAccount.v1.[noGrp]/sa.a, ServiceAccount.v1.[noGrp]/sa.b")
    74  }
    75  

View as plain text