diff --git a/pkg/action/validate.go b/pkg/action/validate.go index 1bef5a742..892ce4189 100644 --- a/pkg/action/validate.go +++ b/pkg/action/validate.go @@ -45,7 +45,10 @@ func requireAdoption(resources kube.ResourceList) (kube.ResourceList, error) { if err != nil { return err } - + // Using generatedName + if info.Name == "" { + return nil + } helper := resource.NewHelper(info.Client, info.Mapping) _, err = helper.Get(info.Namespace, info.Name) if err != nil { @@ -70,7 +73,10 @@ func existingResourceConflict(resources kube.ResourceList, releaseName, releaseN if err != nil { return err } - + // Using generatedName + if info.Name == "" { + return nil + } helper := resource.NewHelper(info.Client, info.Mapping) existing, err := helper.Get(info.Namespace, info.Name) if err != nil { diff --git a/pkg/action/validate_test.go b/pkg/action/validate_test.go index 879a5fa4f..a40ad0d29 100644 --- a/pkg/action/validate_test.go +++ b/pkg/action/validate_test.go @@ -122,9 +122,10 @@ func fakeClientWith(code int, gv schema.GroupVersion, body string) *fake.RESTCli func TestRequireAdoption(t *testing.T) { var ( - missing = newMissingDeployment("missing", "ns-a") - existing = newDeploymentWithOwner("existing", "ns-a", nil, nil) - resources = kube.ResourceList{missing, existing} + missing = newMissingDeployment("missing", "ns-a") + existing = newDeploymentWithOwner("existing", "ns-a", nil, nil) + existingWithGeneratedName = newDeploymentWithOwner("", "ns-a", nil, nil) + resources = kube.ResourceList{missing, existing, existingWithGeneratedName} ) // Verify that a resource that lacks labels/annotations can be adopted @@ -146,10 +147,11 @@ func TestExistingResourceConflict(t *testing.T) { helmReleaseNameAnnotation: releaseName, helmReleaseNamespaceAnnotation: releaseNamespace, } - missing = newMissingDeployment("missing", "ns-a") - existing = newDeploymentWithOwner("existing", "ns-a", labels, annotations) - conflict = newDeploymentWithOwner("conflict", "ns-a", nil, nil) - resources = kube.ResourceList{missing, existing} + missing = newMissingDeployment("missing", "ns-a") + existing = newDeploymentWithOwner("existing", "ns-a", labels, annotations) + existingWithGeneratedName = newDeploymentWithOwner("", "ns-a", nil, nil) + conflict = newDeploymentWithOwner("conflict", "ns-a", nil, nil) + resources = kube.ResourceList{missing, existing, existingWithGeneratedName} ) // Verify only existing resources are returned