From 5e022a8c7db82cda41b700307730e71bb56a245e Mon Sep 17 00:00:00 2001 From: Murali Krishnasamy <70236227+mukrishn@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:02:34 -0400 Subject: [PATCH] removed hard coded aws acc id (#26) * Update hypershift.py * Update hypershift.py * 2 min pause before scrapping Takes a couple of minutes for the endpoints to be available, Error from server (NotFound): routes.route.openshift.io "prometheus-k8s" not found * corrected indentation * subprocess command change * Update hypershift.py * Update hypershift.py * py lint correction * f-string is missing placeholders --- libs/platforms/rosa/hypershift/hypershift.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/platforms/rosa/hypershift/hypershift.py b/libs/platforms/rosa/hypershift/hypershift.py index a778558..d8d682a 100644 --- a/libs/platforms/rosa/hypershift/hypershift.py +++ b/libs/platforms/rosa/hypershift/hypershift.py @@ -396,6 +396,15 @@ def _wait_for_workers( result.append("") return result + def _get_aws_account_id(self): + # Required by OCM-3187 (https://issues.redhat.com/browse/OCM-3187), remove when fixed + (acc_id_code, acc_id_out, acc_id_err) = self.utils.subprocess_exec("aws sts get-caller-identity --output json") + if acc_id_code == 0: + acc_id = json.loads(acc_id_out) + return acc_id['Account'] + self.logging.error("Cannot find AWS Account information for the given credentials") + return None + def create_cluster(self, platform, cluster_name): super().create_cluster(platform, cluster_name) cluster_info = platform.environment["clusters"][cluster_name] @@ -453,8 +462,9 @@ def create_cluster(self, platform, cluster_name): # Required by OCM-3187 (https://issues.redhat.com/browse/OCM-3187), remove when fixed self.logging.info(f"Getting kube-controller-manager role for cluster {cluster_name}") aws_role_name = self._get_aws_role_name(cluster_name) + aws_account_id = self._get_aws_account_id() self.logging.info(f"Found kube-controller-manager role {aws_role_name} for cluster {cluster_name}") - (aws_policy_code, aws_policy_out, aws_policy_err) = self.utils.subprocess_exec("aws iam attach-role-policy --role-name " + aws_role_name + " --policy-arn arn:aws:iam::415909267177:policy/hack-414-custom-policy") + (aws_policy_code, aws_policy_out, aws_policy_err) = self.utils.subprocess_exec("aws iam attach-role-policy --role-name " + aws_role_name + " --policy-arn arn:aws:iam::" + aws_account_id + ":policy/hack-414-custom-policy") if aws_policy_code != 0: cluster_info['status'] = "aws policy failed" return 1 @@ -539,6 +549,8 @@ def create_cluster(self, platform, cluster_name): self.logging.info("Indexing Management cluster stats") os.environ["START_TIME"] = f"{cluster_start_time_on_mc}" # excludes pre-flight durations os.environ["END_TIME"] = f"{cluster_end_time}" + self.logging.info("Waiting 2 minutes for HC prometheus to be available for scrapping") + time.sleep(120) self.utils.cluster_load(platform, cluster_name, load="index") # if cluster_load: # with all_clusters_installed: