From 67757bda8f66ad916f70196e17bb68a3c7c966a8 Mon Sep 17 00:00:00 2001 From: Murali Krishnasamy <70236227+mukrishn@users.noreply.github.com> Date: Thu, 19 Dec 2024 04:17:07 -0500 Subject: [PATCH] rosa create account roles as part of hc creations (#36) --- Dockerfile | 3 ++- libs/platforms/rosa/hypershift/hypershift.py | 4 ++++ libs/platforms/rosa/rosa.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e34a777..7086578 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ RUN python3 -m pip install --upgrade pip || true RUN yes | pip3 install openshift elasticsearch==7.13.4 gitpython packaging --upgrade || true RUN apt-get -y update RUN apt-get -y install jq groff uuid-runtime -RUN curl -L $(curl -s https://api.github.com/repos/openshift/rosa/releases/latest | jq -r ".assets[] | select(.name == \"rosa-linux-amd64\") | .browser_download_url") --output /usr/local/bin/rosa +RUN curl -L $(curl -s https://api.github.com/repos/openshift/rosa/releases/latest | jq -r ".assets[] | select(.name == \"rosa_Linux_x86_64.tar.gz\") | .browser_download_url") --output rosa.tar.gz +RUN tar -xzf rosa.tar.gz -C /usr/local/bin/ RUN curl -L $(curl -s https://api.github.com/repos/openshift-online/ocm-cli/releases/latest | jq -r ".assets[] | select(.name == \"ocm-linux-amd64\") | .browser_download_url") --output /usr/local/bin/ocm RUN curl -L https://releases.hashicorp.com/terraform/1.8.0/terraform_1.8.0_linux_amd64.zip -o terraform_1.8.0_linux_amd64.zip RUN unzip terraform_1.8.0_linux_amd64.zip -d /usr/local/bin/ diff --git a/libs/platforms/rosa/hypershift/hypershift.py b/libs/platforms/rosa/hypershift/hypershift.py index 598e443..27f0dc2 100644 --- a/libs/platforms/rosa/hypershift/hypershift.py +++ b/libs/platforms/rosa/hypershift/hypershift.py @@ -59,6 +59,10 @@ def initialize(self): self.logging.info("Verifying OIDC config") sys.exit("Exiting") if not self._set_oidc_config() else self.logging.info(f"Using {self.environment['oidc_config_id']} as OIDC config ID") + # Create Account roles + self.logging.info("Creating ROSA Account roles") + sys.exit("Exiting") if not self._create_rosa_account_roles() else self.logging.info("Created Account roles successfully") + # Set Operator Roles self.logging.info("Verifying Operator Roles") if self.environment["common_operator_roles"]: diff --git a/libs/platforms/rosa/rosa.py b/libs/platforms/rosa/rosa.py index 6dd4f9e..453f64a 100644 --- a/libs/platforms/rosa/rosa.py +++ b/libs/platforms/rosa/rosa.py @@ -130,6 +130,18 @@ def _delete_oidc_config(self): self.logging.info(f"Deleted oidc-config ID {self.environment['oidc_config_id']}") return True + def _create_rosa_account_roles(self): + hc_acc_rol_code, hc_acc_rol_out, hc_acc_rol_err = self.utils.subprocess_exec( + "rosa create account-roles --hosted-cp --prefix ManagedOpenShift -y --mode auto", + extra_params={"universal_newlines": True} + ) + if hc_acc_rol_code != 0: + self.logging.error("Failed to create rosa account roles") + return False + else: + self.logging.info("Create account roles successfully") + return True + def _create_operator_roles(self): self.logging.info("Finding latest installer Role ARN") roles_code, roles_out, roles_err = self.utils.subprocess_exec("rosa list account-roles -o json")