From 46f44b8669bb1868e1c1140db363b9968ba9774e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 17 Jan 2023 11:19:08 +1100 Subject: [PATCH] driver/openstack: order flavor results I hit a situation in a new cloud where I had defined two flavors with the same amount of RAM "opendev-control" and "opendev". The config had min-ram set [1] with a flavor-name of "opendev" -- I expected it to match the exact name first, but nodepool was choosing "opendev-control". I guess the default order returned by the cloud is flavorid [2]. I'd propose that sorting on a tuple of (ram, name) -- so that we match names in alphabetical order -- is a more intuitive way to run the match. Documentation is updated, and a release note added. [1] which actually we didn't want, really, because we wanted to exactly match the flavor: https://review.opendev.org/c/openstack/project-config/+/870677 [2] https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail#list-flavors Change-Id: I268dd598ca9f1b617c5062b41ad27d0305df60b9 --- doc/source/openstack.rst | 13 +++++++++---- nodepool/driver/openstack/adapter.py | 2 +- .../flavors-alphabetical-fdf2196d64e7eb00.yaml | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/flavors-alphabetical-fdf2196d64e7eb00.yaml diff --git a/doc/source/openstack.rst b/doc/source/openstack.rst index 8524aa503..517f0eebe 100644 --- a/doc/source/openstack.rst +++ b/doc/source/openstack.rst @@ -575,11 +575,16 @@ Selecting the OpenStack driver adds the following options to the Name or id of the flavor to use. If :attr:`providers.[openstack].pools.labels.min-ram` is - omitted, it must be an exact match. If - :attr:`providers.[openstack].pools.labels.min-ram` is given, - ``flavor-name`` will be used to find flavor names that meet + omitted, it must be an exact match. + + If :attr:`providers.[openstack].pools.labels.min-ram` is + given, ``flavor-name`` will be used to find flavor names + that meet :attr:`providers.[openstack].pools.labels.min-ram` and also - contain ``flavor-name``. + contain ``flavor-name``. Flavors that match the RAM + requirements will be examined in standard alphabetical + order; the first to contain the ``flavor-name`` string will + be chosen. One of :attr:`providers.[openstack].pools.labels.min-ram` or :attr:`providers.[openstack].pools.labels.flavor-name` must diff --git a/nodepool/driver/openstack/adapter.py b/nodepool/driver/openstack/adapter.py index 20af87410..e5cd1e283 100644 --- a/nodepool/driver/openstack/adapter.py +++ b/nodepool/driver/openstack/adapter.py @@ -589,7 +589,7 @@ class OpenStackAdapter(statemachine.Adapter): def _getFlavors(self): flavors = self._listFlavors() - flavors.sort(key=operator.itemgetter('ram')) + flavors.sort(key=operator.itemgetter('ram', 'name')) return flavors def _findFlavorByName(self, flavor_name): diff --git a/releasenotes/notes/flavors-alphabetical-fdf2196d64e7eb00.yaml b/releasenotes/notes/flavors-alphabetical-fdf2196d64e7eb00.yaml new file mode 100644 index 000000000..813cd62e1 --- /dev/null +++ b/releasenotes/notes/flavors-alphabetical-fdf2196d64e7eb00.yaml @@ -0,0 +1,10 @@ +--- +upgrade: + - | + In the OpenStack driver, when using ```min-ram``` in combination + with a ```flavor-name```, the first flavor to be found that + satisfied the ```min-ram``` requirements and contained the + substring ``flavor-name``` would be used. The order of the + flavors to be searched was dependent on what the cloud returned. + From this release, the available flavors are now alphabetically + sorted before matching ```flavor-name```.