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/e2e: improve nginx deployment test #2044

Conversation

wainersm
Copy link
Member

The nginx deployment test isn't completely stable. Sometimes it fails and we don't know yet whether it's a legit bug on peer pods or not. With this PR I don't solve that problem either, as I still don't know the roots of the problem, however, it improves the test that it will run the Teardown() function even when WithSetup() failed. We have this suspect that the left nginx deployment might be messing with the next tests, so this change will at least solve that problem (if it's really a problem). Regardless, tests should always delete their resources at the execution end.

There is one thing that I'd like to implement, which is, do not run Teardown() if not running on CI. In other words, if I'm running the test locally and it fails I want to have the deployment running so I can inspect. I may be sending this on another PR or maybe even on this one....depending on the reviews.

@stevenhorsman stevenhorsman added the test_e2e_libvirt Run Libvirt e2e tests label Sep 18, 2024
Copy link
Member

@stevenhorsman stevenhorsman left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Thanks @wainersm!

@mkulke
Copy link
Collaborator

mkulke commented Sep 18, 2024

i don't have a lot of context, but in my (manual) tests I'm always using deployments. but, essentially, deployments are higher-order kubernetes constructs, as a primitive they should not be relevant for CAA. Thus, if we hava a Deployment test that will spawn Pods w/ a Pod spec that is 1:1 matching the Spec for a (reliable) Pod test, I'd conclude that there are problems in our testing suite (race conditions probably). Maybe it makes sense to remodel the deployment tests to mirror the pod test closely.

@mkulke
Copy link
Collaborator

mkulke commented Sep 18, 2024

I also noticed that the test cause side-effects that makes it impossible to run them in parallel. Essentially the asserts of a test find leftovers of services or other k8s objects, because they use the same name. So, it might make sense to create some logic that will make a test independent, because there is a random segment in the names

@stevenhorsman
Copy link
Member

I also noticed that the test cause side-effects that makes it impossible to run them in parallel. Essentially the asserts of a test find leftovers of services or other k8s objects, because they use the same name. So, it might make sense to create some logic that will make a test independent, because there is a random segment in the names

We currently have a different namespace for each test run. We picked that to make it easier to clean everything up together if it went wrong, but if you think it would help to have a random namespace for every tests, then we could consider that?

@mkulke
Copy link
Collaborator

mkulke commented Sep 19, 2024

We currently have a different namespace for each test run. We picked that to make it easier to clean everything up together if it went wrong, but if you think it would help to have a random namespace for every tests, then we could consider that?

yeah, ideally, within a test-run the tests should also be independent, so maybe running them in their own namespace would indeed be a good measure, it'll also help with cleanup. we can use a label: test-run: 123 for the ns, so we can bulk delete in a tear-down section.

@wainersm
Copy link
Member Author

wainersm commented Oct 7, 2024

Hi @mkulke ,

i don't have a lot of context, but in my (manual) tests I'm always using deployments. but, essentially, deployments are higher-order kubernetes constructs, as a primitive they should not be relevant for CAA. Thus, if we hava a Deployment test that will spawn Pods w/ a Pod spec that is 1:1 matching the Spec for a (reliable) Pod test, I'd conclude that there are problems in our testing suite (race conditions probably). Maybe it makes sense to remodel the deployment tests to mirror the pod test closely.

I don't remember the context that nginx deployment test was added, the original commit doesn't explain either, so I don't know for sure. Well, it's exercising ReadinessProbe and LivenessProbe, maybe Probes are relevant for peer pods implementation? Let's suppose "yes", do the test should be a Deployment rather than a regular Pod?

In the end, I'm trying to understand whether I should address the static checker errors aiming to get this merged OR drop the nginx deployment test OR take another action :)

@wainersm
Copy link
Member Author

wainersm commented Oct 7, 2024

We currently have a different namespace for each test run. We picked that to make it easier to clean everything up together if it went wrong, but if you think it would help to have a random namespace for every tests, then we could consider that?

yeah, ideally, within a test-run the tests should also be independent, so maybe running them in their own namespace would indeed be a good measure, it'll also help with cleanup. we can use a label: test-run: 123 for the ns, so we can bulk delete in a tear-down section.

Makes sense to me. Created an issue to discuss that and other stuffs for running the tests in parallel: #2092

@wainersm wainersm force-pushed the improve_nginx_deployment_test branch from ead2efe to a3749ee Compare December 5, 2024 13:37
@wainersm wainersm requested a review from a team as a code owner December 5, 2024 13:37
@wainersm
Copy link
Member Author

wainersm commented Dec 5, 2024

@stevenhorsman rebased and resolved conflicts. I will run it locally and past the results here as this test is disabled on CI.

@stevenhorsman
Copy link
Member

I've had some success in #2183 uncommenting some of the failed tests, so do you think it's worth trying to un skip it as part of this PR, or do you just want to get these improvements in for local tests at the moment?

@wainersm
Copy link
Member Author

wainersm commented Dec 5, 2024

@stevenhorsman nginx deployment failed locally. It might be my environment. The good thing is that this failure ended up testing the changes I'm proposing here :)

So I think it's better to submit a separated PR with the tests that passed on PR 2183

