From 80c6ad17001b852d55ab27301d234df12538c3e0 Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 18 Jan 2021 18:51:35 +0000 Subject: [PATCH 1/2] fix: include namespace in renderedYaml filename This fixes a problem when resources have the same name/kind, but live in different namespaces. This caused the first file written to be overwritten by the later resources. --- CHANGELOG.md | 2 ++ provider/pkg/provider/provider.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7805cd52b..a66b676a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## HEAD (Unreleased) +- Fix bug where rendering manifests results in files being overwritten by subsequent resources with the same kind and name, but different namespace (https://github.com/pulumi/pulumi-kubernetes/pull/1429) + ## 2.8.2 (February 23, 2021) - Postpone the removal of admissionregistration/v1beta1, which has been retargeted at 1.22 (https://github.com/pulumi/pulumi-kubernetes/pull/1474) diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 2426fb611e..0d75bcf769 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -2764,7 +2764,7 @@ func renderPathForResource(resource *unstructured.Unstructured, yamlDirectory st crdDirectory := filepath.Join(yamlDirectory, "0-crd") manifestDirectory := filepath.Join(yamlDirectory, "1-manifest") - fileName := fmt.Sprintf("%s-%s.yaml", strings.ToLower(resource.GetKind()), resource.GetName()) + fileName := fmt.Sprintf("%s-%s-%s.yaml", strings.ToLower(resource.GetKind()), resource.GetNamespace(), resource.GetName()) filepath.Join(yamlDirectory, fileName) var path string From f994a71e6eb8a8ab938145ca13d6c348ab36d806 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 26 Feb 2021 11:52:03 +0000 Subject: [PATCH 2/2] fix: expand empty namespace to default for exported filenames --- provider/pkg/provider/provider.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 0d75bcf769..d38747b28a 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -2764,7 +2764,12 @@ func renderPathForResource(resource *unstructured.Unstructured, yamlDirectory st crdDirectory := filepath.Join(yamlDirectory, "0-crd") manifestDirectory := filepath.Join(yamlDirectory, "1-manifest") - fileName := fmt.Sprintf("%s-%s-%s.yaml", strings.ToLower(resource.GetKind()), resource.GetNamespace(), resource.GetName()) + namespace := "default" + if "" != resource.GetNamespace() { + namespace = resource.GetNamespace() + } + + fileName := fmt.Sprintf("%s-%s-%s.yaml", strings.ToLower(resource.GetKind()), namespace, resource.GetName()) filepath.Join(yamlDirectory, fileName) var path string