diff --git a/oks_cli/cluster.py b/oks_cli/cluster.py index cb92d85..75b15ff 100644 --- a/oks_cli/cluster.py +++ b/oks_cli/cluster.py @@ -373,8 +373,8 @@ def _create_cluster(project_name, cluster_config, output): @click.option('--cidr-service', help='CIDR of services') @click.option('--control-plane', shell_complete=shell_completions, help="Controlplane plan") @click.option('--zone', '-z', multiple=True, shell_complete=shell_completions, help="List of Control Plane availability zones") -@click.option('--enable-admission-plugins', help="List of admission plugins, separated by commas") -@click.option('--disable-admission-plugins', help="List of admission plugins, separated by commas") +@click.option('--enable-admission-plugins', shell_complete=shell_completions, help="List of admission plugins, separated by commas") +@click.option('--disable-admission-plugins', shell_complete=shell_completions, help="List of admission plugins, separated by commas") @click.option('--quirk', '-q', multiple=True, help="Quirk") @click.option('--tags', '-t', help="Comma-separated list of tags, example: 'key1=value1,key2=value2'") @click.option('--disable-api-termination', type=click.BOOL, help="Disable delete action by API") @@ -472,8 +472,8 @@ def cluster_create_command(ctx, project_name, cluster_name, description, admin, @click.option('--admin', '-a', help="Admin Whitelist ips. you can use 'my-ip' to automatically use your current IP.") @click.option('--version', '-v', shell_complete=shell_completions, help="Kubernetes version") @click.option('--tags', '-t', help="Comma-separated list of tags, example: 'key1=value1,key2=value2'") -@click.option('--enable-admission-plugins', help="List of admission plugins, separated by commas") -@click.option('--disable-admission-plugins', help="List of admission plugins, separated by commas") +@click.option('--enable-admission-plugins', shell_complete=shell_completions, help="List of admission plugins, separated by commas") +@click.option('--disable-admission-plugins', shell_complete=shell_completions, help="List of admission plugins, separated by commas") @click.option('--quirk', '-q', multiple=True, help="Quirk") @click.option('--disable-api-termination', type=click.BOOL, help="Disable delete action by API") @click.option('--control-plane', shell_complete=shell_completions, help="Controlplane plan") diff --git a/oks_cli/utils.py b/oks_cli/utils.py index a0e719a..736e0eb 100644 --- a/oks_cli/utils.py +++ b/oks_cli/utils.py @@ -83,6 +83,8 @@ def find_response_object(data): return response["EimUsers"] elif key == "EimUser": return response["EimUser"] + elif key == "AdmissionPlugins": + return response["AdmissionPlugins"] elif key == "Data": return response @@ -847,9 +849,11 @@ def kubeconfig_parse_fields(kubeconfig, cluster_name, user, group): return kubedata -def retrieve_cp_sized(filepath, endpoint): +def retrieve_cp_sized(filepath, endpoint, key = None): """Fetch control plane sizes from API and save to file.""" cp_list = do_request("GET", endpoint) + if key: + cp_list = cp_list.get(key) with open(filepath, "w") as file: json.dump(cp_list, file) @@ -871,6 +875,8 @@ def shell_completions(ctx, param: click.core.Option, incomplete): if profile not in profiles: return [] + key = None + login_profile(profile) if param.name == "version": @@ -879,6 +885,16 @@ def shell_completions(ctx, param: click.core.Option, incomplete): endpoint = "clusters/limits/control_plane_plans" elif param.name == "zone": endpoint = "clusters/limits/cp_subregions" + elif param.name == "disable_admission_plugins" and ctx.params["version"]: + key = "DisableAdmissionPlugins" + version = ctx.params["version"] + endpoint = f"clusters/limits/admission_plugins?version={version}" + param.name += f".{version}" + elif param.name == "enable_admission_plugins" and ctx.params["version"]: + key = "EnableAdmissionPlugins" + version = ctx.params["version"] + endpoint = f"clusters/limits/admission_plugins?version={version}" + param.name += f".{version}" else: return [] @@ -888,9 +904,9 @@ def shell_completions(ctx, param: click.core.Option, incomplete): if os.path.exists(CP_SIZES_PATH): file_ctime = os.path.getctime(CP_SIZES_PATH) if datetime.timestamp(datetime.now()) - file_ctime > 300: - retrieve_cp_sized(CP_SIZES_PATH, endpoint) + retrieve_cp_sized(CP_SIZES_PATH, endpoint, key) else: - retrieve_cp_sized(CP_SIZES_PATH, endpoint) + retrieve_cp_sized(CP_SIZES_PATH, endpoint, key) if os.path.exists(CP_SIZES_PATH): with open(CP_SIZES_PATH, "r") as file: @@ -898,6 +914,19 @@ def shell_completions(ctx, param: click.core.Option, incomplete): else: cp_list = [] + # Handle comma-separated values + if "," in incomplete: + parts = incomplete.split(",") + selected = set(parts[:-1]) + current = parts[-1] + prefix = ",".join(parts[:-1]) + + return [ + f"{prefix},{item}" + for item in cp_list + if item.startswith(current) and item not in selected + ] + return [k for k in cp_list if k.startswith(incomplete)] def update_shell_profile(shell_profile, filepath):