=== RUN   TestLibvirtCreateNginxDeployment
=== RUN   TestLibvirtCreateNginxDeployment/Nginx_image_deployment_test
    nginx_deployment.go:111: Creating nginx deployment...
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:179: Current deployment available replicas: 0
    nginx_deployment.go:183: timed out waiting for the condition
    nginx_deployment.go:191: ===================
    nginx_deployment.go:192: Debug info for pod: nginx-deployment-7b8496c665-6z8xl
    nginx_deployment.go:197: Current Pod State: phase: Pending
        conditions:
        - type: PodReadyToStartContainers
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        - type: Initialized
          status: "True"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        - type: Ready
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ContainersNotReady
          message: 'containers with unready status: [nginx]'
        - type: ContainersReady
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ContainersNotReady
          message: 'containers with unready status: [nginx]'
        - type: PodScheduled
          status: "True"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        message: ""
        reason: ""
        nominatednodename: ""
        hostip: 192.168.122.245
        podip: ""
        podips: []
        starttime: "2024-12-05T11:03:07-03:00"
        initcontainerstatuses: []
        containerstatuses:
        - name: nginx
          state:
            waiting:
              reason: ContainerCreating
              message: ""
            running: null
            terminated: null
          lastterminationstate:
            waiting: null
            running: null
            terminated: null
          ready: false
          restartcount: 0
          image: quay.io/nginx/nginx-unprivileged:latest
          imageid: ""
          containerid: ""
          started: false
        qosclass: BestEffort
        ephemeralcontainerstatuses: []
    nginx_deployment.go:191: ===================
    nginx_deployment.go:192: Debug info for pod: nginx-deployment-7b8496c665-qnxph
    nginx_deployment.go:197: Current Pod State: phase: Pending
        conditions:
        - type: PodReadyToStartContainers
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        - type: Initialized
          status: "True"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        - type: Ready
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ContainersNotReady
          message: 'containers with unready status: [nginx]'
        - type: ContainersReady
          status: "False"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ContainersNotReady
          message: 'containers with unready status: [nginx]'
        - type: PodScheduled
          status: "True"
          lastprobetime: "0001-01-01T00:00:00Z"
          lasttransitiontime: "2024-12-05T11:03:07-03:00"
          reason: ""
          message: ""
        message: ""
        reason: ""
        nominatednodename: ""
        hostip: 192.168.122.245
        podip: ""
        podips: []
        starttime: "2024-12-05T11:03:07-03:00"
        initcontainerstatuses: []
        containerstatuses:
        - name: nginx
          state:
            waiting:
              reason: ContainerCreating
              message: ""
            running: null
            terminated: null
          lastterminationstate:
            waiting: null
            running: null
            terminated: null
          ready: false
          restartcount: 0
          image: quay.io/nginx/nginx-unprivileged:latest
          imageid: ""
          containerid: ""
          started: false
        qosclass: BestEffort
        ephemeralcontainerstatuses: []
=== RUN   TestLibvirtCreateNginxDeployment/Nginx_image_deployment_test/Access_for_nginx_deployment_test
    nginx_deployment.go:126: 
=== NAME  TestLibvirtCreateNginxDeployment/Nginx_image_deployment_test
    nginx_deployment.go:152: Deleting webserver deployment...
    nginx_deployment.go:157: Deleting deployment nginx-deployment...
    nginx_deployment.go:164: Deployment nginx-deployment has been successfully deleted within 120s
--- FAIL: TestLibvirtCreateNginxDeployment (905.07s)
    --- FAIL: TestLibvirtCreateNginxDeployment/Nginx_image_deployment_test (905.07s)
        --- SKIP: TestLibvirtCreateNginxDeployment/Nginx_image_deployment_test/Access_for_nginx_deployment_test (0.00s)
FAIL
FAIL	github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/e2e	1772.082s
FAIL
make: *** [Makefile:97: test-e2e] Error 1

@stevenhorsman
Copy link
Member

Fair enough. I guess we get this in and worry about the other failure later?

@wainersm wainersm requested a review from mkulke December 6, 2024 17:56
Copy link
Collaborator

@mkulke mkulke left a comment

Choose a reason for hiding this comment

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

linter is sad, but otherwise lgtm

Fixed the printing of the pod name. Also will print an
user-friendly message when there isn't any pod logs to show.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
@wainersm wainersm force-pushed the improve_nginx_deployment_test branch from a3749ee to f49770a Compare December 9, 2024 19:40
@wainersm
Copy link
Member Author

wainersm commented Dec 9, 2024

linter is sad, but otherwise lgtm

Thanks! I had forgotten the linter warning... I sent a fix on a separated commit; if you guys ack then I can apply the fixup before merging.

The teardown function doesn't run if WithSetup fail, which might
leave the deployment on the cluster and it might mess with next
tests.

This replaced some t.Fatal() with t.Error() so that the current
goroutine doesn't exit, in fact, the execution continues after
the t.Error() call but the test is marked failed. So I had to
proper return when t.Error().

On WithSetup() failing, it doesn't make sense to run the Assess()
and the only way to pass the status down to Assess() is through the
`ctx` variable (due to a limitation on the k8s e2e framework, the `t`
object is not shared).

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
@wainersm wainersm force-pushed the improve_nginx_deployment_test branch from f49770a to 8eacfb2 Compare December 10, 2024 12:51
@wainersm
Copy link
Member Author

Just applied the fixup.

@stevenhorsman stevenhorsman merged commit 2435e0e into confidential-containers:main Dec 11, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e-test test_e2e_libvirt Run Libvirt e2e tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants