From 4aaacc7919e6f12239713e8f65ab1ccc68d67f50 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 28 Jun 2022 16:36:44 -0700 Subject: [PATCH] Fix ignore_provider_quota in statemachine drivers The statemachine driver copied the quota handling from OpenStack, which also included a check for the presence of the ignore_provider_quota configuration attribute. This attribute does not exist in any of the statemachine drivers, and due to the way the check was constructed, it meant that we defaulted to ignoring the provider quota rather than actually checking it. We should perform this check so that providers can exclude themselves if there is no possibility of satisfying a request. This corrects the check. Change-Id: I7ced3f749a1646ecbb2b80f93b26e61a4e8cd69a --- nodepool/driver/__init__.py | 1 + nodepool/driver/statemachine.py | 14 ++++++++------ nodepool/driver/utils.py | 9 +++++---- ...fix-ignore-provider-quota-e7e5efd6f8ffb4a0.yaml | 6 ++++++ 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/fix-ignore-provider-quota-e7e5efd6f8ffb4a0.yaml diff --git a/nodepool/driver/__init__.py b/nodepool/driver/__init__.py index 12e00558c..eee016285 100644 --- a/nodepool/driver/__init__.py +++ b/nodepool/driver/__init__.py @@ -861,6 +861,7 @@ class ConfigPool(ConfigValue, metaclass=abc.ABCMeta): self.max_servers = math.inf self.node_attributes = None self.priority = None + self.ignore_provider_quota = False @classmethod def getCommonSchemaDict(self): diff --git a/nodepool/driver/statemachine.py b/nodepool/driver/statemachine.py index 33e747ce0..fd4a636de 100644 --- a/nodepool/driver/statemachine.py +++ b/nodepool/driver/statemachine.py @@ -1,5 +1,5 @@ # Copyright 2019 Red Hat -# Copyright 2021 Acme Gating, LLC +# Copyright 2021-2022 Acme Gating, LLC # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -374,13 +374,15 @@ class StateMachineHandler(NodeRequestHandler): needed_quota.add( self.manager.quotaNeededByLabel(ntype, self.pool)) + ignore = False if hasattr(self.pool, 'ignore_provider_quota'): - if not self.pool.ignore_provider_quota: - cloud_quota = self.manager.estimatedNodepoolQuota() - cloud_quota.subtract(needed_quota) + ignore = self.pool.ignore_provider_quota + if not ignore: + cloud_quota = self.manager.estimatedNodepoolQuota() + cloud_quota.subtract(needed_quota) - if not cloud_quota.non_negative(): - return False + if not cloud_quota.non_negative(): + return False # Now calculate pool specific quota. Values indicating no quota default # to math.inf representing infinity that can be calculated with. diff --git a/nodepool/driver/utils.py b/nodepool/driver/utils.py index dea047223..0df42a494 100644 --- a/nodepool/driver/utils.py +++ b/nodepool/driver/utils.py @@ -296,14 +296,15 @@ class QuotaSupport: def estimatedNodepoolQuota(self): ''' - Determine how much quota is available for nodepool managed resources. - This needs to take into account the quota of the tenant, resources - used outside of nodepool and the currently used resources by nodepool, - max settings in nodepool config. This is cached for MAX_QUOTA_AGE + Determine how much quota is available for nodepool managed + resources. This needs to take into account the quota of the + tenant, resources used outside of nodepool, and the max + settings in nodepool config. This is cached for MAX_QUOTA_AGE seconds. :return: Total amount of resources available which is currently available to nodepool including currently existing nodes. + ''' if self._current_nodepool_quota: diff --git a/releasenotes/notes/fix-ignore-provider-quota-e7e5efd6f8ffb4a0.yaml b/releasenotes/notes/fix-ignore-provider-quota-e7e5efd6f8ffb4a0.yaml new file mode 100644 index 000000000..de6e55fd2 --- /dev/null +++ b/releasenotes/notes/fix-ignore-provider-quota-e7e5efd6f8ffb4a0.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + The AWS, Azure, and IBMVPC drivers now check provider quota before + accepting requests. This allows them to decline requests which + can not possibly be satisfied given provider quota constraints.