Closed carltonmason closed 5 years ago
I wonder if .class
is the cause of the problem. It's a reserved word in Ruby and a lot of other languages.
What happens if you use the bracket-style for the child node? i.e., "$.metadata.annotations.ingress['class']"
Thanks @docwhat, I tried that and it is better as I no longer get the "FrozenError" but the rule assertion fails. Getting closer...
My yaml input:
rule IngressAnnotation ensure {
// fetch("$.metadata.annotations.kubernetes.io/ingress.class").first == "eurekap" // Doesn't work, error: can't modify frozen String (FrozenError)
fetch("$.metadata.annotations.ingress['class']").first == "eurekap" // The assertion fails "IngressAnnotation - FAIL" better than the frozen string error...
}
My rule file:
rule IngressAnnotation ensure {
// fetch("$.metadata.annotations.kubernetes.io/ingress.class").first == "eurekap" // Doesn't work, error: can't modify frozen String (FrozenError)
fetch("$.metadata.annotations.ingress['class']").first == "eurekap" // The assertion fails "IngressAnnotation - FAIL" better than the frozen string error...
}
And the result of running both in Copper:
copper check --rules ingress.cop --file ingress-good.yaml
Validating part 0
IngressAnnotation - FAIL
Copper uses JSONPath format in which .
has a special meaning. You can use [
to refernece attributes better. For more details, please see https://goessner.net/articles/JsonPath/
D'oh! I missed that ingress.class
was a single path component.
@carltonmason
Given:
metadata:
annotations:
kubernetes.io/ingress.class: eurekap
You should use:
"$.metadata.annotations['kubernetes.io/ingress.class']"
@docwhat that worked! Thanks.
Hello Again,
I am trying to validate that a simple Ingress .yaml contains a certain ingress class in its annotations yet, I get:
I think it has something to do with the
.
and/
in my annotation values.Here is my input yaml:
Here is my Copper rule file:
And when I run Copper, I get the following error:
If I modify both my .yaml and the rule to get rid of the slashes and dots in the annotation element, it works. I can't use that as a solution though. So, its got something to do with the format of my annotation and not sure how to get it to read them properly.
For example, if I modify my .yaml and rule to change my annotation from
kubernetes.io/ingress.class
toingress-class
it works.The Copper rule to be:
Then it works:
Thanks for your help.