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

Proposal: Generate expected yaml from a command #552

Open
gmolau opened this issue Aug 19, 2024 · 1 comment
Open

Proposal: Generate expected yaml from a command #552

gmolau opened this issue Aug 19, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@gmolau
Copy link

gmolau commented Aug 19, 2024

Hi everyone, what do you think of making it possible to generate the expected yaml from a command? Currently there are two ways of writing the expected state:

  1. Directly in yaml
  2. Together with an assertion in a script

My use case is a controller that installs Helm charts, where I would like to make assertions against the helm status output. Since that output does not live on a cluster I currently have to write a script like this:


apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
  - script: |
      expectedNamespace=test-chart
      expectedRelease=test-chart
      expectedStatus=deployed
      
      helmStatus=$(helm status -n $expectedNamespace $expectedRelease)
      if [ $? -ne 0 ]; then
        echo "Failed to get Helm release status for $expectedRelease in namespace $expectedNamespace"
        exit 1
      fi
      
      status=$(echo "$helmStatus" | grep STATUS | awk '{print $2}')
      
      if [ "$status" != "$expectedStatus" ]; then
        echo "Expected Helm release $expectedRelease in namespace $expectedNamespace to have status '$expectedStatus', but got '$status'"
        exit 1
      fi

It would be much nicer if I could give a command that produces a yaml and an expected yaml, then rely on Kuttls internal machinery to compare the two. E.g. something like:

expected:
  status: deployed
actual: helm status -o yaml

Do you think it would be possible to add something like this? And if so, what would be the best way to implement it?

@porridge
Copy link
Member

I think it would be doable, but not exactly easy. Here is the function that does the fetching and comparison.

I'd suggest that you write a short proposal how this would look from the user's PoV. The expected yaml would likely go into an assert.yaml file, but what about the command which produces the actual yaml?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants