9.0.0
This commit is contained in:
@@ -23,6 +23,7 @@ class decort_k8s(DecortController):
|
||||
validated_rg_facts = None
|
||||
validated_k8ci_id = 0
|
||||
self.k8s_should_exist = False
|
||||
self.is_k8s_stopped_or_will_be_stopped: None | bool = None
|
||||
|
||||
self.wg_default_params = {
|
||||
'num': 1,
|
||||
@@ -77,62 +78,12 @@ class decort_k8s(DecortController):
|
||||
rg_id=validated_rg_id,
|
||||
check_state=False)
|
||||
|
||||
if self.k8s_id:
|
||||
if self.k8s_id and self.k8s_info['status'] != 'DESTROYED':
|
||||
self.k8s_should_exist = True
|
||||
self.acc_id = self.k8s_info['accountId']
|
||||
# check workers and groups for add or remove?
|
||||
|
||||
aparam_sysctl = arg_amodule.params['lb_sysctl']
|
||||
if aparam_sysctl is not None:
|
||||
_, lb_info = self._lb_get_by_id(lb_id=self.k8s_info['lbId'])
|
||||
sysctl_with_str_values = {
|
||||
k: str(v) for k, v in aparam_sysctl.items()
|
||||
}
|
||||
if sysctl_with_str_values != lb_info['sysctlParams']:
|
||||
self.message(
|
||||
'Check for parameter "lb_sysctl" failed: '
|
||||
'cannot change lb_sysctl for an existing cluster '
|
||||
'load balancer.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
if not self.k8s_id:
|
||||
validated_k8ci_id = self.k8s_k8ci_find(arg_amodule.params['k8ci_id'])
|
||||
if not validated_k8ci_id:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "Cannot find K8CI ID {}.".format(arg_amodule.params['k8ci_id'])
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
if not arg_amodule.params['workers']:
|
||||
self.result['failed'] = True
|
||||
self.result['changed'] = False
|
||||
self.result['msg'] = "At least one worker group must be present"
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
if (
|
||||
arg_amodule.params['lb_sysctl'] is not None
|
||||
and not arg_amodule.params['with_lb']
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "lb_sysctl" failed: '
|
||||
'"lb_sysctl" can only be set if the parameter "with_lb" '
|
||||
'is set to True.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
if (
|
||||
self.aparams['master_count'] is not None
|
||||
and self.aparams['master_count'] > 1
|
||||
and not self.aparams['with_lb']
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "master_count" failed: '
|
||||
'master_count can be more than 1 only if the parameter '
|
||||
'"with_lb" is set to True.'
|
||||
)
|
||||
self.exit(fail=True)
|
||||
|
||||
self.check_amodule_args_for_change()
|
||||
else:
|
||||
self.check_amodule_args_for_create()
|
||||
return
|
||||
|
||||
def package_facts(self,check_mode=False):
|
||||
@@ -168,6 +119,7 @@ class decort_k8s(DecortController):
|
||||
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
|
||||
|
||||
@@ -240,6 +192,7 @@ class decort_k8s(DecortController):
|
||||
self.amodule.params['extnet_only'],
|
||||
master_chipset,
|
||||
lb_sysctl=self.amodule.params['lb_sysctl'],
|
||||
zone_id=self.aparams['zone_id'],
|
||||
)
|
||||
|
||||
if not k8s_id:
|
||||
@@ -270,7 +223,7 @@ class decort_k8s(DecortController):
|
||||
self.k8s_should_exist = False
|
||||
return
|
||||
|
||||
def action(self, disared_state, started=True, preupdate: bool = False):
|
||||
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'
|
||||
@@ -292,14 +245,19 @@ class decort_k8s(DecortController):
|
||||
# K8s info updating
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
#k8s state
|
||||
self.k8s_state(self.k8s_info, disared_state, started)
|
||||
self.k8s_state(self.k8s_info, disared_state)
|
||||
self.k8s_info = self.k8s_get_by_id(k8s_id=self.k8s_id)
|
||||
if started == True and self.k8s_info['techStatus'] == "STOPPED":
|
||||
self.k8s_state(self.k8s_info, disared_state,started)
|
||||
self.k8s_info['techStatus'] == "STARTED"
|
||||
#check groups and modify if needed
|
||||
if self.aparams['workers'] is not None:
|
||||
self.k8s_workers_modify(self.k8s_info, self.amodule.params['workers'])
|
||||
|
||||
aparam_zone_id = self.aparams['zone_id']
|
||||
if aparam_zone_id is not None and aparam_zone_id != self.k8s_info['zoneId']:
|
||||
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)
|
||||
#TODO check workers metadata and modify if needed
|
||||
@@ -328,17 +286,14 @@ class decort_k8s(DecortController):
|
||||
'disabled',
|
||||
'enabled',
|
||||
'present',
|
||||
'check',
|
||||
'started',
|
||||
'stopped',
|
||||
],
|
||||
),
|
||||
permanent=dict(
|
||||
type='bool',
|
||||
default=False,
|
||||
),
|
||||
started=dict(
|
||||
type='bool',
|
||||
default=True,
|
||||
),
|
||||
name=dict(
|
||||
type='str',
|
||||
default='',
|
||||
@@ -490,18 +445,110 @@ class decort_k8s(DecortController):
|
||||
lb_sysctl=dict(
|
||||
type='dict',
|
||||
),
|
||||
zone_id=dict(
|
||||
type='int',
|
||||
),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
required_one_of=[
|
||||
('id', 'name'),
|
||||
],
|
||||
)
|
||||
|
||||
def check_amodule_args_for_change(self):
|
||||
check_errors = False
|
||||
|
||||
self.is_k8s_stopped_or_will_be_stopped = (
|
||||
(
|
||||
self.k8s_info['techStatus'] == 'STOPPED'
|
||||
and (
|
||||
self.aparams['state'] is None
|
||||
or self.aparams['state'] in ('present', 'stopped')
|
||||
)
|
||||
)
|
||||
or (
|
||||
self.k8s_info['techStatus'] != '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'])
|
||||
sysctl_with_str_values = {
|
||||
k: str(v) for k, v in aparam_sysctl.items()
|
||||
}
|
||||
if sysctl_with_str_values != lb_info['sysctlParams']:
|
||||
self.message(
|
||||
'Check for parameter "lb_sysctl" failed: '
|
||||
'cannot change lb_sysctl for an existing cluster '
|
||||
'load balancer.'
|
||||
)
|
||||
check_errors = True
|
||||
|
||||
if self.check_aparam_zone_id() is False:
|
||||
check_errors = True
|
||||
if (
|
||||
self.aparams['zone_id'] is not None
|
||||
and self.aparams['zone_id'] != self.k8s_info['zoneId']
|
||||
and not self.is_k8s_stopped_or_will_be_stopped
|
||||
):
|
||||
check_errors = True
|
||||
self.message(
|
||||
'Check for parameter "zone_id" failed: '
|
||||
'K8s cluster must be stopped to migrate to a zone.'
|
||||
)
|
||||
|
||||
if check_errors:
|
||||
self.exit(fail=True)
|
||||
|
||||
def check_amodule_args_for_create(self):
|
||||
check_errors = False
|
||||
|
||||
validated_k8ci_id = self.k8s_k8ci_find(self.aparams['k8ci_id'])
|
||||
if not validated_k8ci_id:
|
||||
self.message(f'Cannot find K8CI ID {"k8ci_id"}.')
|
||||
check_errors = True
|
||||
|
||||
if not self.aparams['workers']:
|
||||
self.message('At least one worker group must be present.')
|
||||
check_errors = True
|
||||
|
||||
if (
|
||||
self.aparams['lb_sysctl'] is not None
|
||||
and not self.aparams['with_lb']
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "lb_sysctl" failed: '
|
||||
'"lb_sysctl" can only be set if the parameter "with_lb" '
|
||||
'is set to True.'
|
||||
)
|
||||
check_errors = True
|
||||
|
||||
if (
|
||||
self.aparams['master_count'] is not None
|
||||
and self.aparams['master_count'] > 1
|
||||
and not self.aparams['with_lb']
|
||||
):
|
||||
self.message(
|
||||
'Check for parameter "master_count" failed: '
|
||||
'master_count can be more than 1 only if the parameter '
|
||||
'"with_lb" is set to True.'
|
||||
)
|
||||
check_errors = True
|
||||
|
||||
if self.check_aparam_zone_id() is False:
|
||||
check_errors = True
|
||||
|
||||
if check_errors:
|
||||
self.exit(fail=True)
|
||||
|
||||
|
||||
def main():
|
||||
subj = decort_k8s()
|
||||
amodule = subj.amodule
|
||||
|
||||
if amodule.params['state'] == 'check':
|
||||
if subj.amodule.check_mode:
|
||||
subj.result['changed'] = False
|
||||
if subj.k8s_id:
|
||||
# cluster is found - package facts and report success to Ansible
|
||||
@@ -521,7 +568,9 @@ def main():
|
||||
"ENABLING","DISABLING","RESTORING","MODELED"):
|
||||
subj.error()
|
||||
elif subj.k8s_info['status'] == "DELETED":
|
||||
if amodule.params['state'] in ('disabled', 'enabled', 'present'):
|
||||
if amodule.params['state'] in (
|
||||
'disabled', 'enabled', 'present', 'started', 'stopped'
|
||||
):
|
||||
subj.k8s_restore(subj.k8s_id)
|
||||
subj.action(disared_state=amodule.params['state'],
|
||||
preupdate=True)
|
||||
@@ -530,24 +579,15 @@ def main():
|
||||
subj.destroy()
|
||||
else:
|
||||
subj.nop()
|
||||
elif subj.k8s_info['techStatus'] in ("STARTED","STOPPED"):
|
||||
if amodule.params['state'] == 'disabled':
|
||||
subj.action(amodule.params['state'])
|
||||
elif amodule.params['state'] == 'absent':
|
||||
subj.destroy()
|
||||
else:
|
||||
subj.action(amodule.params['state'],amodule.params['started'])
|
||||
elif subj.k8s_info['status'] == "DISABLED":
|
||||
elif subj.k8s_info['status'] in ('ENABLED', 'DISABLED'):
|
||||
if amodule.params['state'] == 'absent':
|
||||
subj.destroy()
|
||||
elif amodule.params['state'] in ('present','enabled'):
|
||||
subj.action(amodule.params['state'],amodule.params['started'])
|
||||
else:
|
||||
subj.nop()
|
||||
elif subj.k8s_info['status'] == "DESTROED":
|
||||
subj.action(disared_state=amodule.params['state'])
|
||||
elif subj.k8s_info['status'] == "DESTROYED":
|
||||
if amodule.params['state'] in ('present','enabled'):
|
||||
subj.create()
|
||||
if amodule.params['state'] == 'absent':
|
||||
if amodule.params['state'] == 'absent':
|
||||
subj.nop()
|
||||
else:
|
||||
if amodule.params['state'] == 'absent':
|
||||
|
||||
Reference in New Issue
Block a user