-
Notifications
You must be signed in to change notification settings - Fork 420
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
resources: Fail on non-string template labels. #1030
Conversation
Although ObjectMeta defines labels as a map[string]string, Unstructured types allow for map[string]interface{}, which means that users can set non-string values like ints in their configurations, and we will parse it with no issues. We discovered that the behavior of [unstructured.GetLabels](https://github.com/kubernetes/apimachinery/blob/dd12c7a65e7f49c4e00b5bd5eb93de2fcbf7831d/pkg/apis/meta/v1/unstructured/unstructured.go#L395) will silently ignore errors, returning an empty label set if a non-string value is included. When used in triggers, this looks like we are completely ignoring the user provided labels. This change replaces GetLabels with it's underlying implementation, and bubbles back the non-string error if it is encountered.
/kind bug |
The following is the coverage report on the affected files.
|
Nice -- one thing I was thinking was that we could do a similar check in the resourceTemplate validation as well...so that if a user creates a resource with the wrong type, we catch it at creation time vs run time. What do you think? /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
That's probably going to be more work than I want to commit to for this PR. 😅 TriggerResourceTemplates are currently stored as Worth noting - if we move forward with #697 this validation should happen automatically. |
Ahh, missed the runtime.RawExtension vs unstructured.Unstructured difference. I don't think it would be too bad converting them in the controller/webhook but I agree that is outside the scope of this PR. |
Changes
Although ObjectMeta defines labels as a map[string]string, Unstructured
types allow for map[string]interface{}, which means that users can set
non-string values like ints in their configurations, and we will parse it
with no issues.
We discovered that the behavior of
unstructured.GetLabels
will silently ignore errors, returning an empty label set if a
non-string value is included. When used in triggers, this looks like we
are completely ignoring the user provided labels.
This change replaces GetLabels with it's underlying implementation, and bubbles
back the non-string error if it is encountered.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Release Note