diff --git a/microservices/gatewayApi/Dockerfile b/microservices/gatewayApi/Dockerfile index 9a862b99..70a3df6a 100644 --- a/microservices/gatewayApi/Dockerfile +++ b/microservices/gatewayApi/Dockerfile @@ -20,15 +20,16 @@ RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl - #COPY --from=build /deck/deck /usr/local/bin -# gwa api v1/v2 +# gwa api (kong 2) RUN curl -sL https://github.com/kong/deck/releases/download/v1.5.0/deck_1.5.0_linux_amd64.tar.gz -o deck.tar.gz && \ tar -xf deck.tar.gz -C /tmp && \ - cp /tmp/deck /usr/local/bin/ + cp /tmp/deck /usr/local/bin/deck_kong2_150 -# gwa api v3 -RUN curl -sL https://github.com/Kong/deck/releases/download/v1.27.1/deck_1.27.1_linux_amd64.tar.gz -o deck.tar.gz && \ +# gwa api (kong 3) +RUN curl -sL https://github.com/Kong/deck/releases/download/v1.45.0/deck_1.45.0_linux_amd64.tar.gz -o deck.tar.gz && \ tar -xf deck.tar.gz -C /tmp && \ - cp /tmp/deck /usr/local/bin/deck127 + cp /tmp/deck /usr/local/bin/deck && \ + cp /tmp/deck /usr/local/bin/deck_kong3_1450 RUN python -m pip install --upgrade pip # FIX: No module named 'urllib3.packages.six' @@ -50,5 +51,6 @@ RUN chmod +x entrypoint.sh EXPOSE 2000 ENV DECK_ANALYTICS=off +ENV DECK_CLI=deck ENTRYPOINT ["./entrypoint.sh"] diff --git a/microservices/gatewayApi/config/test.json b/microservices/gatewayApi/config/test.json index 9dd08b18..d1ac3791 100644 --- a/microservices/gatewayApi/config/test.json +++ b/microservices/gatewayApi/config/test.json @@ -30,5 +30,6 @@ "kubeApiPass": "password", "kubeApiUser": "username" }, - "compatibilityApiUrl": "http://compatibility-api" + "compatibilityApiUrl": "http://compatibility-api", + "deckCLI": "deck" } \ No newline at end of file diff --git a/microservices/gatewayApi/entrypoint.sh b/microservices/gatewayApi/entrypoint.sh index 3499110a..e9a9611f 100755 --- a/microservices/gatewayApi/entrypoint.sh +++ b/microservices/gatewayApi/entrypoint.sh @@ -61,7 +61,8 @@ cat > "${CONFIG_PATH:-./config/default.json}" < object: # Call the 'deck' command cmd = "sync" + deck_cli = app.config['deckCLI'] + + + log.info("[%s] (%s) %s action using %s" % (namespace, deck_cli, cmd, selectTag)) + args = deck_cmd_sync_diff(deck_cli, cmd, selectTag, tempFolder) - log.info("[%s] %s action using %s" % (namespace, cmd, selectTag)) - args = [ - "deck", cmd, "--config", "/tmp/deck.yaml", "--skip-consumers", "--select-tag", selectTag, "--state", tempFolder - ] log.debug("[%s] Running %s" % (namespace, args)) deck_run = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_run.communicate() @@ -235,6 +237,9 @@ def write_config(namespace: str) -> object: # Enrichments ####################### + # Add format version if its missing - needed in Kong v3+ + add_version_if_missing(gw_config) + # Transformation route hosts if in non-prod environment (HOST_TRANSFORM_ENABLED) host_transformation(namespace, gw_config) @@ -246,19 +251,21 @@ def write_config(namespace: str) -> object: # Enrich the rate-limiting plugin with the appropriate Redis details plugins_transformations(namespace, gw_config) - # Check Kong 3 compatibility - is_compatible, compatibility_message, failed_routes, kong2_config = check_kong3_compatibility(namespace, gw_config) - if not is_compatible: - warning_message = compatibility_message + # Disabled: + # + # # Check Kong 3 compatibility + # is_compatible, compatibility_message, failed_routes, kong2_config = check_kong3_compatibility(namespace, gw_config) + # if not is_compatible: + # warning_message = compatibility_message - # Track incompatible routes - if not is_compatible: - has_incompatible_routes = True - all_failed_routes.extend(failed_routes) + # # Track incompatible routes + # if not is_compatible: + # has_incompatible_routes = True + # all_failed_routes.extend(failed_routes) - # Use kong2_config (which has compatibility tags) regardless of compatibility status - if kong2_config: - gw_config = kong2_config + # # Use kong2_config (which has compatibility tags) regardless of compatibility status + # if kong2_config: + # gw_config = kong2_config with open("%s/%s" % (tempFolder, 'config-%02d.yaml' % index), 'w') as file: yaml.dump(gw_config, file) @@ -320,12 +327,12 @@ def write_config(namespace: str) -> object: selectTag = ns_qualifier # Call the 'deck' command + deck_cli = app.config['deckCLI'] + + log.info("[%s] (%s) %s action using %s" % (namespace, deck_cli, cmd, selectTag)) - log.info("[%s] %s action using %s" % (namespace, cmd, selectTag)) + args = deck_cmd_validate(deck_cli, tempFolder) - args = [ - "deck", "validate", "--config", "/tmp/deck.yaml", "--state", tempFolder - ] log.debug("[%s] Running %s" % (namespace, args)) deck_validate = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_validate.communicate() @@ -335,9 +342,8 @@ def write_config(namespace: str) -> object: abort_early(event_id, 'validate', namespace, jsonify( error="Validation Failed.", results=mask(out.decode('utf-8')))) - args = [ - "deck", cmd, "--config", "/tmp/deck.yaml", "--skip-consumers", "--select-tag", selectTag, "--state", tempFolder - ] + args = deck_cmd_sync_diff(deck_cli, cmd, selectTag, tempFolder) + log.debug("[%s] Running %s" % (namespace, args)) deck_run = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_run.communicate() diff --git a/microservices/gatewayApi/v2/routes/gateway.py b/microservices/gatewayApi/v2/routes/gateway.py index 4308fd3e..05073b6a 100644 --- a/microservices/gatewayApi/v2/routes/gateway.py +++ b/microservices/gatewayApi/v2/routes/gateway.py @@ -20,8 +20,9 @@ from clients.kong import get_routes, register_kong_certs, get_public_certs_by_ns from clients.ocp_gateway_secret import prep_submitted_config from utils.validators import host_valid, validate_upstream -from utils.transforms import plugins_transformations +from utils.transforms import plugins_transformations, add_version_if_missing from utils.masking import mask +from utils.deck import deck_cmd_sync_diff, deck_cmd_validate from clients.compatibility import check_kong3_compatibility gw = Blueprint('gwa_v2', 'gateway') @@ -54,7 +55,7 @@ def delete_config(namespace: str, qualifier="") -> object: os.makedirs(tempFolder, exist_ok=False) with open("%s/%s" % (tempFolder, 'empty.yaml'), 'w') as file: - file.write("") + file.write("_format_version: '3.0'") selectTag = "ns.%s" % namespace log.debug("ST = %s" % selectTag) @@ -64,11 +65,11 @@ def delete_config(namespace: str, qualifier="") -> object: # Call the 'deck' command cmd = "sync" + deck_cli = app.config['deckCLI'] + + log.info("[%s] (%s) %s action using %s" % (namespace, deck_cli, cmd, selectTag)) + args = deck_cmd_sync_diff(deck_cli, cmd, selectTag, tempFolder) - log.info("[%s] %s action using %s" % (namespace, cmd, selectTag)) - args = [ - "deck", cmd, "--config", "/tmp/deck.yaml", "--skip-consumers", "--select-tag", selectTag, "--state", tempFolder - ] log.debug("[%s] Running %s" % (namespace, args)) deck_run = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_run.communicate() @@ -233,6 +234,9 @@ def write_config(namespace: str) -> object: # Enrichments ####################### + # Add format version if its missing - needed in Kong v3+ + add_version_if_missing(gw_config) + # Transformation route hosts if in non-prod environment (HOST_TRANSFORM_ENABLED) host_transformation(namespace, dp, gw_config) @@ -243,19 +247,21 @@ def write_config(namespace: str) -> object: # Enrich the rate-limiting plugin with the appropriate Redis details plugins_transformations(namespace, gw_config) + # Disabled: + # # Check Kong 3 compatibility - is_compatible, compatibility_message, failed_routes, kong2_config = check_kong3_compatibility(namespace, gw_config) - if not is_compatible: - warning_message = compatibility_message + #is_compatible, compatibility_message, failed_routes, kong2_config = check_kong3_compatibility(namespace, gw_config) + #if not is_compatible: + # warning_message = compatibility_message # Track incompatible routes - if not is_compatible: - has_incompatible_routes = True - all_failed_routes.extend(failed_routes) + #if not is_compatible: + # has_incompatible_routes = True + # all_failed_routes.extend(failed_routes) # Use kong2_config (which has compatibility tags) regardless of compatibility status - if kong2_config: - gw_config = kong2_config + #if kong2_config: + # gw_config = kong2_config # After enrichments, dump config to file with open("%s/%s" % (tempFolder, 'config-%02d.yaml' % index), 'w') as file: @@ -318,12 +324,12 @@ def write_config(namespace: str) -> object: selectTag = ns_qualifier # Call the 'deck' command + deck_cli = app.config['deckCLI'] - log.info("[%s] %s action using %s" % (namespace, cmd, selectTag)) + log.info("[%s] (%s) %s action using %s" % (namespace, deck_cli, cmd, selectTag)) + + args = deck_cmd_validate(deck_cli, tempFolder) - args = [ - "deck", "validate", "--config", "/tmp/deck.yaml", "--state", tempFolder - ] log.debug("[%s] Running %s" % (namespace, args)) deck_validate = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_validate.communicate() @@ -333,9 +339,8 @@ def write_config(namespace: str) -> object: abort_early(event_id, 'validate', namespace, jsonify( error="Validation Failed.", results=mask(out.decode('utf-8')))) - args = [ - "deck", cmd, "--config", "/tmp/deck.yaml", "--skip-consumers", "--select-tag", selectTag, "--state", tempFolder - ] + args = deck_cmd_sync_diff(deck_cli, cmd, selectTag, tempFolder) + log.debug("[%s] Running %s" % (namespace, args)) deck_run = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_run.communicate() diff --git a/microservices/gatewayApi/v2/routes/namespaces.py b/microservices/gatewayApi/v2/routes/namespaces.py index bf55752f..31684690 100644 --- a/microservices/gatewayApi/v2/routes/namespaces.py +++ b/microservices/gatewayApi/v2/routes/namespaces.py @@ -39,6 +39,7 @@ from v1.services.namespaces import NamespaceService, get_base_group_path from utils.cleanup import cleanup from utils.get_data_plane import get_data_plane +from utils.deck import deck_cmd_sync_diff ns = Blueprint('namespaces_v2', 'namespaces') local_environment = os.environ.get("LOCAL_ENVIRONMENT", default=False) @@ -97,18 +98,19 @@ def delete_namespace(namespace: str) -> object: os.makedirs(tempFolder, exist_ok=False) with open("%s/%s" % (tempFolder, 'empty.yaml'), 'w') as file: - file.write("") + file.write("_format_version: '3.0'") selectTag = "ns.%s" % namespace log.debug("ST = %s" % selectTag) # Call the 'deck' command cmd = "sync" + deck_cli = app.config['deckCLI'] + + log.info("[%s] (%s) %s action using %s" % (namespace, deck_cli, cmd, selectTag)) + + args = deck_cmd_sync_diff(deck_cli, cmd, selectTag, tempFolder) - log.info("[%s] %s action using %s" % (namespace, cmd, selectTag)) - args = [ - "deck", cmd, "--config", "/tmp/deck.yaml", "--skip-consumers", "--select-tag", selectTag, "--state", tempFolder - ] log.debug("[%s] Running %s" % (namespace, args)) deck_run = Popen(args, stdout=PIPE, stderr=STDOUT) out, err = deck_run.communicate()