Skip to content

Commit

Permalink
Merge pull request #5097 from emissary-ingress/hqudsi/go-filter-disable
Browse files Browse the repository at this point in the history
go-filter: replace GO_FILTER_OBJECT_FILE env var with disable flag
  • Loading branch information
Hamzah Qudsi committed Jun 9, 2023
2 parents 778688a + 2deda87 commit faf3052
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions k8s-config/kat-ambassador/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions python/ambassador/ir/irgofilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions python/tests/integration/manifests/ambassador.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions python/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import patch

import pytest
Expand All @@ -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
11 changes: 10 additions & 1 deletion python/tests/unit/test_gofilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit faf3052

Please sign in to comment.