This commit is contained in:
parent
2f51866ad3
commit
c3e395ea2a
@ -19,7 +19,7 @@ def ensure_running_pod_on_site(site: str):
|
||||
version = 'v1beta1' # str | the custom resource's version
|
||||
namespace = 'birbnetes' # str | The custom resource's namespace
|
||||
plural = 'federateddeployments' # str | the custom resource's plural name. For TPRs this would be lowercase plural kind.
|
||||
name = f'svm-prefilter-service-{site}' # str | the custom object's name
|
||||
name = 'svm-prefilter-service' # str | the custom object's name
|
||||
|
||||
try:
|
||||
api_response = api_instance.get_namespaced_custom_object(group, version, namespace, plural, name)
|
||||
@ -27,13 +27,51 @@ def ensure_running_pod_on_site(site: str):
|
||||
logger.error("Exception when calling CustomObjectsApi->get_namespaced_custom_object: %s\n" % e)
|
||||
raise
|
||||
|
||||
if api_response['spec']['template']['spec']['replicas'] != 0:
|
||||
logging.debug("It seems like that this site have working replicas")
|
||||
return
|
||||
patch_needed = False
|
||||
|
||||
api_response['spec']['template']['spec']['replicas'] = 1
|
||||
override_id_for_this_site = -1
|
||||
for i, override in enumerate(api_response['spec']['overrides']):
|
||||
if override['clusterName'] == site:
|
||||
override_id_for_this_site = i
|
||||
break
|
||||
|
||||
if override_id_for_this_site == -1:
|
||||
api_response['spec']['overrides'].append(
|
||||
{
|
||||
"clusterName": site,
|
||||
"clusterOverrides": [
|
||||
{
|
||||
"path": "/spec/replicas",
|
||||
"value": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
patch_needed = True
|
||||
else:
|
||||
cluster_override_id = -1
|
||||
for i, cluster_override in enumerate(
|
||||
api_response['spec']['overrides'][override_id_for_this_site]['clusterOverrides']
|
||||
):
|
||||
if cluster_override['path'] == "/spec/replicas":
|
||||
cluster_override_id = i
|
||||
break
|
||||
|
||||
if cluster_override_id == -1:
|
||||
api_response['spec']['overrides'][override_id_for_this_site]['clusterOverrides'].append(
|
||||
{"path": "/spec/replicas", "value": 1}
|
||||
)
|
||||
patch_needed = True
|
||||
else:
|
||||
current_replicas = api_response['spec']['overrides'][override_id_for_this_site]['clusterOverrides'][cluster_override_id]['value']
|
||||
if current_replicas == 0:
|
||||
api_response['spec']['overrides'][override_id_for_this_site]['clusterOverrides'][cluster_override_id]['value'] = 1
|
||||
patch_needed = True
|
||||
|
||||
if patch_needed:
|
||||
logger.info("Patching object to fulfill request...")
|
||||
api_instance.patch_namespaced_custom_object(group, version, namespace, plural, name, api_response)
|
||||
|
||||
# TODO: Wait for pod to start up
|
||||
time.sleep(7) # close enough
|
||||
else:
|
||||
logger.debug("No patching needed...")
|
||||
|
Loading…
Reference in New Issue
Block a user