12.0.0
This commit is contained in:
@@ -20,7 +20,7 @@ class decort_k8s(DecortController):
|
||||
|
||||
validated_acc_id = 0
|
||||
validated_rg_id = 0
|
||||
validated_rg_facts = None
|
||||
validated_rg_model = None
|
||||
validated_k8ci_id = 0
|
||||
self.k8s_should_exist = False
|
||||
self.is_k8s_stopped_or_will_be_stopped: None | bool = None
|
||||
@@ -55,12 +55,12 @@ class decort_k8s(DecortController):
|
||||
self.amodule.fail_json(**self.result)
|
||||
# fail the module -> exit
|
||||
# now validate RG
|
||||
validated_rg_id, validated_rg_facts = self.rg_find(
|
||||
validated_rg_id, validated_rg_model = self.rg_find(
|
||||
arg_account_id=validated_acc_id,
|
||||
arg_rg_id=arg_amodule.params['rg_id'],
|
||||
arg_rg_name=arg_amodule.params['rg_name']
|
||||
)
|
||||
if not validated_rg_id:
|
||||
if not validated_rg_id or not validated_rg_model:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "Cannot find RG ID {} / name '{}'.".format(arg_amodule.params['rg_id'],
|
||||
@@ -70,19 +70,21 @@ class decort_k8s(DecortController):
|
||||
|
||||
self.rg_id = validated_rg_id
|
||||
arg_amodule.params['rg_id'] = validated_rg_id
|
||||
arg_amodule.params['rg_name'] = validated_rg_facts['name']
|
||||
self.acc_id = validated_rg_facts['accountId']
|
||||
arg_amodule.params['rg_name'] = validated_rg_model.name
|
||||
self.acc_id = validated_rg_model.account_id
|
||||
|
||||
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=arg_amodule.params['id'],
|
||||
k8s_name=arg_amodule.params['name'],
|
||||
rg_id=validated_rg_id,
|
||||
check_state=False)
|
||||
self.k8s_id, self._k8s_info = self.k8s_find(
|
||||
k8s_id=arg_amodule.params['id'],
|
||||
k8s_name=arg_amodule.params['name'],
|
||||
rg_id=validated_rg_id,
|
||||
check_state=False,
|
||||
)
|
||||
|
||||
if self.k8s_id and self.k8s_info['status'] != 'DESTROYED':
|
||||
self.k8s_should_exist = True
|
||||
self.acc_id = self.k8s_info['accountId']
|
||||
self.acc_id = self.k8s_info['account_id']
|
||||
self.check_amodule_args_for_change()
|
||||
else:
|
||||
elif arg_amodule.params['state'] != 'absent':
|
||||
self.check_amodule_args_for_create()
|
||||
return
|
||||
|
||||
@@ -96,32 +98,14 @@ class decort_k8s(DecortController):
|
||||
config=None,
|
||||
)
|
||||
|
||||
if self.amodule.params['getConfig'] and self.k8s_info['techStatus'] == "STARTED":
|
||||
ret_dict['config'] = self.k8s_getConfig()
|
||||
|
||||
if check_mode:
|
||||
# in check mode return immediately with the default values
|
||||
return ret_dict
|
||||
|
||||
#if self.k8s_facts is None:
|
||||
# #if void facts provided - change state value to ABSENT and return
|
||||
# ret_dict['state'] = "ABSENT"
|
||||
# return ret_dict
|
||||
|
||||
ret_dict['id'] = self.k8s_info['id']
|
||||
ret_dict['name'] = self.k8s_info['name']
|
||||
ret_dict['techStatus'] = self.k8s_info['techStatus']
|
||||
ret_dict['state'] = self.k8s_info['status']
|
||||
ret_dict['rg_id'] = self.k8s_info['rgId']
|
||||
ret_dict['vins_id'] = self.k8s_vins_id
|
||||
ret_dict['account_id'] = self.acc_id
|
||||
ret_dict['k8s_Masters'] = self.k8s_info['k8sGroups']['masters']
|
||||
ret_dict['k8s_Workers'] = self.k8s_info['k8sGroups']['workers']
|
||||
ret_dict['lb_id'] = self.k8s_info['lbId']
|
||||
ret_dict['description'] = self.k8s_info['desc']
|
||||
ret_dict['zone_id'] = self.k8s_info['zoneId']
|
||||
|
||||
return ret_dict
|
||||
self.k8s_info['vins_id'] = self.k8s_vins_id
|
||||
self.k8s_info['config'] = None
|
||||
if self.amodule.params['getConfig'] and self.k8s_info['tech_status'] == "STARTED":
|
||||
self.k8s_info['config'] = self.k8s_getConfig()
|
||||
return self.k8s_info
|
||||
|
||||
def nop(self):
|
||||
"""No operation (NOP) handler for k8s cluster management by decort_k8s module.
|
||||
@@ -204,10 +188,12 @@ class decort_k8s(DecortController):
|
||||
self.result['failed'] = True
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
self.k8s_id,self.k8s_info = self.k8s_find(k8s_id=k8s_id,
|
||||
k8s_name=self.amodule.params['name'],
|
||||
rg_id=self.rg_id,
|
||||
check_state=False)
|
||||
self.k8s_id, self._k8s_info = self.k8s_find(
|
||||
k8s_id=k8s_id,
|
||||
k8s_name=self.amodule.params['name'],
|
||||
rg_id=self.rg_id,
|
||||
check_state=False,
|
||||
)
|
||||
|
||||
if self.k8s_id:
|
||||
self.k8s_should_exist = True
|
||||
@@ -219,19 +205,22 @@ class decort_k8s(DecortController):
|
||||
self.aparams['storage_policy_id']
|
||||
),
|
||||
)
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
self._k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
return
|
||||
|
||||
def destroy(self):
|
||||
self.k8s_delete(self.k8s_id,self.amodule.params['permanent'])
|
||||
self.sdk_checkmode(self.api.ca.k8s.delete)(
|
||||
k8s_id=self.k8s_id,
|
||||
permanently=self.amodule.params['permanent'],
|
||||
)
|
||||
self.k8s_info['status'] = 'DELETED'
|
||||
self.k8s_should_exist = False
|
||||
return
|
||||
|
||||
def action(self, disared_state, preupdate: bool = False):
|
||||
if self.amodule.params['master_chipset'] is not None:
|
||||
for master_node in self.k8s_info['k8sGroups']['masters'][
|
||||
'detailedInfo'
|
||||
for master_node in self.k8s_info['node_groups']['master'][
|
||||
'vms'
|
||||
]:
|
||||
_, master_node_info, _ = self._compute_get_by_id(
|
||||
comp_id=master_node['id']
|
||||
@@ -247,17 +236,27 @@ class decort_k8s(DecortController):
|
||||
self.exit(fail=True)
|
||||
|
||||
if (
|
||||
self.aparams['name'] is not None
|
||||
and self.aparams['name'] != self.k8s_info['name']
|
||||
(
|
||||
self.aparams['name'] is not None
|
||||
and self.aparams['name'] != self.k8s_info['name']
|
||||
)
|
||||
or (
|
||||
self.aparams['description'] is not None
|
||||
and self.aparams['description'] != self.k8s_info['description']
|
||||
)
|
||||
):
|
||||
self.k8s_update(id=self.k8s_id, name=self.aparams['name'])
|
||||
self.sdk_checkmode(self.api.ca.k8s.update)(
|
||||
k8s_id=self.k8s_id,
|
||||
description=self.aparams['description'],
|
||||
name=self.aparams['name'],
|
||||
)
|
||||
|
||||
if preupdate:
|
||||
# K8s info updating
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
self._k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
#k8s state
|
||||
self.k8s_state(self.k8s_info, disared_state)
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
self._k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
#check groups and modify if needed
|
||||
if self.aparams['workers'] is not None:
|
||||
self.k8s_workers_modify(
|
||||
@@ -266,14 +265,17 @@ class decort_k8s(DecortController):
|
||||
)
|
||||
|
||||
aparam_zone_id = self.aparams['zone_id']
|
||||
if aparam_zone_id is not None and aparam_zone_id != self.k8s_info['zoneId']:
|
||||
if (
|
||||
aparam_zone_id is not None
|
||||
and aparam_zone_id != self.k8s_info['zone_id']
|
||||
):
|
||||
self.k8s_migrate_to_zone(
|
||||
k8s_id=self.k8s_id,
|
||||
zone_id=aparam_zone_id,
|
||||
)
|
||||
|
||||
if self.result['changed'] == True:
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
self._k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
#TODO check workers metadata and modify if needed
|
||||
|
||||
return
|
||||
@@ -413,7 +415,6 @@ class decort_k8s(DecortController):
|
||||
),
|
||||
description=dict(
|
||||
type='str',
|
||||
default='Created by decort ansible module',
|
||||
),
|
||||
with_lb=dict(
|
||||
type='bool',
|
||||
@@ -473,25 +474,25 @@ class decort_k8s(DecortController):
|
||||
|
||||
self.is_k8s_stopped_or_will_be_stopped = (
|
||||
(
|
||||
self.k8s_info['techStatus'] == 'STOPPED'
|
||||
self.k8s_info['tech_status'] == 'STOPPED'
|
||||
and (
|
||||
self.aparams['state'] is None
|
||||
or self.aparams['state'] in ('present', 'stopped')
|
||||
)
|
||||
)
|
||||
or (
|
||||
self.k8s_info['techStatus'] != 'STOPPED'
|
||||
self.k8s_info['tech_status'] != 'STOPPED'
|
||||
and self.aparams['state'] == 'stopped'
|
||||
)
|
||||
)
|
||||
|
||||
aparam_sysctl = self.aparams['lb_sysctl']
|
||||
if aparam_sysctl is not None:
|
||||
_, lb_info = self._lb_get_by_id(lb_id=self.k8s_info['lbId'])
|
||||
lb_model = self._lb_get_by_id(lb_id=self.k8s_info['lb_id'])
|
||||
sysctl_with_str_values = {
|
||||
k: str(v) for k, v in aparam_sysctl.items()
|
||||
}
|
||||
if sysctl_with_str_values != lb_info['sysctlParams']:
|
||||
if sysctl_with_str_values != lb_model.sysctl_params:
|
||||
self.message(
|
||||
'Check for parameter "lb_sysctl" failed: '
|
||||
'cannot change lb_sysctl for an existing cluster '
|
||||
@@ -503,7 +504,7 @@ class decort_k8s(DecortController):
|
||||
check_errors = True
|
||||
if (
|
||||
self.aparams['zone_id'] is not None
|
||||
and self.aparams['zone_id'] != self.k8s_info['zoneId']
|
||||
and self.aparams['zone_id'] != self.k8s_info['zone_id']
|
||||
and not self.is_k8s_stopped_or_will_be_stopped
|
||||
):
|
||||
check_errors = True
|
||||
@@ -515,13 +516,11 @@ class decort_k8s(DecortController):
|
||||
aparam_storage_policy_id = self.aparams['storage_policy_id']
|
||||
if aparam_storage_policy_id is not None:
|
||||
computes_ids = []
|
||||
for master_node in self.k8s_info['k8sGroups']['masters'][
|
||||
'detailedInfo'
|
||||
]:
|
||||
for master_node in self.k8s_info['node_groups']['master']['vms']:
|
||||
computes_ids.append(master_node['id'])
|
||||
for wg in self.k8s_info['k8sGroups']['workers']:
|
||||
for wg in self.k8s_info['node_groups']['worker']:
|
||||
workers_ids = [
|
||||
worker['id'] for worker in wg['detailedInfo']
|
||||
worker['id'] for worker in wg['vms']
|
||||
]
|
||||
computes_ids.extend(workers_ids)
|
||||
for compute_id in computes_ids:
|
||||
@@ -589,7 +588,7 @@ class decort_k8s(DecortController):
|
||||
)
|
||||
elif (
|
||||
aparam_storage_policy_id
|
||||
not in self.rg_info['storage_policy_ids']
|
||||
not in self.rg_info.storage_policy_ids
|
||||
):
|
||||
check_errors = True
|
||||
self.message(
|
||||
@@ -630,7 +629,9 @@ class decort_k8s(DecortController):
|
||||
if amodule.params['state'] in (
|
||||
'disabled', 'enabled', 'present', 'started', 'stopped'
|
||||
):
|
||||
self.k8s_restore(self.k8s_id)
|
||||
self.sdk_checkmode(self.api.ca.k8s.restore)(
|
||||
k8s_id=self.k8s_id,
|
||||
)
|
||||
self.action(disared_state=amodule.params['state'],
|
||||
preupdate=True)
|
||||
if amodule.params['state'] == 'absent':
|
||||
|
||||
Reference in New Issue
Block a user