def _pre_update_hook_modify_spec(instance_id, instance, callback, dry_run=False): # applies changes to both the non-persistent spec and persists the changes on latest instance spec latest_instance = crds_manager.get(INSTANCE_CRD_SINGULAR, crds_manager.get_resource_name( INSTANCE_CRD_SINGULAR, instance_id ), required=True) callback(instance) callback(latest_instance) kubectl.apply(latest_instance, dry_run=dry_run)
def load(cluster_id): cluster = crds_manager.get( 'kamateracluster', crds_manager.get_resource_name('kamateracluster', cluster_id))['spec'] cluster['servers'] = [] servers_path = os.path.expanduser(f'~/cluster-{cluster_id}-servers') os.makedirs(servers_path, exist_ok=True) for server_name in cluster['server_names']: server = crds_manager.get( 'kamateraserver', crds_manager.get_resource_name('kamateraserver', server_name))['spec'] server_secrets = crds_manager.config_get('kamateraserver', server_name, is_secret=True) password_filename = f'{servers_path}/server_{server_name}_password.txt' private_key_filename = f'{servers_path}/server_{server_name}_id_rsa' public_key_filename = private_key_filename + '.pub' with open(password_filename, 'w') as f: f.write(server_secrets['password']) with open(private_key_filename, 'w') as f: f.write(server_secrets['private_key']) with open(public_key_filename, 'w') as f: f.write(server_secrets['public_key']) server['passwordfile'] = password_filename server['keyfile'] = private_key_filename cluster['servers'].append(server) del cluster['server_names'] cluster_path = get_cluster_path(cluster_id) os.makedirs(cluster_path, exist_ok=True) with open(f'{cluster_path}/cluster.json', 'w') as f: json.dump(cluster, f) cluster_secrets = crds_manager.config_get('kamateracluster', cluster_id, is_secret=True) with open(f'{cluster_path}/kube_config_rke-cluster.yml', 'w') as f: f.write(cluster_secrets['kube_config_rke-cluster.yml'])
def _get_user_role_resource_name(user): name, role = _get_name_role(user) return crds_manager.get_resource_name(CRD_SINGULAR, f'user-{name}-role-{role}')
def _get_role_resource_name(user): _, role = _get_name_role(user) return crds_manager.get_resource_name(CRD_SINGULAR, f'role-{role}')