From 7c75f384381ea67be73f2814e3ea69ab293f8df6 Mon Sep 17 00:00:00 2001 From: Ambrose Slone Date: Sun, 2 Aug 2020 10:27:59 -0700 Subject: [PATCH] bugfix for https://github.com/google/caliban/issues/65: do not add resource maxima when quota is < 1 (#67) This addresses an error where we specify resource maxima for GKE clusters using quota information returned from the GCP compute API. The API can return a quota of zero for a given resource type, but requesting a limit of zero in the cluster creation API causes an error, so this change prevents setting a limit of zero for any resource. --- caliban/platform/gke/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/caliban/platform/gke/util.py b/caliban/platform/gke/util.py index 9a754ea..9b4d5ea 100644 --- a/caliban/platform/gke/util.py +++ b/caliban/platform/gke/util.py @@ -378,13 +378,19 @@ def resource_limits_from_quotas( for q in quotas: metric = q['metric'] - limit = q['limit'] + limit = int(q['limit']) + + # the api can return a limit of 0, but specifying a limit of zero + # causes an error when configuring the cluster, so we skip any + # resources with no quota + if limit < 1: + continue if metric == 'CPUS': limits.append({'resourceType': 'cpu', 'maximum': str(limit)}) limits.append({ 'resourceType': 'memory', - 'maximum': str(int(limit) * k.MAX_GB_PER_CPU) + 'maximum': str(limit * k.MAX_GB_PER_CPU) }) continue