kudobuilder/kuttl

Assert if a field is missing from a resource

gibizer opened this issue · 7 comments

What would you like to be added:

A way to assert if a field is missing from the resource.

Why is this needed:

For example as a test step I'm scaling down a Deployment to 0 replicas and I want to assert that

apiVersion: apps/v1
kind: Deployment
metadata:
  name: keystone
status:
  availableReplicas: 0

However when the availableReplicas is 0 the field itself is not returned from the api server so my assert fails.

I think you can do this already, at least as a workaround, by using the "errors" feature. Continuing on your example, you could just add a 00-errors.yaml (adjust the index to your test) file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: keystone
status:
  availableReplicas: {}

Should this match any value for availableReplicas? I'm trying with the errors command against a deployment that has a value for availableReplicas of 2 and it does not fail. But if I change the {} to a 2 in the errors file, then it catches it.

Should this match any value for availableReplicas? I'm trying with the errors command against a deployment that has a value for availableReplicas of 2 and it does not fail. But if I change the {} to a 2 in the errors file, then it catches it.

Ok, then it seems like my suggestion only works when the field is a dict, and not when it is a literal.

Is there any way to do a similar existence check if the field is a literal?

Is there any way to do a similar existence check if the field is a literal?

Not that I am aware of, except using command/script - which can do "anything". But it's a lot less flexible IMO.

Thank you folks.
I'm wondering if the kuttl maintainers would be open to extend kuttl to handle this somehow.

They will be open to that for sure!