-
Notifications
You must be signed in to change notification settings - Fork 2k
Update secrets when mgmt configmap changes #6947
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
Merged
+166
−13
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c569289
when mgmt configmap changes update secrets
pdabelf5 3ba0ce3
add test for license key secret configmap change
pdabelf5 d735830
remove comment
pdabelf5 8afa5e7
Merge branch 'main' into mgmt-config-map-pytest
vepatel 7c2337c
return error and log event if TLS special secret is not valid
pdabelf5 189782b
Merge branch 'mgmt-config-map-pytest' of github.com:nginxinc/kubernet…
pdabelf5 a65d402
redefine how reloadNginx variable is set
pdabelf5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: nginx-config-mgmt | ||
| namespace: nginx-ingress | ||
| data: | ||
| license-token-secret-name: "license-token-changed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import pytest | ||
| from settings import TEST_DATA | ||
| from suite.utils.resources_utils import ( | ||
| create_license, | ||
| ensure_connection_to_public_endpoint, | ||
| get_events_for_object, | ||
| get_first_pod_name, | ||
| get_reload_count, | ||
| is_secret_present, | ||
| replace_configmap_from_yaml, | ||
| wait_before_test, | ||
| ) | ||
|
|
||
|
|
||
| def assert_event(event_list, event_type, reason, message_substring): | ||
| """ | ||
| Assert that an event with specific type, reason, and message substring exists. | ||
|
|
||
| :param event_list: List of events | ||
| :param event_type: 'Normal' or 'Warning' | ||
| :param reason: Event reason | ||
| :param message_substring: Substring expected in the event message | ||
| """ | ||
| for event in event_list: | ||
| if event.type == event_type and event.reason == reason and message_substring in event.message: | ||
| return | ||
| assert ( | ||
| False | ||
| ), f"Expected event with type '{event_type}', reason '{reason}', and message containing '{message_substring}' not found." | ||
|
|
||
|
|
||
| @pytest.mark.skip_for_nginx_oss | ||
| @pytest.mark.ingresses | ||
| @pytest.mark.smoke | ||
| class TestMGMTConfigMap: | ||
| @pytest.mark.parametrize( | ||
| "ingress_controller", | ||
| [ | ||
| pytest.param( | ||
| {"extra_args": ["-enable-prometheus-metrics"]}, | ||
| ) | ||
| ], | ||
| indirect=["ingress_controller"], | ||
| ) | ||
| def test_mgmt_configmap_events( | ||
| self, | ||
| cli_arguments, | ||
| kube_apis, | ||
| ingress_controller_prerequisites, | ||
| ingress_controller, | ||
| ingress_controller_endpoint, | ||
| ): | ||
| ensure_connection_to_public_endpoint( | ||
| ingress_controller_endpoint.public_ip, | ||
| ingress_controller_endpoint.port, | ||
| ingress_controller_endpoint.port_ssl, | ||
| ) | ||
| ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) | ||
| metrics_url = ( | ||
| f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.metrics_port}/metrics" | ||
| ) | ||
|
|
||
| print("Step 1: get reload count") | ||
| reload_count = get_reload_count(metrics_url) | ||
|
|
||
| wait_before_test(1) | ||
| print(f"Step 1a: initial reload count is {reload_count}") | ||
|
|
||
| print("Step 2: create duplicate existing secret with new name") | ||
| license_name = create_license( | ||
| kube_apis.v1, | ||
| ingress_controller_prerequisites.namespace, | ||
| cli_arguments["plus-jwt"], | ||
| license_token_name="license-token-changed", | ||
| ) | ||
| assert is_secret_present(kube_apis.v1, license_name, ingress_controller_prerequisites.namespace) | ||
|
|
||
| print("Step 3: update the ConfigMap/license-token-secret-name to the new secret") | ||
| replace_configmap_from_yaml( | ||
| kube_apis.v1, | ||
| "nginx-config-mgmt", | ||
| ingress_controller_prerequisites.namespace, | ||
| f"{TEST_DATA}/mgmt-configmap-keys/plus-token-name-keys.yaml", | ||
| ) | ||
|
|
||
| wait_before_test() | ||
|
|
||
| print("Step 4: check reload count has incremented") | ||
| new_reload_count = get_reload_count(metrics_url) | ||
| print(f"Step 4a: new reload count is {new_reload_count}") | ||
| assert new_reload_count > reload_count | ||
|
|
||
| print("Step 5: check pod for SecretUpdated event") | ||
| events = get_events_for_object( | ||
| kube_apis.v1, | ||
| ingress_controller_prerequisites.namespace, | ||
| ic_pod_name, | ||
| ) | ||
|
|
||
| # Assert that the 'SecretUpdated' event is present | ||
| assert_event( | ||
| events, | ||
| "Normal", | ||
| "SecretUpdated", | ||
| f"the special Secret {ingress_controller_prerequisites.namespace}/{license_name} was updated", | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.