Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/simulate/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ func RejectDuplicateNames(comps []*un.Unstructured) error {
// composite resource or claim, such as package metadata, a Provider or a
// ConfigMap, which the engine would otherwise fail on with no hint at what -f
// accepts. It also gives a claim or namespaced composite resource with no
// namespace the kubeconfig context namespace ns, as kubectl apply would. The
// definition client caches the XRDs when it initializes, so the check costs
// no extra calls.
// namespace the kubeconfig context namespace ns, as kubectl apply would, and
// clears any namespace on a cluster-scoped composite resource, which kubectl
// apply ignores there. The definition client caches the XRDs when it
// initializes, so the check costs no extra calls.
func checkComposites(ctx context.Context, defs xpclient.DefinitionClient, ns string, resources []*un.Unstructured) error {
for _, r := range resources {
gvk := r.GroupVersionKind()
Expand All @@ -104,6 +105,8 @@ func checkComposites(ctx context.Context, defs xpclient.DefinitionClient, ns str
// Only a Namespaced scope is namespaced; Cluster and LegacyCluster are not.
if scope, _, _ := un.NestedString(xrd.Object, "spec", "scope"); scope == "Namespaced" {
defaultNamespace(r, ns)
} else {
r.SetNamespace("")
}
continue
}
Expand Down
2 changes: 2 additions & 0 deletions internal/simulate/inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ func TestCheckCompositesNamespace(t *testing.T) {
"NamespacedXRWithoutNamespace": {kind: "XNamespaced", want: "ctx-ns"},
"NamespacedXRWithNamespace": {kind: "XNamespaced", namespace: "mine", want: "mine"},
"ClusterXR": {kind: "XCluster", want: ""},
"ClusterXRWithNamespace": {kind: "XCluster", namespace: "mine", want: ""},
"LegacyClusterXR": {kind: "XLegacy", want: ""},
"LegacyClusterXRWithNamespace": {kind: "XLegacy", namespace: "mine", want: ""},
"ClaimWithoutNamespace": {kind: "Claim", want: "ctx-ns"},
"ClaimWithNamespace": {kind: "Claim", namespace: "mine", want: "mine"},
}
Expand Down
Loading