From e6bc5d076774fb7196f9a6311308e355cbaa6a5e Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Mon, 17 Sep 2018 20:52:28 +0000 Subject: [PATCH] plugins: Add get_releases to Armada base operator Currently, the `ArmadaGetReleasesOperator` does not save any releases retrieved from the environment. In order to add future functionality that invokes Helm tests for all releases, deployed releases must be cataloged. This commit adds a method, `get_releases`, to the Armada base operator and updates existing plugins to utilize it. Additionally, this change moves the retrieval of tiller information before the Armada client is fetched in order to limit subsequent calls to the `get_tiller_info` method. Change-Id: Ib4aaec762d509994ce90460d0854e526280c4592 --- .../plugins/armada_base_operator.py | 19 +++++++++++++++++++ .../plugins/armada_get_releases.py | 17 +---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_base_operator.py b/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_base_operator.py index f988539a..aa96446d 100644 --- a/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_base_operator.py +++ b/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_base_operator.py @@ -20,6 +20,7 @@ from airflow.utils.decorators import apply_defaults import armada.common.client as client import armada.common.session as session +from armada.exceptions import api_exceptions as errors try: from get_k8s_pod_port_ip import get_pod_port_ip @@ -89,6 +90,11 @@ class ArmadaBaseOperator(UcpBaseOperator): self.svc_token ) + # Retrieve Tiller Information + # TODO(@drewwalters96): This should be explicit. Refactor in + # conjunction with `get_pod_port_ip` decorator. + self.get_tiller_info(pods_ip_port={}) + @staticmethod def _init_armada_client(armada_svc_endpoint, svc_token): @@ -125,6 +131,19 @@ class ArmadaBaseOperator(UcpBaseOperator): else: raise AirflowException("Failed to set up Armada client!") + def get_releases(self): + """Retrieve all deployed releases""" + try: + get_releases_resp = self.armada_client.get_releases( + query=self.query, + timeout=self.dc['armada.get_releases_timeout'] + ) + return get_releases_resp['releases'] + except errors.ClientError as client_error: + # Dump logs from Armada pods + self.get_k8s_logs() + raise AirflowException(client_error) + @get_pod_port_ip('tiller', namespace='kube-system') def get_tiller_info(self, pods_ip_port={}): diff --git a/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_get_releases.py b/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_get_releases.py index 76d6e15a..e51ca845 100644 --- a/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_get_releases.py +++ b/src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_get_releases.py @@ -21,7 +21,6 @@ try: except ImportError: from shipyard_airflow.plugins.armada_base_operator import \ ArmadaBaseOperator -from armada.exceptions import api_exceptions as errors LOG = logging.getLogger(__name__) @@ -36,23 +35,9 @@ class ArmadaGetReleasesOperator(ArmadaBaseOperator): """ def do_execute(self): - - # Retrieve Tiller Information - self.get_tiller_info(pods_ip_port={}) - - # Retrieve read timeout - timeout = self.dc['armada.get_releases_timeout'] - # Retrieve Armada Releases after deployment LOG.info("Retrieving Helm charts releases after deployment..") - - try: - armada_get_releases = self.armada_client.get_releases( - self.query, - timeout=timeout) - - except errors.ClientError as client_error: - raise AirflowException(client_error) + armada_get_releases = self.get_releases() if armada_get_releases: LOG.info("Successfully retrieved Helm charts releases")