raise K8sException("kdu_instance {} not found".format(kdu_instance))
# init env, paths
- paths, env = self._init_paths_env(
+ paths, _ = self._init_paths_env(
cluster_name=cluster_uuid, create_if_not_exist=True
)
resource_name=resource_name,
)
+ self.log.debug(
+ f"Number of replicas of the KDU instance {kdu_instance} and resource {resource_name} obtained: {replicas}"
+ )
+
# Get default value if scale count is not found from provided values
- if not replicas:
+ # Important note: this piece of code shall only be executed in the first scaling operation,
+ # since it is expected that the _get_replica_count_instance is able to obtain the number of
+ # replicas when a scale operation was already conducted previously for this KDU/resource!
+ if replicas is None:
repo_url = await self._find_repo(
kdu_model=kdu_model, cluster_uuid=cluster_uuid
)
kdu_model=kdu_model, repo_url=repo_url, resource_name=resource_name
)
- if not replicas:
- msg = "Replica count not found. Cannot be scaled"
- self.log.error(msg)
- raise K8sException(msg)
+ self.log.debug(
+ f"Number of replicas of the Helm Chart package for KDU instance {kdu_instance} and resource "
+ f"{resource_name} obtained: {replicas}"
+ )
+
+ if replicas is None:
+ msg = "Replica count not found. Cannot be scaled"
+ self.log.error(msg)
+ raise K8sException(msg)
return int(replicas)
kdu_model: str,
repo_url: str = None,
resource_name: str = None,
- ):
+ ) -> (int, str):
"""Get the replica count value in the Helm Chart Values.
Args:
resource_name: Resource name
Returns:
- True if replicas, False replicaCount
+ A tuple with:
+ - The number of replicas of the specific instance; if not found, returns None; and
+ - The string corresponding to the replica count key in the Helm values
"""
kdu_values = yaml.load(
Loader=yaml.SafeLoader,
)
+ self.log.debug(f"Obtained the Helm package values for the KDU: {kdu_values}")
+
if not kdu_values:
raise K8sException(
"kdu_values not found for kdu_model {}".format(kdu_model)
replica_str = ""
replicas = None
- if kdu_values.get("replicaCount", None):
+ if kdu_values.get("replicaCount") is not None:
replicas = kdu_values["replicaCount"]
replica_str = "replicaCount"
- elif kdu_values.get("replicas", None):
+ elif kdu_values.get("replicas") is not None:
duplicate_check = True
replicas = kdu_values["replicas"]
replica_str = "replicas"
namespace: str,
kubeconfig: str,
resource_name: str = None,
- ):
+ ) -> int:
"""Get the replica count value in the instance.
Args:
resource_name: Resource name
Returns:
- True if replicas, False replicaCount
+ The number of replicas of the specific instance; if not found, returns None
"""
kdu_values = yaml.load(
Loader=yaml.SafeLoader,
)
+ self.log.debug(f"Obtained the Helm values for the KDU instance: {kdu_values}")
+
replicas = None
if kdu_values:
resource_values = (
kdu_values.get(resource_name, None) if resource_name else None
)
- replicas = (
- (
- resource_values.get("replicaCount", None)
- or resource_values.get("replicas", None)
- )
- if resource_values
- else (
- kdu_values.get("replicaCount", None)
- or kdu_values.get("replicas", None)
- )
- )
+
+ for replica_str in ("replicaCount", "replicas"):
+ if resource_values:
+ replicas = resource_values.get(replica_str)
+ else:
+ replicas = kdu_values.get(replica_str)
+
+ if replicas is not None:
+ break
return replicas