pulumi-kubernetes icon indicating copy to clipboard operation
pulumi-kubernetes copied to clipboard

Kubernetes Resource Naming Convention Needs Rethinking

Open gkramer opened this issue 3 years ago • 4 comments

Attempting to spin up two separate k8s clusters within the same stack, both of which run generic services (external-dns, cert-manager, etc) fails due to URN naming convention. It seems that URN should include the cluster name, so as to facilitate this requirement. This problem becomes more pronounced when deploying CRDs, where its not possible to modify the resource/CRD name.

Steps to reproduce

Deploy two K8S clusters within the same stack, both of which are running cert-manager. Pulumi will fail due to lack of unique URNs.

gkramer avatar Aug 25 '21 10:08 gkramer

URNs are defined by the name of the Pulumi resource which doesn't have to match the actual resource name in the provider's target. If you have two K8s clusters in the same stack, you need to give them unique Pulumi names. The same applies to other resource types. Component resources will usually use the parent name to build up the children names.

Do you want to share some code where you think it's problematic?

mikhailshilkov avatar Aug 31 '21 12:08 mikhailshilkov

The problem is deploying the resources. Pulumi doesn't use the provider name or k8s name in the URN of the resources. So if you deploy the same resources to two different k8s clusters, Pulumi generates the same URN.

As an example, try using NewConfigFile with this CSI AWS provider. And then doing:

_, err = k8syaml.NewConfigFile(ctx, clusterName+"_aws_secrets_store_provider", &k8syaml.ConfigFileArgs{
		File: "aws-provider-installer.yaml",
}, provider)
if err != nil {
	return err
}

On two different clusterNames and providers configured for two different k8s clusters. Pulumi still thinks it's managing the same resources meanwhile they're on different k8s clusters.

travisjeffery avatar Feb 03 '22 22:02 travisjeffery

I ended up just writing everything in that yaml in the equivalent resource code by hand, but that api is pretty broken. Should at least use the logical name given to help make things unique.

travisjeffery avatar Feb 04 '22 05:02 travisjeffery

I have the same problem using the Pulumi TypeScript SDK and Azure-native Kubernetes :+1:

TheDome avatar Feb 17 '22 10:02 TheDome