diff --git a/Tests/kaas/plugin/README.md b/Tests/kaas/plugin/README.md index e4f0ae216..97616c575 100644 --- a/Tests/kaas/plugin/README.md +++ b/Tests/kaas/plugin/README.md @@ -75,10 +75,11 @@ The config file is used to set parameters for creating a Kubernetes cluster with These parameters configure specific settings for the cluster-stack: ```yaml -cs_name: # Default: "scs" -cs_version: # Default: "v1" -cs_channel: # Default: "stable" -cs_cloudname: # Default: "openstack" +cs_name: # Cluster Stack Name, default: "scs" +cs_version: # Cluster Stack Version +cs_channel: # Release channel +cs_cloudname: # Cloud name from OpenStack clouds.yaml +cs_namespace: "default" # Namespace for the Cluster Stack deployment ``` #### Git-Related Parameters @@ -86,9 +87,9 @@ cs_cloudname: # Default: "openstack" The [Cluster Stack Operator](https://github.com/sovereignCloudStack/cluster-stack-operator/) (CSO) utilizing the [Cluster Stack Provider OpenStack](https://github.com/SovereignCloudStack/cluster-stacks/tree/main/providers/openstack) (CSPO) must be directed to the Cluster Stacks repository housing releases for the OpenStack provider. Modify the following parameters if you wish to redirect CSO and CSPO to an alternative Git repository ```yaml -git_provider: # Default: "github" -git_org_name: # Default: "SovereignCloudStack" -git_repo_name: # Default: "cluster-stacks" +git_provider: # Git provider, default: "github" +git_org_name: # Organization name on Git provider, default: "SovereignCloudStack" +git_repo_name: # Repository name on Git provider, default: "cluster-stacks" ``` #### Cluster Parameters @@ -96,8 +97,8 @@ git_repo_name: # Default: "cluster-stacks" Set these parameters to customize the configuration for your cluster. ```yaml -cs_pod_cidr: # Default: "192.168.0.0/16" -cs_service_cidr: # Default: "10.96.0.0/12" -cs_external_id: # Default: A generated UUID -cs_k8s_patch_version: # Default: "6" +cs_pod_cidr: # Pod CIDR for networking +cs_service_cidr: # Service CIDR for networking +cs_external_id: # External ID for the Cluster Stack +cs_k8s_patch_version: # Kubernetes patch version to use ``` diff --git a/Tests/kaas/plugin/plugin_cluster_stacks.py b/Tests/kaas/plugin/plugin_cluster_stacks.py index 6c1ba071c..0b31ed6fb 100644 --- a/Tests/kaas/plugin/plugin_cluster_stacks.py +++ b/Tests/kaas/plugin/plugin_cluster_stacks.py @@ -175,9 +175,9 @@ def create_cluster(self, cluster_name="scs-cluster", version=None, kubeconfig_fi self._apply_yaml_with_envsubst("cluster.yaml", "Error applying cluster.yaml", kubeconfig=self.kubeconfig_mgmnt_path) # Get and wait on kubeadmcontrolplane and retrieve workload cluster kubeconfig - kcp_name = self._get_kubeadm_control_plane_name(kubeconfig=self.kubeconfig_mgmnt_path) - self._wait_kcp_ready(kcp_name, kubeconfig=self.kubeconfig_mgmnt_path) - self._retrieve_kubeconfig(kubeconfig=self.kubeconfig_mgmnt_path) + kcp_name = self._get_kubeadm_control_plane_name(namespace=self.cs_namespace, kubeconfig=self.kubeconfig_mgmnt_path) + self._wait_kcp_ready(kcp_name, namespace=self.cs_namespace, kubeconfig=self.kubeconfig_mgmnt_path) + self._retrieve_kubeconfig(namespace=self.cs_namespace, kubeconfig=self.kubeconfig_mgmnt_path) # Wait for workload system pods to be ready # wait_for_workload_pods_ready(kubeconfig_path=self.kubeconfig_cs_cluster) @@ -188,12 +188,12 @@ def delete_cluster(self, cluster_name=None, kubeconfig_filepath=None): kubeconfig_cs_cluster_filename = kubeconfig_filepath try: # Check if the cluster exists - check_cluster_command = f"kubectl get cluster {cluster_name}" + check_cluster_command = f"kubectl get cluster {cluster_name} -n {self.cs_namespace}" result = self._run_subprocess(check_cluster_command, "Failed to get cluster resource", shell=True, capture_output=True, text=True, kubeconfig=self.kubeconfig_mgmnt_path) # Proceed with deletion only if the cluster exists if result.returncode == 0: - delete_command = f"kubectl delete cluster {cluster_name} --timeout=600s" + delete_command = f"kubectl delete cluster {cluster_name} --timeout=600s -n {self.cs_namespace}" self._run_subprocess(delete_command, "Timeout while deleting the cluster", shell=True, kubeconfig=self.kubeconfig_mgmnt_path) except subprocess.CalledProcessError as error: @@ -237,10 +237,12 @@ def _apply_yaml_with_envsubst(self, yaml_file, error_msg, kubeconfig=None): except subprocess.CalledProcessError as error: raise RuntimeError(f"{error_msg}: {error}") - def _get_kubeadm_control_plane_name(self, kubeconfig=None): + def _get_kubeadm_control_plane_name(self, namespace="default", kubeconfig=None): """ - Retrieves the name of the KubeadmControlPlane resource for the Kubernetes cluster. + Retrieves the name of the KubeadmControlPlane resource for the Kubernetes cluster + in the specified namespace. + :param namespace: The namespace to search for the KubeadmControlPlane resource. :param kubeconfig: Optional path to the kubeconfig file for the target Kubernetes cluster. :return: The name of the KubeadmControlPlane resource as a string. @@ -250,7 +252,8 @@ def _get_kubeadm_control_plane_name(self, kubeconfig=None): for _ in range(max_retries): try: kcp_command = ( - "kubectl get kubeadmcontrolplane -o=jsonpath='{.items[0].metadata.name}'" + f"kubectl get kubeadmcontrolplane -n {namespace} " + "-o=jsonpath='{.items[0].metadata.name}'" ) kcp_name = self._run_subprocess(kcp_command, "Error retrieving kcp_name", shell=True, capture_output=True, text=True, kubeconfig=kubeconfig) logger.info(kcp_name) @@ -265,16 +268,17 @@ def _get_kubeadm_control_plane_name(self, kubeconfig=None): else: raise RuntimeError("Failed to get kubeadmcontrolplane name") - def _wait_kcp_ready(self, kcp_name, kubeconfig=None): + def _wait_kcp_ready(self, kcp_name, namespace="default", kubeconfig=None): """ Waits for the specified KubeadmControlPlane resource to become 'Available'. :param kcp_name: The name of the KubeadmControlPlane resource to check for availability. + :param namespace: The namespace where the KubeadmControlPlane resource is. :param kubeconfig: Optional path to the kubeconfig file for the target Kubernetes cluster. """ try: self._run_subprocess( - f"kubectl wait kubeadmcontrolplane/{kcp_name} --for=condition=Available --timeout=600s", + f"kubectl wait kubeadmcontrolplane/{kcp_name} --for=condition=Available --timeout=600s -n {namespace}", "Error waiting for kubeadmcontrolplane availability", shell=True, kubeconfig=kubeconfig @@ -282,14 +286,15 @@ def _wait_kcp_ready(self, kcp_name, kubeconfig=None): except subprocess.CalledProcessError as error: raise RuntimeError(f"Error waiting for kubeadmcontrolplane to be ready: {error}") - def _retrieve_kubeconfig(self, kubeconfig=None): + def _retrieve_kubeconfig(self, namespace="default", kubeconfig=None): """ Retrieves the kubeconfig for the specified cluster and saves it to a local file. + :param namespace: The namespace of the cluster to retrieve the kubeconfig for. :param kubeconfig: Optional path to the kubeconfig file for the target Kubernetes cluster. """ kubeconfig_command = ( - f"sudo -E clusterctl get kubeconfig {self.cluster_name} > {self.kubeconfig_cs_cluster}" + f"sudo -E clusterctl get kubeconfig {self.cluster_name} -n {namespace} > {self.kubeconfig_cs_cluster}" ) self._run_subprocess(kubeconfig_command, "Error retrieving kubeconfig", shell=True, kubeconfig=kubeconfig)