Browse Source

Remove Shipyard queries for Tiller information

Currently Shipyard is attempting to retrieve Tiller information to pass
to Armada. Once the dependent change is merged, Tiller will be moved
into the same pod as Armada, and this information will be retrieved
from the Armada configuration file. Therefore, Shipyard should no
longer be retrieving this information for Armada.

Co-Authored-By: Michael Beaver <michaelbeaver64@gmail.com>
Depends-On: https://review.openstack.org/#/c/632788/
Change-Id: I689e396ef9f184525f09f819f13c1490344481f2
Nishant kumar 2 months ago
parent
commit
afd2788729

+ 1
- 1
src/bin/shipyard_airflow/requirements.txt View File

@@ -41,4 +41,4 @@ Werkzeug==0.14.1
41 41
 # Dependencies for other UCP components
42 42
 git+https://git.openstack.org/openstack/airship-deckhand@0aae9dc1776bd97ab8f4152a51baedb24eb61396#egg=deckhand
43 43
 git+https://git.openstack.org/openstack/airship-drydock.git@d93d6d5a0a370ced536180612d1ade708e29cd47#egg=drydock_provisioner&subdirectory=python
44
-git+https://git.openstack.org/openstack/airship-armada.git@269083c0c063efa50bd5e88374dbd89abb3921c3#egg=armada
44
+git+https://git.openstack.org/openstack/airship-armada.git@37249f3492b137ff6beb3d3c7e5e9dc1732ef8fb#egg=armada

+ 0
- 15
src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_base_operator.py View File

@@ -23,13 +23,11 @@ import armada.common.session as session
23 23
 from armada.exceptions import api_exceptions as errors
24 24
 
25 25
 try:
26
-    from get_k8s_pod_port_ip import get_pod_port_ip
27 26
     import service_endpoint
28 27
     from service_token import shipyard_service_token
29 28
     from ucp_base_operator import UcpBaseOperator
30 29
     from xcom_pusher import XcomPusher
31 30
 except ImportError:
32
-    from shipyard_airflow.plugins.get_k8s_pod_port_ip import get_pod_port_ip
33 31
     from shipyard_airflow.plugins import service_endpoint
34 32
     from shipyard_airflow.plugins.service_token import shipyard_service_token
35 33
     from shipyard_airflow.plugins.ucp_base_operator import UcpBaseOperator
@@ -90,11 +88,6 @@ class ArmadaBaseOperator(UcpBaseOperator):
90 88
             self.svc_token
91 89
         )
92 90
 
93
-        # Retrieve Tiller Information
94
-        # TODO(@drewwalters96): This should be explicit. Refactor in
95
-        # conjunction with `get_pod_port_ip` decorator.
96
-        self.get_tiller_info(pods_ip_port={})
97
-
98 91
     @staticmethod
99 92
     def _init_armada_client(armada_svc_endpoint, svc_token):
100 93
 
@@ -144,14 +137,6 @@ class ArmadaBaseOperator(UcpBaseOperator):
144 137
             self.get_k8s_logs()
145 138
             raise AirflowException(client_error)
146 139
 
147
-    @get_pod_port_ip('tiller', namespace='kube-system')
148
-    def get_tiller_info(self, pods_ip_port={}):
149
-
150
-        # Assign value to the 'query' dictionary so that we can pass
151
-        # it via the Armada Client
152
-        self.query['tiller_host'] = pods_ip_port['tiller']['ip']
153
-        self.query['tiller_port'] = pods_ip_port['tiller']['port']
154
-
155 140
 
156 141
 class ArmadaBaseOperatorPlugin(AirflowPlugin):
157 142
 

+ 0
- 3
src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_get_status.py View File

@@ -38,9 +38,6 @@ class ArmadaGetStatusOperator(ArmadaBaseOperator):
38 38
 
39 39
     def do_execute(self):
40 40
 
41
-        # Retrieve Tiller Information
42
-        self.get_tiller_info(pods_ip_port={})
43
-
44 41
         # Retrieve read timeout
