From 2deda8724fd8c3346af18b3bb210b420ed712990 Mon Sep 17 00:00:00 2001 From: Hamzah Qudsi Date: Thu, 8 Jun 2023 16:45:34 -0400 Subject: [PATCH] go-filter: replace GO_FILTER_OBJECT_FILE env var with AMBASSADOR_DISABLE_GO_FILTER AMBASSADOR_DISABLE_GO_FILTER is an env var flag to disable injecting the go filter when running in EdgeStack mode. When running pure Emissary, the go-filter is not injected anyway. the library path is now kept hardcoded since there's not reason to really expose it to be configurable and was causing some confusion on naming. Due to the presence of this flag now, we add it to the KAT/integration test manifests so that the go-filter isn't injected during those tests. This is fine for now because those tests are not testing any functionality from the go-filter. Future work will include overhauling the E2E test suite. Signed-off-by: Hamzah Qudsi --- k8s-config/kat-ambassador/values.yaml | 1 + python/ambassador/ir/irgofilter.py | 15 +++++++++++---- .../tests/integration/manifests/ambassador.yaml | 2 ++ python/tests/unit/conftest.py | 8 ++++++++ python/tests/unit/test_gofilter.py | 11 ++++++++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/k8s-config/kat-ambassador/values.yaml b/k8s-config/kat-ambassador/values.yaml index 6409e353b8..11ea1b848e 100644 --- a/k8s-config/kat-ambassador/values.yaml +++ b/k8s-config/kat-ambassador/values.yaml @@ -18,6 +18,7 @@ env: AMBASSADOR_ID: «self.path.k8s» AMBASSADOR_SNAPSHOT_COUNT: "0" AMBASSADOR_CONFIG_BASE_DIR: "/tmp/ambassador" + AMBASSADOR_DISABLE_GO_FILTER: true envRaw: "- ←«envs»" security: containerSecurityContext: diff --git a/python/ambassador/ir/irgofilter.py b/python/ambassador/ir/irgofilter.py index b4aab8c659..cbc08dbd83 100644 --- a/python/ambassador/ir/irgofilter.py +++ b/python/ambassador/ir/irgofilter.py @@ -22,7 +22,8 @@ if TYPE_CHECKING: from .ir import IR # pragma: no cover -GO_FILTER_OBJECT_FILE: str = os.getenv("GO_FILTER_OBJECT_FILE", "/ambassador/go_filter.so") +GO_FILTER_LIBRARY_PATH = "/ambassador/filter.so" +AMBASSADOR_DISABLE_GO_FILTER = os.getenv("AMBASSADOR_DISABLE_GO_FILTER", False) def go_library_exists(go_library_path: str) -> bool: @@ -61,10 +62,16 @@ def __init__( # We want to enable this filter only in Edge Stack def setup(self, ir: "IR", _: Config) -> bool: if ir.edge_stack_allowed: - if not go_library_exists(GO_FILTER_OBJECT_FILE): - self.logger.error("%s not found, disabling Go filter...", GO_FILTER_OBJECT_FILE) + if AMBASSADOR_DISABLE_GO_FILTER: + self.logger.info( + "AMBASSADOR_DISABLE_GO_FILTER=%s, disabling Go filter...", + AMBASSADOR_DISABLE_GO_FILTER, + ) return False - self.config = GOFilterConfig(library_path=GO_FILTER_OBJECT_FILE) + if not go_library_exists(GO_FILTER_LIBRARY_PATH): + self.logger.error("%s not found, disabling Go filter...", GO_FILTER_LIBRARY_PATH) + return False + self.config = GOFilterConfig(library_path=GO_FILTER_LIBRARY_PATH) return True return False diff --git a/python/tests/integration/manifests/ambassador.yaml b/python/tests/integration/manifests/ambassador.yaml index ec2b32924c..584f17775b 100644 --- a/python/tests/integration/manifests/ambassador.yaml +++ b/python/tests/integration/manifests/ambassador.yaml @@ -105,6 +105,8 @@ spec: value: {self.path.k8s}-agent-cloud-token - name: AMBASSADOR_CONFIG_BASE_DIR value: /tmp/ambassador + - name: AMBASSADOR_DISABLE_GO_FILTER + value: "true" - name: AMBASSADOR_ID value: {self.path.k8s} - name: AMBASSADOR_SNAPSHOT_COUNT diff --git a/python/tests/unit/conftest.py b/python/tests/unit/conftest.py index 2c5901bc30..4ff0d5acc2 100644 --- a/python/tests/unit/conftest.py +++ b/python/tests/unit/conftest.py @@ -1,3 +1,4 @@ +import os from unittest.mock import patch import pytest @@ -8,3 +9,10 @@ def go_library(): with patch("ambassador.ir.irgofilter.go_library_exists") as go_library_exists: go_library_exists.return_value = True yield go_library_exists + + +@pytest.fixture() +def disable_go_filter(): + with patch("ambassador.ir.irgofilter.AMBASSADOR_DISABLE_GO_FILTER") as disable_go_filter: + disable_go_filter.return_value = True + yield disable_go_filter diff --git a/python/tests/unit/test_gofilter.py b/python/tests/unit/test_gofilter.py index a8f9294ee0..ebb1417a91 100644 --- a/python/tests/unit/test_gofilter.py +++ b/python/tests/unit/test_gofilter.py @@ -118,7 +118,16 @@ def test_gofilter_missing_object_file(go_library, caplog): assert len(filters) == 0 - assert "/ambassador/go_filter.so not found" in caplog.text + assert "/ambassador/filter.so not found" in caplog.text + + +@pytest.mark.compilertest +@edgestack() +def test_gofilter_disable(disable_go_filter, caplog): + econf = get_envoy_config(MAPPING) + filters = _get_go_filters(econf.as_dict()) + + assert len(filters) == 0 @pytest.mark.compilertest