Feature 11057: Cluster management in Openshift-based infrastructures 11/15311/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 4 Aug 2025 07:15:48 +0000 (09:15 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 4 Aug 2025 12:01:15 +0000 (14:01 +0200)
Change-Id: I643f0689340ebfec93d020a52a2cd4b65a538fd9
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/cli_commands/cluster.py

index 2acbed2..83d5c65 100755 (executable)
@@ -15,6 +15,7 @@
 
 import click
 from osmclient.cli_commands import common, utils
+from osmclient.common.exceptions import ClientException
 from osmclient.common import print_output
 import logging
 import yaml
@@ -50,6 +51,10 @@ logger = logging.getLogger("osmclient")
     default=True,
     help="bootstrap the cluster with Flux (prepare for GitOps) (default=True)",
 )
+@click.option("--config", default=None, help="cluster specific yaml configuration")
+@click.option(
+    "--config_file", default=None, help="cluster specific yaml configuration file"
+)
 @click.pass_context
 def cluster_create(
     ctx,
@@ -62,7 +67,9 @@ def cluster_create(
     region_name,
     resource_group,
     bootstrap,
-    **kwargs
+    config,
+    config_file,
+    **kwargs,
 ):
     """creates a K8s cluster
 
@@ -83,6 +90,18 @@ def cluster_create(
     if resource_group:
         cluster["resource_group"] = resource_group
     cluster["bootstrap"] = bootstrap
+    if config_file:
+        if config:
+            raise ClientException(
+                '"--config" option is incompatible with "--config_file" option'
+            )
+        with open(config_file, "r", encoding="utf-8") as cf:
+            config = cf.read()
+    if config:
+        try:
+            cluster["config"] = yaml.safe_load(config)
+        except yaml.YAMLError as e:
+            raise ClientException(f"Error parsing YAML configuration: {e}") from e
     ctx.obj.cluster.create(name, content_dict=cluster)
 
 
@@ -283,6 +302,12 @@ def cluster_get_kubeconfig(ctx, name, **kwargs):
     default=True,
     help="bootstrap the cluster with Flux (prepare for GitOps) (default=True)",
 )
+@click.option(
+    "--openshift",
+    required=False,
+    default=False,
+    help="flag to indicate that the cluster is Openshift-based (bootstrap is slightly different) (default=False)",
+)
 @click.pass_context
 def cluster_register(
     ctx,
@@ -291,6 +316,7 @@ def cluster_register(
     creds,
     description,
     bootstrap,
+    openshift,
 ):
     """registers a K8s cluster to OSM
 
@@ -305,6 +331,8 @@ def cluster_register(
     if description:
         cluster["description"] = description
     cluster["bootstrap"] = bootstrap
+    if openshift:
+        cluster["openshift"] = openshift
     ctx.obj.cluster.register(name, cluster)