45 42
         timeout = self.dc['armada.get_status_timeout']
46 43
 

+ 0
- 3
src/bin/shipyard_airflow/shipyard_airflow/plugins/armada_post_apply.py View File

@@ -47,9 +47,6 @@ class ArmadaPostApplyOperator(ArmadaBaseOperator):
47 47
         self.dc = self.xcom_puller.get_deployment_configuration()
48 48
         self.target_manifest = self.dc['armada.manifest']
49 49
 
50
-        # Retrieve Tiller Information
51
-        self.get_tiller_info(pods_ip_port={})
52
-
53 50
         # Update query dict with information of target_manifest
54 51
         self.query['target_manifest'] = self.target_manifest
55 52
 

+ 0
- 121
src/bin/shipyard_airflow/shipyard_airflow/plugins/get_k8s_pod_port_ip.py View File

@@ -1,121 +0,0 @@
1
-# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
2
-#
3
-# Licensed under the Apache License, Version 2.0 (the "License");
4
-# you may not use this file except in compliance with the License.
5
-# You may obtain a copy of the License at
6
-#
7
-#     http://www.apache.org/licenses/LICENSE-2.0
8
-#
9
-# Unless required by applicable law or agreed to in writing, software
10
-# distributed under the License is distributed on an "AS IS" BASIS,
11
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-# See the License for the specific language governing permissions and
13
-# limitations under the License.
14
-
15
-import logging
16
-from functools import wraps
17
-
18
-from airflow.exceptions import AirflowException
19
-from kubernetes import client, config
20
-
21
-
22
-def get_pod_port_ip(*pods, namespace):
23
-    def get_k8s_pod_port_ip(func):
24
-        @wraps(func)
25
-        def k8s_pod_port_ip_get(self, pods_ip_port):
26
-            """This function retrieves Kubernetes Pod Port and IP
27
-               information. It can be used to retrieve information of
28
-               single pod deployment and/or statefulsets. For instance,
29
-               it can be used to retrieve the tiller pod IP and port
30
-               information for usage in the Armada Operator.
31
-
32
-            :param pods_ip_port: IP and port information of the pods
33
-
34
-            Example::
35
-
36
-                from get_k8s_pod_port_ip import get_pod_port_ip
37
-
38
-                @get_pod_port_ip('tiller', namespace='kube-system')
39
-                def get_pod_info(self, pods_ip_port={}):
40
-
41
-                    tiller_ip = pods_ip_port['tiller']['ip']
42
-                    tiller_port = pods_ip_port['tiller']['port']
43
-
44
-            """
45
-            # Initialize variable
46
-            k8s_pods = {}
47
-
48
-            # The function allows us to query information on multiple
49
-            # pods
50
-            for pod_name in pods:
51
-                # Initialize variables
52
-                pod_attr = {}
53
-                pod_attr[pod_name] = {}
54
-
55
-                # Initialize/Reset counter
56
-                count = 0
57
-
58
-                # Make use of kubernetes client to retrieve pod IP
59
-                # and port information
60
-                # Note that we should use 'in_cluster_config'
61
-                # Note that we will only search for pods in the namespace
62
-                # that was specified in the request
63
-                config.load_incluster_config()
64
-                v1 = client.CoreV1Api()
65
-                ret = v1.list_namespaced_pod(namespace=namespace,
66
-                                             watch=False)
67
-
68
-                # Loop through items to extract port and IP information
69
-                # of the pod
70
-                for i in ret.items:
71
-                    if pod_name in i.metadata.name:
72
-                        # Get pod IP
73
-                        logging.info("Retrieving %s IP", pod_name)
74
-                        pod_attr[pod_name]['ip'] = i.status.pod_ip
75
-                        logging.info("%s IP is %s", pod_name,
76
-                                     pod_attr[pod_name]['ip'])
77
-
78
-                        # Get pod port
79
-                        logging.info("Retrieving %s Port", pod_name)
80
-
81
-                        # It is possible for a pod to have an IP with no
82
-                        # port. For instance maas-rack takes on genesis
83
-                        # node IP and has no port associated with it. We
84
-                        # will assign the value 'None' to the port value
85
-                        # in such cases.
86
-                        try:
87
-                            specs_dict = i.spec.containers[0].__dict__
88
-                            ports_dict = specs_dict['_ports'][0].__dict__
89
-                            pod_attr[pod_name]['port'] = (
90
-                                ports_dict['_container_port'])
91
-                            logging.info("%s Port is %s", pod_name,
92
-                                         pod_attr[pod_name]['port'])
93
-                        except:
94
-                            pod_attr[pod_name]['port'] = 'None'
95
-                            logging.warning("%s Port is None", pod_name)
96
-
97
-                        # Update k8s_pods with new entry
98
-                        k8s_pods.update(pod_attr)
99
-
100
-                        # It is possible for different pods to have the same
101
-                        # partial names. This means that we can end up with
102
-                        # inconsistent results depending on how the pods were
103
-                        # ordered in the results for 'list_namespaced_pod'.
104
-                        # Hence an exception should be raised when the function
105
-                        # returns results for 2 or more pods.
106
-                        if count > 0:
107
-                            raise AirflowException(
108
-                                "Pod search string is not unique!")
109
-
110
-                        # Step counter
111
-                        count += 1
112
-
113
-                # Raise Execptions if the pod does not exits in the
114
-                # Kubernetes cluster
115
-                if not pod_attr[pod_name]:
116
-                    raise AirflowException("Unable to locate", pod_name)
117
-
118
-            return func(self, pods_ip_port=k8s_pods)
119
-
120
-        return k8s_pod_port_ip_get
121
-    return get_k8s_pod_port_ip

