Fix: --dry-run=server with "generateName" is respected

Signed-off-by: saimanojk1 <saimanojk1@hotmail.com>
pull/31564/head
saimanojk1 11 months ago
parent 61d289c119
commit 05e20b8534
No known key found for this signature in database
GPG Key ID: DD31B2C23E0019E1

@ -45,7 +45,10 @@ func requireAdoption(resources kube.ResourceList) (kube.ResourceList, error) {
if err != nil { if err != nil {
return err return err
} }
// Using generatedName
if info.Name == "" {
return nil
}
helper := resource.NewHelper(info.Client, info.Mapping) helper := resource.NewHelper(info.Client, info.Mapping)
_, err = helper.Get(info.Namespace, info.Name) _, err = helper.Get(info.Namespace, info.Name)
if err != nil { if err != nil {
@ -70,7 +73,10 @@ func existingResourceConflict(resources kube.ResourceList, releaseName, releaseN
if err != nil { if err != nil {
return err return err
} }
// Using generatedName
if info.Name == "" {
return nil
}
helper := resource.NewHelper(info.Client, info.Mapping) helper := resource.NewHelper(info.Client, info.Mapping)
existing, err := helper.Get(info.Namespace, info.Name) existing, err := helper.Get(info.Namespace, info.Name)
if err != nil { if err != nil {

@ -122,9 +122,10 @@ func fakeClientWith(code int, gv schema.GroupVersion, body string) *fake.RESTCli
func TestRequireAdoption(t *testing.T) { func TestRequireAdoption(t *testing.T) {
var ( var (
missing = newMissingDeployment("missing", "ns-a") missing = newMissingDeployment("missing", "ns-a")
existing = newDeploymentWithOwner("existing", "ns-a", nil, nil) existing = newDeploymentWithOwner("existing", "ns-a", nil, nil)
resources = kube.ResourceList{missing, existing} existingWithGeneratedName = newDeploymentWithOwner("", "ns-a", nil, nil)
resources = kube.ResourceList{missing, existing, existingWithGeneratedName}
) )
// Verify that a resource that lacks labels/annotations can be adopted // Verify that a resource that lacks labels/annotations can be adopted
@ -146,10 +147,11 @@ func TestExistingResourceConflict(t *testing.T) {
helmReleaseNameAnnotation: releaseName, helmReleaseNameAnnotation: releaseName,
helmReleaseNamespaceAnnotation: releaseNamespace, helmReleaseNamespaceAnnotation: releaseNamespace,
} }
missing = newMissingDeployment("missing", "ns-a") missing = newMissingDeployment("missing", "ns-a")
existing = newDeploymentWithOwner("existing", "ns-a", labels, annotations) existing = newDeploymentWithOwner("existing", "ns-a", labels, annotations)
conflict = newDeploymentWithOwner("conflict", "ns-a", nil, nil) existingWithGeneratedName = newDeploymentWithOwner("", "ns-a", nil, nil)
resources = kube.ResourceList{missing, existing} conflict = newDeploymentWithOwner("conflict", "ns-a", nil, nil)
resources = kube.ResourceList{missing, existing, existingWithGeneratedName}
) )
// Verify only existing resources are returned // Verify only existing resources are returned

Loading…
Cancel
Save