Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3d45f55
feat(coderd/database): allow filtering provisioner daemons by tags
SasSwart Nov 8, 2024
92b9d25
feat(coderd/database): allow filtering provisioner daemons by tags
SasSwart Nov 8, 2024
e68a8fc
add a type hint for sqlc
SasSwart Nov 8, 2024
93058e6
ensure BC with GetProvisionerDaemonsByOrganization
SasSwart Nov 8, 2024
a2bfae3
add a type hint for sqlc
SasSwart Nov 11, 2024
39ab8a0
fix unit test
SasSwart Nov 11, 2024
8bf79c8
Add tags param to provisioner daemons endpoint
SasSwart Nov 11, 2024
86f7dab
fix provisioner tag filtering
SasSwart Nov 11, 2024
bd6f3ed
handle tag reading error
SasSwart Nov 11, 2024
a2476dc
remove assignment to a nil map
SasSwart Nov 11, 2024
e835326
filter by tags in dbmem
SasSwart Nov 11, 2024
23bd23f
correctly set the default value when no tags are provided
SasSwart Nov 11, 2024
9985ef6
support the zero value tag in sql
SasSwart Nov 11, 2024
a173bfb
update the default value for when no tags are provided
SasSwart Nov 12, 2024
70c7ea9
use a sql domain as a type alias so that we can override it as a Stri…
SasSwart Nov 12, 2024
1c57bd2
complete down migration
SasSwart Nov 12, 2024
ebb716d
complete down migration
SasSwart Nov 12, 2024
96b64f4
update the default value for when no tags are provided
SasSwart Nov 12, 2024
5941dc3
fix job acquisition for untagged provisioners
SasSwart Nov 12, 2024
ff75f5e
make gen
SasSwart Nov 12, 2024
85b1ef4
review notes
SasSwart Nov 12, 2024
071fdc4
fix down migration
SasSwart Nov 12, 2024
78abf67
use the correct name for provisionerdaemons' tag field
SasSwart Nov 12, 2024
d1c7d3e
typo
SasSwart Nov 12, 2024
38d77cf
use the updated tag name
SasSwart Nov 12, 2024
1c64353
fix special case of tagset_contains
SasSwart Nov 12, 2024
8508cd8
Use a stringmap instead of a stringslice for provisioner tags
SasSwart Nov 13, 2024
9dcbb83
update tags param parsing in provisionerDaemons
SasSwart Nov 13, 2024
4c1fc0d
update tags param parsing in provisionerDaemons
SasSwart Nov 13, 2024
fbd70f3
fix special case of tagset_contains
SasSwart Nov 13, 2024
69126f4
rename tagset_contains function
SasSwart Nov 13, 2024
e109caf
attempt to fix the special case for provisioner_tagset_contains
SasSwart Nov 13, 2024
f10561e
attempt to fix the special case for provisioner_tagset_contains
SasSwart Nov 13, 2024
a56b130
attempt to fix the special case for provisioner_tagset_contains
SasSwart Nov 13, 2024
2bce007
fix provisioner_tagset_contains
SasSwart Nov 13, 2024
2860f5d
remove defunct code
SasSwart Nov 14, 2024
d6f26df
Add tag filtering tests for GetProvisionerDaemons
SasSwart Nov 14, 2024
1ce410f
fix foreign key constraint in tests
SasSwart Nov 14, 2024
c065742
Add linting
SasSwart Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix provisioner tag filtering
  • Loading branch information
SasSwart committed Nov 11, 2024
commit 86f7dab01b079bc70d305da9d4f85860d259ca83
8 changes: 4 additions & 4 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions coderd/database/migrations/000274_check_tags.up.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE OR REPLACE FUNCTION tags_compatible(provisioner_tags jsonb, required_tags jsonb)
CREATE OR REPLACE FUNCTION tags_compatible(subset_tags jsonb, superset_tags jsonb)
RETURNS boolean as $$
BEGIN
RETURN CASE
WHEN provisioner_tags = '{"scope": "organization", "owner": ""}' :: jsonb
THEN provisioner_tags = required_tags
ELSE required_tags <@ provisioner_tags
WHEN superset_tags = '{"scope": "organization", "owner": ""}' :: jsonb
THEN subset_tags = superset_tags
ELSE subset_tags <@ superset_tags
END;
END;
$$ LANGUAGE plpgsql;
2 changes: 1 addition & 1 deletion coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WHERE
AND nested.organization_id = @organization_id
-- Ensure the caller has the correct provisioner.
AND nested.provisioner = ANY(@types :: provisioner_type [ ])
AND tags_compatible(nested.tags, @tags)
AND tags_compatible(@tags, nested.tags)
ORDER BY
nested.created_at
FOR UPDATE
Expand Down
15 changes: 7 additions & 8 deletions enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
org := httpmw.OrganizationParam(r)

tags := provisionerTags(r)

tagsJSON, err := json.Marshal(tags)

Check failure on line 68 in enterprise/coderd/provisionerdaemons.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
daemons, err := api.Database.GetProvisionerDaemonsByOrganization(
ctx,
database.GetProvisionerDaemonsByOrganizationParams{
OrganizationID: org.ID,
Tags: tags,
Tags: tagsJSON,
},
)
if err != nil {
Expand All @@ -84,22 +84,21 @@
httpapi.Write(ctx, rw, http.StatusOK, db2sdk.List(daemons, db2sdk.ProvisionerDaemon))
}

func provisionerTags(r *http.Request) json.RawMessage {
func provisionerTags(r *http.Request) map[string]string {
tags := r.URL.Query()["tags"]
if len(tags) == 0 {
return json.RawMessage("{}")
return nil
}

var pairs []string
var tagMap map[string]string
for _, tag := range tags {
parts := strings.SplitN(tag, "=", 2)
if len(parts) == 2 {
pairs = append(pairs, fmt.Sprintf(`%q:%q`, parts[0], parts[1]))
tagMap[parts[0]] = parts[1]

Check failure on line 97 in enterprise/coderd/provisionerdaemons.go

View workflow job for this annotation

GitHub Actions / lint

SA5000: assignment to nil map (staticcheck)
}
}

jsonString := fmt.Sprintf("{%s}", strings.Join(pairs, ","))
return json.RawMessage(jsonString)
return tagMap
}

type provisiionerDaemonAuthResponse struct {
Expand Down
Loading