diff --git a/microservices/gatewayApi/app.py b/microservices/gatewayApi/app.py index 0789987..1726229 100644 --- a/microservices/gatewayApi/app.py +++ b/microservices/gatewayApi/app.py @@ -113,6 +113,12 @@ def expired_token(error): content = jsonify({"error":"Token Expired"}) return make_response(content, HTTPStatus.UNAUTHORIZED) + @app.errorhandler(Exception) + def other_exception(error): + log.error(error) + content = jsonify({"error":"Unexpected Error"}) + return make_response(content, HTTPStatus.BAD_REQUEST) + @app.route('/', methods=['GET'], strict_slashes=False) def index(): """ diff --git a/microservices/gatewayApi/v1/routes/namespaces.py b/microservices/gatewayApi/v1/routes/namespaces.py index e2faeb5..e0906b4 100644 --- a/microservices/gatewayApi/v1/routes/namespaces.py +++ b/microservices/gatewayApi/v1/routes/namespaces.py @@ -71,10 +71,13 @@ def update_namespace(namespace: str) -> object: log.error("Namespace validation failed %s", namespace) abort(make_response(jsonify(error="Namespace name validation failed. Reference regular expression '%s'." % namespace_validation_rule), 400)) + log.info("Updating namespace %s" % namespace) + try: svc = NamespaceService() ns_group = svc.get_namespace (namespace) + log.info("-> Found %s" % ns_group) svc.update_ns_attributes (ns_group, params) diff --git a/microservices/gatewayJobScheduler/main.py b/microservices/gatewayJobScheduler/main.py index e0b4f92..9809e3c 100644 --- a/microservices/gatewayJobScheduler/main.py +++ b/microservices/gatewayJobScheduler/main.py @@ -40,17 +40,26 @@ def get_namespace_attributes(self, namespace): def get_routes(): try: - p1 = Popen(shlex.split("curl %s/routes" % os.getenv('KONG_ADMIN_API_URL')), stdout=PIPE) - run = Popen(shlex.split( - "jq '.data'"), stdin=p1.stdout, stdout=PIPE, stderr=PIPE) - out, err = run.communicate() + endpoint = "/routes" + routes_list = [] + while True: + p1 = Popen(shlex.split("curl %s%s" % (os.getenv('KONG_ADMIN_API_URL'), endpoint)), stdout=PIPE) + run = Popen(shlex.split( + "jq ."), stdin=p1.stdout, stdout=PIPE, stderr=PIPE) + out, err = run.communicate() + + if run.returncode != 0: + logger.error("Failed to get existing routes - %s - %s", out, err) + clear('sync-routes') + exit(1) + + result = json.loads(out) + routes_list = routes_list + result['data'] + + if result['next'] == None: + return routes_list + endpoint = result['next'] - if run.returncode != 0: - logger.error("Failed to get existing routes - %s - %s", out, err) - clear('sync-routes') - exit(1) - - return json.loads(out) except: traceback.print_exc() logger.error('Failed to get existing routes - %s' % (exc_info()[0])) @@ -66,7 +75,6 @@ def sync_routes(): 'content-type': 'application/json' } data = transform_data_by_ns(get_routes()) - for ns in data: url = os.getenv('KUBE_API_URL') + '/namespaces/%s/routes/sync' % ns response = requests.post(url, headers=headers, json=data[ns], auth=(