+ 3
- 6
src/bin/shipyard_airflow/tests/unit/plugins/test_armada_test_releases_operator.py View File

@@ -45,8 +45,7 @@ class TestArmadaTestReleasesOperator:
45 45
     @mock.patch.object(ArmadaBaseOperator, 'armada_client', create=True)
46 46
     @mock.patch.object(ArmadaBaseOperator, 'get_releases',
47 47
         return_value=RELEASES)
48
-    @mock.patch.object(ArmadaBaseOperator, 'get_tiller_info')
49
-    def test_do_execute(self, mock_tiller_info, mock_releases, mock_client,
48
+    def test_do_execute(self, mock_releases, mock_client,
50 49
                         mock_logs):
51 50
         op = ArmadaTestReleasesOperator(main_dag_name='main',
52 51
                                         shipyard_conf=CONF_FILE,
@@ -69,8 +68,7 @@ class TestArmadaTestReleasesOperator:
69 68
 
70 69
     @mock.patch('shipyard_airflow.plugins.armada_test_releases.LOG.info')
71 70
     @mock.patch.object(ArmadaBaseOperator, 'armada_client', create=True)
72
-    @mock.patch.object(ArmadaBaseOperator, 'get_tiller_info')
73
-    def test_do_execute_with_params(self, mock_tiller, mock_client, mock_logs):
71
+    def test_do_execute_with_params(self, mock_client, mock_logs):
74 72
         op = ArmadaTestReleasesOperator(main_dag_name='main',
75 73
                                         shipyard_conf=CONF_FILE,
76 74
                                         task_id='t1')
@@ -91,9 +89,8 @@ class TestArmadaTestReleasesOperator:
91 89
     @mock.patch.object(ArmadaBaseOperator, 'armada_client', create=True)
92 90
     @mock.patch.object(ArmadaBaseOperator, 'get_releases',
93 91
         return_value=RELEASES)
94
-    @mock.patch.object(ArmadaBaseOperator, 'get_tiller_info')
95 92
     @mock.patch.object(UcpBaseOperator, 'get_k8s_logs')
96
-    def test_do_execute_fail(self, mock_k8s_logs, mock_tiller_info,
93
+    def test_do_execute_fail(self, mock_k8s_logs,
97 94
                              mock_releases, mock_client):
98 95
         mock_client.get_test_release.return_value = None
99 96
 

Loading…
Cancel
Save