-
Notifications
You must be signed in to change notification settings - Fork 24
test: kubectl-dns secret-generation command #841
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
Merged
Changes from all commits
Commits
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
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
Empty file.
File renamed without changes.
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,25 @@ | ||
| """Wrapper around kubectl-dns binary""" | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
|
|
||
| class KubectlDNS: | ||
| """Wrapper on top of kubectl-dns binary""" | ||
|
|
||
| def __init__(self, binary) -> None: | ||
| super().__init__() | ||
| self.binary = binary | ||
|
|
||
| def run(self, *args, **kwargs): | ||
| """Passes arguments to subprocess.run()""" | ||
| args = (self.binary, *args) | ||
| kwargs.setdefault("capture_output", True) | ||
| kwargs.setdefault("text", True) | ||
|
|
||
| if "env" in kwargs: | ||
| env = os.environ.copy() | ||
| env.update(kwargs["env"]) | ||
| kwargs["env"] = env | ||
|
|
||
| return subprocess.run(args, **kwargs) # pylint: disable= subprocess-run-check | ||
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
Empty file.
52 changes: 52 additions & 0 deletions
52
testsuite/tests/multicluster/coredns/two_clusters/kubectl_dns/test_secret_generation.py
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,52 @@ | ||
| """Test kubectl-dns secret-generate command with basic coredns setup with 1 primary and 1 secondary clusters""" | ||
|
|
||
| import shutil | ||
|
|
||
| import dns.resolver | ||
| import pytest | ||
|
|
||
| from testsuite.cli.kubectl_dns import KubectlDNS | ||
| from testsuite.tests.multicluster.coredns.conftest import IP1, IP2 | ||
|
|
||
| pytestmark = [pytest.mark.cli] | ||
|
averevki marked this conversation as resolved.
|
||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def kubectl_dns(testconfig, skip_or_fail): | ||
| """Return Kuadrantctl wrapper with merged kubeconfig""" | ||
| binary_path = testconfig["kubectl-dns"] | ||
| if not shutil.which(binary_path): | ||
|
averevki marked this conversation as resolved.
|
||
| skip_or_fail("kubectl-dns binary not found") | ||
| return KubectlDNS(binary_path) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def kubeconfig_secrets(request, testconfig, cluster, cluster2, kubectl_dns, blame): | ||
|
averevki marked this conversation as resolved.
|
||
| """Run generate-secret command on merged kubeconfig to generate kubeconfig secret for the secondary cluster""" | ||
| system_project = testconfig["service_protection"]["system_project"] | ||
| secret_name = blame("kubecfg") | ||
|
averevki marked this conversation as resolved.
|
||
| request.addfinalizer( | ||
| lambda: cluster.do_action("delete", "secret", secret_name, "-n", system_project, "--ignore-not-found") | ||
| ) | ||
|
|
||
| merged_kubeconfig = cluster.create_merged_kubeconfig(cluster2) | ||
| result = kubectl_dns.run( | ||
| "secret-generation", | ||
| "--name", | ||
| secret_name, | ||
| "--context", | ||
| cluster2.current_context_name, | ||
| "--namespace", | ||
| system_project, | ||
| "--service-account", | ||
| "coredns", | ||
| env={"KUBECONFIG": merged_kubeconfig}, | ||
| ) | ||
| assert result.returncode == 0, f"kubectl-dns couldn't generate kubeconfig secret: {result.stderr}" | ||
| return [] | ||
|
|
||
|
|
||
| def test_kubectl_dns_secret_generation(hostname): | ||
| """IPs from both, primary and secondary, clusters should return in DNS A record set""" | ||
| dns_ips = {ip.address for ip in dns.resolver.resolve(hostname.hostname)} | ||
| assert {IP1, IP2} == dns_ips, "CoreDNS should have returned both IP addresses in A record set" | ||
Oops, something went wrong.
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.