kudobuilder / kuttl

KUbernetes Test TooL (kuttl)
https://kuttl.dev
Apache License 2.0
636 stars 83 forks source link

fix: create namespace when running TestSuite #518

Closed chenmj11 closed 1 month ago

chenmj11 commented 2 months ago

What this PR does / why we need it:

The tests in a TestSuite fail, because the specified namespace does not exist.

kuttl-test.yaml

apiVersion: kuttl.dev/v1beta1
kind: TestSuite
namespace: test
timeout: 60
reportName: test
reportFormat: JSON 

error logs

    logger.go:42: 13:48:07 | pod | Ignoring pod-assert.yaml as it does not match file name regexp: ^(\d+)-(?:[^\.]+)(?:\.yaml)?$  
    logger.go:42: 13:48:07 | pod | Ignoring pod.yaml as it does not match file name regexp: ^(\d+)-(?:[^\.]+)(?:\.yaml)?$  
    logger.go:42: 13:48:07 | pod | Skipping creation of user-supplied namespace: test  
    logger.go:42: 13:48:07 | pod/0-step | starting test step 0-step  
    case.go:366: failed in step 0-step  
    case.go:368: namespaces "test" not found  

*Automatically closes linked issue when PR is merged. Fixes 512

porridge commented 1 month ago

Looking closer at this, the determineNamespace() call should probably be made using all clients once their list is populated a bit later. Otherwise we risk creating the ns on some clusters but not others, in case we get an error because the namespace already exists on some of them.

However I'm going to merge this now since it's already an improvement in the common single-cluster case.