| 1 |
// Copyright 2022 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package krusty_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"strings" |
| 8 |
"testing" |
| 9 |
|
| 10 |
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" |
| 11 |
) |
| 12 |
|
| 13 |
// test for https://github.com/kubernetes-sigs/kustomize/issues/4240 |
| 14 |
func TestBlankNamespace4240(t *testing.T) { |
| 15 |
th := kusttest_test.MakeHarness(t) |
| 16 |
th.WriteK(".", ` |
| 17 |
resources: |
| 18 |
- resource.yaml |
| 19 |
`) |
| 20 |
|
| 21 |
th.WriteF("resource.yaml", ` |
| 22 |
--- |
| 23 |
apiVersion: v1 |
| 24 |
kind: ServiceAccount |
| 25 |
metadata: |
| 26 |
name: test |
| 27 |
--- |
| 28 |
apiVersion: rbac.authorization.k8s.io/v1 |
| 29 |
kind: Role |
| 30 |
metadata: |
| 31 |
name: test |
| 32 |
rules: [] |
| 33 |
--- |
| 34 |
apiVersion: rbac.authorization.k8s.io/v1 |
| 35 |
kind: RoleBinding |
| 36 |
metadata: |
| 37 |
name: test |
| 38 |
subjects: |
| 39 |
- kind: ServiceAccount |
| 40 |
name: test |
| 41 |
namespace: |
| 42 |
roleRef: |
| 43 |
kind: Role |
| 44 |
name: test |
| 45 |
apiGroup: rbac.authorization.k8s.io |
| 46 |
`) |
| 47 |
|
| 48 |
err := th.RunWithErr(".", th.MakeDefaultOptions()) |
| 49 |
if !strings.Contains(err.Error(), "Invalid Input: namespace is blank for resource") { |
| 50 |
t.Fatalf("unexpected error: %q", err) |
| 51 |
} |
| 52 |
} |