Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a thread to recreate the IPv6 firewall rule every 30 seconds to counteract the enforcer deleting it. #120

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tests/dualstack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
# limitations under the License.
import datetime as dt
import logging
import threading
import time
from typing import Final

from absl import flags
from absl.testing import absltest
from typing_extensions import TypeAlias, override
from typing_extensions import override

from framework import xds_k8s_flags
from framework import xds_k8s_testcase
Expand All @@ -39,6 +41,8 @@
class DualStackTest(xds_k8s_testcase.RegularXdsKubernetesTestCase):
v4_server_runner: _KubernetesServerRunner = None
v6_server_runner: _KubernetesServerRunner = None
fr_recreater: threading.Thread = None
firewall_rule_creation_should_stop: bool = False

@staticmethod
@override
Expand Down Expand Up @@ -95,6 +99,8 @@ def setUp(self):
)

def cleanup(self):
self.firewall_rule_creation_should_stop = True

self.td.cleanup(force=self.force_cleanup)
self.client_runner.cleanup(
force=self.force_cleanup, force_namespace=self.force_cleanup
Expand Down Expand Up @@ -128,6 +134,22 @@ def test_dualstack(self) -> None:
self.server_xds_host, self.server_xds_port
)

with self.subTest("_start_firewall_rule_creation_thread"):

def recreate_firewall_rule():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this functionality is generally useful. Can we just incorporate it into the --ensure_firewall flag?

time.sleep(30)
while self.firewall_rule_creation_should_stop is False:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use threading.Event for inter-thread synchronization. The current approach may suffer from tearing.

self.td.create_firewall_rules(
allowed_ports=self.firewall_allowed_ports,
source_range=self.firewall_source_range,
source_range_ipv6=self.firewall_source_range_ipv6,
)
time.sleep(30)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this could be done with a single call to time.sleep

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the delay be pulled to a module-level constant? Also, 30 seems a bit slow to me. Maybe 10?


self.fr_recreater = threading.Thread(
target=recreate_firewall_rule, args=(self,), daemon=True
)

test_servers: list[_XdsTestServer] = []
with self.subTest("03_start_test_server-dualstack"):
test_servers.append(
Expand Down Expand Up @@ -155,6 +177,7 @@ def test_dualstack(self) -> None:

logger.info("Test servers: %s", test_servers)

# Start recreating the firewall rule every 15 seconds
with self.subTest("04_add_server_backends_to_backend_services"):
(
neg_name,
Expand Down
Loading