Skip to content

Supporting flavor aliases #228

Closed as not planned
Closed as not planned

Description

@garloff

edit for the current proposal, jump to this comment

When flavor names need to change, this will cause pain for customers and operators.

  • If we just rename the flavors (in the database, nova-api does not expose this), running instances and code using flavor UUIDs will be fine; however IaC code that uses the old names will fail. This may include reconciliation loops (e.g. in cluster-api), causing significant pain.
  • Creating a duplicate set of flavors (one with old and one with new name) does create some UI challenges and postpones the issue to the point in time when the duplicates will be switched off ... The problem at that point in time is worse, as we'll likely have things referencing flavors that we then want to delete. Advanced database magic, which is risky.

We have this problem, as issue #190 reported that k8s based solutions create labels using the IaaS flavor names and ":" is not allowed in k8s labels. Following the reasoning in #192, a proposal exists as PR #226, where we introduce a 1:1 relationship between old and new names. The strategy to ease the transition pain however is not addressed yet.

This issue is supposed to discuss ideas how to smooth the transition for operators and their customers.

Activity

  1. garloff commented on Feb 18, 2023

    @garloff
    MemberAuthor

    One possibility would be to add the unfortunately missing flavor alias support to nova.
    When users request old names, they would silently get the flavors with the new names instead, introducing a flavor_by_name matching that also hits the alias names.
    The attached PoC works nicely with the openstackclient tools.
    Testing with other tools (capo, occm, terraform) still has to be done.
    scs-flavor-by-alias.diff

  2. garloff commented on Feb 18, 2023

    @garloff
    MemberAuthor

    From: Kurt Garloff [email protected]
    Subject: Allow query flavor by name, support alias in desc

    When flavors get renamed, all running instances will automatically
    see the new names, as they reference the flavors by the unchanged
    flavor IDs.

    Infra-as-Code tooling from users or from Operators acting as a user
    (such as for example the k8s-cluster-api-provider in a managed KaaS
    setting) may have configuration with the old flavor names and thus
    starts failing after the rename.

    nova unfortunately does not have a mechanism to support ailases
    for flavors. It does not even expose functionaliaty to find flavors
    by name via the API. Neither GET NOVA_URL/v2.1/flavors?name=NAME
    nor GET NOVA_URL/v2.1/flavors/NAME work. The openstackclient
    on openstack flavor show NAME instead gets a list of all flavors,
    searches it for the ID and then does another query with the ID.

    To remediate this, we do two things:
    (1) We support GET NOVA_URL/v2.1/flavors/NAME. This is only
    invoked if the lookup by ID failed and if the NAME starts
    with SCS. This will get logged.
    This significantly speeds up openstack flavor show SCSNAME
    if there is a long list of flavors, as we don't need to transfer
    that list. Other tools that don't check whether an identifer
    is or is not a UUID and just try (like openstackclient does)
    will benefit likewise.
    (2) When the GET NOVA_URL/v2.1/flavors/NAME happens and the
    name starts with SCS but is not found, another database lookup
    is done, checking whether an entry with alias=NAME exists
    in the description column of the flavors table. This will
    create another log entry.

    This works nicely for openstackclient server create and flavor show.

    The strategy for a flavor rename could thus be implemented as:
    Rename all flavors from OLDNAME to NEWNAME and add alias=OLDNAME
    into the description. The nova API does not expose the rename
    capability, so it must be done in the database (nova_api flavors
    table). It is recommended to script and carefully test this.
    The alias support could be dropped later, when no log entries are
    created any more indicating that the alias support is no longer
    needed.

    Considerations for risks and adverse effects:

    • The description field was only introduced in compute API microversion
      2.55 and is thus often not even reported and thus unlikely used much.
      So we can indeed store our alias information there.
      (We could of course also do a few python replace lines to do the
      translations without storing anything in any table; this would be
      very SCS specific then.)
    • The description field is part of the main flavor database table;
      another query to it will not cause any significant load. Instead,
      avoiding to transfer the list of flavors will likely be beneficial
      for the overall load on the server.
    • The likelihood for some tool getting confused that
      GET NOVA_URL/v2.1/flavors/NAME succeeds is negligible. We limit
      this to names starting with SCS which should not have any duplicates.
      The extra check for SCS names is an extra safety measure which
      could be dropped to make this aliasing support more generally useful.
    • There is some likelihood that some tool gets confused if a flavor
      by name is searched and found and the reported name then diverges from
      what has been asked for. Careful code might have assertions that fail.
    • There is a chance that some IaC tools don't just try the GET call
      but recognize that an identifier is not a UUID and thus query
      the list immediately. For these tools, the workaround will be
      ineffective. We should validate capo, occm, terraform here.

    Way forward:

    • This is of course a workaround that compensates for a missing flavor
      alias support functionality upstream. A good solution would be to
      have a generic mechanism for this drafted in a blueprint and
      submitted and merged upstream.
    • The design would probably implement a standard REST interface for
      searching, i.e. GET NOVA_URL/v2.1/flavors?name=XXX (and also
      other attributes). The openstackclient should detect that an identifier
      is not a UUID and the use this new interface when searching for
      a flavor by name.
    • There probably would be a discussion whether the alias belongs into
      the properties (stored in the separate flavor_extra_specs table).
      This would be cleaner and at the same time slightly worse in terms
      of performance.
    • As this is a new interface, all tools (terraform, capo, occm, ...)
      would need to be taught about this.

    Signed-off-by: Kurt Garloff [email protected]

    --- nova/objects/flavor.py.orig 2023-02-18 07:27:33.635806306 +0000
    +++ nova/objects/flavor.py      2023-02-18 09:49:55.456418712 +0000
    @@ -12,6 +12,7 @@
     #    License for the specific language governing permissions and limitations
     #    under the License.
    
    +from oslo_log import log as logging
     from oslo_db import exception as db_exc
     from oslo_db.sqlalchemy import utils as sqlalchemyutils
     from oslo_utils import versionutils
    @@ -31,6 +32,8 @@ from nova import objects
     from nova.objects import base
     from nova.objects import fields
    
    +LOG = logging.getLogger(__name__)
    +
     OPTIONAL_FIELDS = ['extra_specs', 'projects']
     # Remove these fields in version 2.0 of the object.
     DEPRECATED_FIELDS = ['deleted', 'deleted_at']
    @@ -298,6 +301,12 @@ class Flavor(base.NovaPersistentObject,
             result = Flavor._flavor_get_query_from_db(context).\
                                 filter_by(name=name).\
                                 first()
    +        if not result and name and name[:3] == "SCS":
    +            LOG.info("Flavor name %(name)s not found by name, searching by description",
    +                     {'name': name})
    +            result = Flavor._flavor_get_query_from_db(context).\
    +                            filter_by(description="alias="+name).\
    +                            first()
             if not result:
                 raise exception.FlavorNotFoundByName(flavor_name=name)
             return _dict_with_extra_specs(result)
    --- nova/compute/flavors.py.orig        2023-02-18 08:49:00.974344243 +0000
    +++ nova/compute/flavors.py     2023-02-18 09:08:39.899905822 +0000
    @@ -20,6 +20,7 @@
    
     import re
    
    +from oslo_log import log as logging
     from oslo_utils import strutils
     from oslo_utils import uuidutils
    
    @@ -32,6 +33,7 @@ from nova import objects
     from nova import utils
    
     CONF = nova.conf.CONF
    +LOG = logging.getLogger(__name__)
    
     # Validate extra specs key names.
     VALID_EXTRASPEC_NAME_REGEX = re.compile(r"[\w\.\- :]+$", re.UNICODE)
    @@ -136,7 +138,19 @@ def get_flavor_by_flavor_id(flavorid, ct
         if ctxt is None:
             ctxt = context.get_admin_context(read_deleted=read_deleted)
    
    -    return objects.Flavor.get_by_flavor_id(ctxt, flavorid, read_deleted)
    +    try:
    +        obj = objects.Flavor.get_by_flavor_id(ctxt, flavorid, read_deleted)
    +    except exception.FlavorNotFound as exc:
    +        if flavorid[:3] == "SCS":
    +            try:
    +                obj = objects.Flavor.get_by_name(ctxt, flavorid)
    +                LOG.info("Fallback finding flavor by name %(nm)s",
    +                         {'nm': flavorid})
    +                return obj
    +            except exception.FlavorNotFound:
    +                raise exc
    +        raise exc
    +    return obj
    
     # NOTE(danms): This method is deprecated, do not use it!
     # Use instance.{old_,new_,}flavor instead, as instances no longer
  3. added
    enhancement
    IaaS
    standards
    on Feb 21, 2023
  4. moved this from Backlog to Blocked / On hold in Sovereign Cloud Stackon Feb 21, 2023
  5. garloff commented on Feb 21, 2023

    @garloff
    MemberAuthor

    Would be good to understand whether that approach is:
    (1) highly appreciate and we should further pursue it
    (2) appreciated from a conceptual point of view but would require a more clean upstream approach
    (3) totally hated as it's a hack

  6. garloff commented on Feb 27, 2023

    @garloff
    MemberAuthor

    Some challenges of avoiding standardized flavor naming can be read in SovereignCloudStack/issues#287.

  7. garloff commented on Mar 7, 2023

    @garloff
    MemberAuthor

    Note: The IDs of flavors can be chosen arbitrarily, they don't necessarily need to be in UUID format.

    This opens another option to have a smooth transition v1->v2:
    0. Stop nova-api (no new servers)

    1. Backup server and flavor database tables (this includes the flavor_extra_specs)
    2. Change the flavor ID references to flavor names in the server database table.
    3. Change the flavor table in the DB to have the old name as ID and the new name as name.
    4. Do consistency checks
    5. Roll back in case of error, otherwise commit changes
    6. Restart nova-api

    The DB changes of course should be scripted (python) and tested very carefully.
    Some research needs to be done whether any other place exists that references the flavors.

    The theory is that after this change

    • All running VMs will still have a valid flavor.
    • VMs started freshly with old names will work (as the old name matches the ID)
    • VMs started freshly with new names will also work
    • The flavor list displays the new names

    The billing system which is likely assigning prices to flavors would need to be adjusted to understand the new names.

  8. self-assigned this
    on Jun 7, 2023
  9. moved this from Blocked / On hold to Doing in Sovereign Cloud Stackon Jun 7, 2023
  10. added this to the R5 (v6.0.0) milestone on Jun 7, 2023
  11. added
    Sprint Dublin
    Sprint Edmonton
    on Jun 7, 2023
  12. assigned and unassigned on Aug 9, 2023
  13. mbuechse commented on Aug 16, 2023

    @mbuechse
    Contributor

    Alias Proposal

    • use extra_specs to store any aliases, e.g.,
      • scs:name-v2=SCS-4V-16
      • my-namespace-name=extra-large
    • equip Nova REST API with filter expressions such as
      • GET novaURL/flavors?property%3Ascs%3Aname-v2=SCS-4V-16 (%3A is uri-encoded :)
      • GET novaURL/flavors?property%3Amy-namespace-name=extra-large

    (The uri-encoding of colons may not be necessary, for the Glance API docs don't do it.)

  14. removed their assignment
    on Aug 16, 2023
  15. moved this from Doing to Backlog in Sovereign Cloud Stackon Aug 22, 2023
  16. mbuechse commented on Aug 21, 2024

    @mbuechse
    Contributor

    I guess I will finally close this issue. We have the extra-specs. If people need server-side queries, then we have to open a new issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    IaaSSCS is standardizedSprint DublinSprint Edmontonenhancementstandards

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions