-
Notifications
You must be signed in to change notification settings - Fork 87
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
[KEP-0009] feat: add expression based assertions #576
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, but needs a few changes.
pkg/test/utils/kubernetes.go
Outdated
@@ -1321,3 +1398,29 @@ func Kubeconfig(cfg *rest.Config, w io.Writer) error { | |||
}, | |||
}, w) | |||
} | |||
|
|||
func constructGVK(apiVersion, kind string) schema.GroupVersionKind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice helper method, but it would be even more powerful it you
- changed it from a bare
func
to a method ofTestResourceRef
- made it also internally create an
*Unstructured
:gvk := constructGVK(resourceRef.ApiVersion, resourceRef.Kind) referencedResource := &unstructured.Unstructured{} referencedResource.SetGroupVersionKind(gvk)
- and called it
NewUnstructured
or similar.
Thinking about it, it might make sense to have it also return a NamespacedName
and an error
in case crucial fields (like name and kind) are missing. On one hand, if we don't do any validation here, then the client would probably catch such garbage later. But on the other hand, we could use such validation function earlier, just after loading the assert files, in order to give user feedback on critical errors ASAP.
When you're at it, please also add a couple of test cases for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NamespacedName
/*unstructured.Unstructured
would be required when we evaluate the expressions. If the goal is also to validate, we should have two separate methods:
func (t *TestResourceRef) BuildResourceReference() (namespacedName types.NamespacedName, referencedResource *unstructured.Unstructured)
func (t *TestResourceRef) Validate() (error)
pkg/test/utils/kubernetes.go
Outdated
variables[resourceRef.Id] = referencedResource.Object | ||
} | ||
|
||
env, err := cel.NewEnv() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling cel.NewEnv()
may not be enough, you probably want to enable a couple of options/libs.
This PR adds CEL-expression based assertions to `TestAsserts`. See https://github.com/kudobuilder/kuttl/blob/main/keps/0009-expression-based-assertions.md for more details. Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
3c7d6fe
to
0e43475
Compare
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
…re present Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
0fe748e
to
a85752a
Compare
pkg/test/utils/kubernetes.go
Outdated
|
||
variables := make(map[string]interface{}) | ||
for _, resourceRef := range resourceRefs { | ||
namespacedName, referencedResource := resourceRef.BuildResourceReference() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about the namespace, this should probably default to the current test's namespace if not specified in the assert file 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about cluster-scoped resources? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check. I think some clients ignore the namespace if it's specified when fetching cluster-scoped resources, so while ugly and confusing, we could keep it for simplicity. If this client is more picky, then we'd have to look into discovery to distinguish cluster-scoped from namespaced ones 🤔
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Signed-off-by: Kumar Mallikarjuna <kumarmallikarjuna.work@gmail.com>
Thanks for the quick review @porridge . I'll add the tests tomorrow. |
What this PR does / why we need it:
This PR adds CEL-expression based assertions to
TestAsserts
. See https://github.com/kudobuilder/kuttl/blob/main/keps/0009-expression-based-assertions.md for more details.Fixes #562