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

Test traefik with kubernetes.ingress.localhost-only #5151

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

Nino-K
Copy link
Member

@Nino-K Nino-K commented Jul 12, 2023

Adds additional tests to test the kubernetes.ingress.localhost-only setting.

try --max 30 --delay 10 curl_exe --head --insecure "https://localhost:443"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
# traefik should not be accessible on other interfacec

Check failure

Code scanning / check-spelling

Unrecognized Spelling

[interfacec](#security-tab) is not a recognized word. \(unrecognized-spelling\)
@Nino-K Nino-K force-pushed the add-bats-traefik-test branch 2 times, most recently from ae0c61c to fc8ca34 Compare July 12, 2023 00:09
@gaktive gaktive requested a review from jandubois July 12, 2023 18:11
@Nino-K Nino-K force-pushed the add-bats-traefik-test branch 4 times, most recently from 07d669c to 02a6509 Compare July 21, 2023 20:02
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

First round of feedback

bats/tests/helpers/paths.bash Outdated Show resolved Hide resolved
bats/tests/k8s/traefik.bats Outdated Show resolved Hide resolved
Comment on lines 53 to 50
curl_exe_http_traefik() {
local HTTP_URL=$1
try --max 30 --delay 10 curl.exe --head "$HTTP_URL"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
}
Copy link
Member

Choose a reason for hiding this comment

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

You could generalize this slightly and get rid of curl_exe_https_traefik:

Suggested change
curl_exe_http_traefik() {
local HTTP_URL=$1
try --max 30 --delay 10 curl.exe --head "$HTTP_URL"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
}
curl_exe_traefik() {
try --max 30 --delay 10 curl.exe --head "$@"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
}

And then call it:

 curl_exe_traefik "http://$(wsl_ip):80"
 curl_exe_traefik --insecure "https://$(wsl_ip):443"

Comment on lines 101 to 94
run try --max 30 --delay 10 curl --head "http://localhost:80"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
run try --max 30 --delay 10 curl --head --insecure "https://$(get_host):443"
run try --max 30 --delay 10 curl --head --insecure "https://localhost:443"
assert_success
assert_output --regexp 'HTTP/[0-9.]* 404'
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't all this turn into:

 curl_exe_traefik "http://localhost:80"
 curl_exe_traefik --insecure "https://localhost:443"

Copy link
Member Author

Choose a reason for hiding this comment

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

That one is calling curl, basically, curl from inside the distro.

wait_for_apiserver
# Check if the traefik pods come up
try --max 30 --delay 10 assert_traefik_pods_are_up
assert_success
Copy link
Member

Choose a reason for hiding this comment

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

You don't need assert_success because you did't use run.


# traefik should not be accessible on other interface
run curl.exe --head "http://$(wsl_ip):80"
assert_output --partial "Couldn't connect to server"
Copy link
Member

Choose a reason for hiding this comment

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

I can't make up my mind if there should be an assert_success before testing $output, but I guess it doesn't matter, as we don't test how curl itself behaves.

try --max 30 --delay 10 assert_traefik_pods_are_up
}

@test 'curl traefik endpoints from Windows Host while kubernetes.ingress.localhost-only is true' {
Copy link
Member

Choose a reason for hiding this comment

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

This test needs a if ! is_windows check

@Nino-K Nino-K force-pushed the add-bats-traefik-test branch 3 times, most recently from a784566 to 6a628f1 Compare July 28, 2023 17:50
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Just saw that I still had a pending comment I never sent

@@ -45,18 +41,15 @@ assert_traefik_pods_are_down() {
}

assert_traefik_pods_are_up() {
run kubectl get --all-namespaces pods
ip_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
run kubectl -n kube-system get service traefik -o jsonpath="{.status.loadBalancer.ingress[0].ip}"
Copy link
Member

Choose a reason for hiding this comment

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

Probably should be followed by assert_success. The regex match would fail anyways, but I think it would be clearer to show that kubectl itself failed.

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

The test seems to hang indefinitely on Windows with RD_USE_NETWORKING_TUNNEL=1 RD_USE_WINDOWS_EXE=0:

 ✗ start k8s
   (from function `assert' in file bats-assert/src/assert.bash, line 40,
    from function `wait_for_apiserver' in file tests/helpers/kubernetes.bash, line 6,
    in test file tests/k8s/traefik.bats, line 83)
     `wait_for_apiserver' failed
   time="2023-08-01T15:26:36-07:00" level=info msg="About to launch C:\\Program Files\\Rancher Desktop\\Rancher Desktop.exe --application.debug=true --application.updater.enabled=false --containerEngine.name containerd --kubernetes.version 1.22.7 --kubernetes.enabled=true --kubernetes.options.traefik=true --experimental.virtualMachine.networkingTunnel=true ...\n"
   (node:4652) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
   (Use `Rancher Desktop --trace-deprecation ...` to show where the warning was created)

   -- assertion failed --
   expression : [ 1690929396 -lt 1690929396 ]
   --

If the tests are not (yet) expected to work in this combination, then they should be skipped.

Other than this, everything looks fine.

@Nino-K
Copy link
Member Author

Nino-K commented Aug 3, 2023

RD_USE_NETWORKING_TUNNEL=1

This combination needs to be skipped or cannot run right now due to the wsl integration. The wait_for_apiserver is running from the Ubuntu distro which makes an assumption that the API is accessible via 127.0.0.1:6443.
However, since we have not implemented the wsl integration in the new network stack this is not going to work.

Signed-off-by: Nino Kodabande <nkodabande@suse.com>
Copy link
Contributor

@ericpromislow ericpromislow left a comment

Choose a reason for hiding this comment

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

Tests passed on all three platforms. Code looks fine. Let's merge

@ericpromislow ericpromislow dismissed jandubois’s stale review August 3, 2023 21:05

The test now skips when RD_USE_NETWORKING_TUNNEL=1 and RD_USE_WINDOWS_EXE=0

@ericpromislow ericpromislow merged commit e55dc89 into main Aug 3, 2023
14 checks passed
@ericpromislow ericpromislow deleted the add-bats-traefik-test branch August 3, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants