Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart namespace is applied to non-namespaced objects #2170

Open
maybedino opened this issue Sep 6, 2022 · 5 comments · May be fixed by cdk8s-team/cdk8s-core#2869
Open

Chart namespace is applied to non-namespaced objects #2170

maybedino opened this issue Sep 6, 2022 · 5 comments · May be fixed by cdk8s-team/cdk8s-core#2869
Labels
bug Something isn't working @component/cdk8s-core Issue related to cdk8s-core effort/small 1 day tops priority/p1 Should be on near term plans

Comments

@maybedino
Copy link

Currently, if you set a namespace for a chart, it will set the namespace on every object in the chart that does not have one:

https://github.com/cdk8s-team/cdk8s-core/blob/ab3fbf376841dd37cbfb53201fd1c8169bac16ae/src/api-object.ts#L133

While every Kubernetes object can have a metadata.namespace, some are cluster objects that are not namespaced. Applying a namespace to a cluster object breaks tools that check for this, like Terraform (I was trying to deploy with cdktf-cdk8s)

@iliapolo
Copy link
Member

@maybedino Oooh nice! Thanks for this, we'll look into it.

@iliapolo iliapolo added bug Something isn't working effort/small 1 day tops priority/p1 Should be on near term plans labels Sep 14, 2022
@github-actions
Copy link
Contributor

This issue has not received any attention in 1 year and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.

@github-actions github-actions bot added the closing-soon Issue/PR will be closing soon if no response is provided label Sep 14, 2023
@maybedino
Copy link
Author

This does not really cause any issues unless you have to validate your YAML files. The Kubernetes API does not complain.

@iliapolo Maybe it would still be good to keep this open, since technically it creates invalid YAML files which can cause problems with some deployment tools.

Our current workaround is to do this:

const ns = new k8s.KubeNamespace(this, "FooBar", {
	metadata: { name: "FooBar" },
});
ns.addJsonPatch(JsonPatch.remove("/metadata/namespace"));

@shinebayar-g
Copy link

shinebayar-g commented Sep 12, 2024

Workaround that I used in cdk8s-team/cdk8s-plus#4239 (comment) requires me to update the if condition whenever we introduce a new cdk8s imported class which can be error prone.

I guess something like class ClusterApiObject extends ApiObject can be introduced. Then ClusterApiObject would be used during cdk8s import process. Since CRD yamls already contain wether it's namespaced or not, it should be possible for cdk8s to check that. I don't know how to achieve this in kubernetes-schemas, but we can even maintain hardcoded list for built-in k8s resources.

@iliapolo iliapolo added the @component/cdk8s-core Issue related to cdk8s-core label Sep 20, 2024
@iliapolo iliapolo transferred this issue from cdk8s-team/cdk8s-core Sep 20, 2024
@shinebayar-g
Copy link

Really would love to see this issue fixed natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working @component/cdk8s-core Issue related to cdk8s-core effort/small 1 day tops priority/p1 Should be on near term plans
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants