-
Notifications
You must be signed in to change notification settings - Fork 923
feat(coderd): update endpoint to allow filtering provisioner daemons by tags #15448
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
Changes from all commits
3d45f55
92b9d25
e68a8fc
93058e6
a2bfae3
39ab8a0
8bf79c8
86f7dab
bd6f3ed
a2476dc
e835326
23bd23f
9985ef6
a173bfb
70c7ea9
1c57bd2
ebb716d
96b64f4
5941dc3
ff75f5e
85b1ef4
071fdc4
78abf67
d1c7d3e
38d77cf
1c64353
8508cd8
9dcbb83
4c1fc0d
fbd70f3
69126f4
e109caf
f10561e
a56b130
2bce007
2860f5d
d6f26df
1ce410f
c065742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP FUNCTION IF EXISTS provisioner_tagset_contains(tagset, tagset); | ||
|
||
DROP DOMAIN IF EXISTS tagset; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CREATE DOMAIN tagset AS jsonb; | ||
|
||
COMMENT ON DOMAIN tagset IS 'A set of tags that match provisioner daemons to provisioner jobs, which can originate from workspaces or templates. tagset is a narrowed type over jsonb. It is expected to be the JSON representation of map[string]string. That is, {"key1": "value1", "key2": "value2"}. We need the narrowed type instead of just using jsonb so that we can give sqlc a type hint, otherwise it defaults to json.RawMessage. json.RawMessage is a suboptimal type to use in the context that we need tagset for.'; | ||
|
||
CREATE OR REPLACE FUNCTION provisioner_tagset_contains(provisioner_tags tagset, job_tags tagset) | ||
RETURNS boolean AS $$ | ||
BEGIN | ||
RETURN CASE | ||
-- Special case for untagged provisioners, where only an exact match should count | ||
WHEN job_tags::jsonb = '{"scope": "organization", "owner": ""}'::jsonb THEN job_tags::jsonb = provisioner_tags::jsonb | ||
-- General case | ||
ELSE job_tags::jsonb <@ provisioner_tags::jsonb | ||
END; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
COMMENT ON FUNCTION provisioner_tagset_contains(tagset, tagset) IS 'Returns true if the provisioner_tags contains the job_tags, or if the job_tags represents an untagged provisioner and the superset is exactly equal to the subset.'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
❤️ thanks for adding an explanation.
I'm curious why you needed to add an override for this type instead of doing so on a field-level like with
for example?
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.
It's been a few days since I've tested this. Happy to retest. But from memory of when I was generating the code for this, the type inference for the column works just fine. It just doesn't transitively apply to the parameters passed into the select query.
I'll have a look into this once more just to be able to give you a more concrete answer at least.
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.
Absolutely non-blocking; this can be done after merge