Skip to content

Commit 07a64f7

Browse files
committed
Fix import of server where name is not specified
Commit 3deb8ee fixed import for names that are substring of another server name, however this broke the import for when we don't specify a name in the filter. In which case, the filter would look for servers that don't have a name. This is obviously not what we want. This broke the `import-error` test and we didn't notice because we had forgotten to enable the suite as part of the CI runs. Now, only filter by name when a name is set in the filter.
1 parent 3e00338 commit 07a64f7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

internal/controllers/server/actuator.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
2727
corev1 "k8s.io/api/core/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
29-
"k8s.io/utils/ptr"
3029
ctrl "sigs.k8s.io/controller-runtime"
3130
"sigs.k8s.io/controller-runtime/pkg/client"
3231

@@ -85,13 +84,16 @@ func (actuator serverActuator) ListOSResourcesForAdoption(ctx context.Context, o
8584

8685
func (actuator serverActuator) ListOSResourcesForImport(ctx context.Context, filter filterT) serverIterator {
8786
listOpts := servers.ListOpts{
88-
Name: fmt.Sprintf("^%s$", string(ptr.Deref(filter.Name, ""))),
8987
Tags: neutrontags.Join(filter.FilterByServerTags.Tags),
9088
TagsAny: neutrontags.Join(filter.FilterByServerTags.TagsAny),
9189
NotTags: neutrontags.Join(filter.FilterByServerTags.NotTags),
9290
NotTagsAny: neutrontags.Join(filter.FilterByServerTags.NotTagsAny),
9391
}
9492

93+
if filter.Name != nil {
94+
listOpts.Name = fmt.Sprintf("^%s$", string(*filter.Name))
95+
}
96+
9597
return actuator.osClient.ListServers(ctx, listOpts)
9698
}
9799

0 commit comments

Comments
 (0)