Skip to content

Commit bb1eda7

Browse files
committed
feat(tags): add ptype tags support
1 parent 4b6fc44 commit bb1eda7

File tree

8 files changed

+84
-65
lines changed

8 files changed

+84
-65
lines changed

cmd/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ type Commander interface {
9898
RoutingEnable(string) error
9999
RoutingDisable(string) error
100100
ShortcutsList() error
101-
TagsList(string) error
102-
TagsSet(string, []string) error
103-
TagsUnset(string, []string) error
101+
TagsList(string, string) error
102+
TagsSet(string, string, []string) error
103+
TagsUnset(string, string, []string) error
104104
TLSInfo(string) error
105105
TLSForceEnable(string) error
106106
TLSForceDisable(string) error

cmd/tags.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// TagsList lists an app's tags.
12-
func (d *DryccCmd) TagsList(appID string) error {
12+
func (d *DryccCmd) TagsList(appID, procType string) error {
1313
s, appID, err := load(d.ConfigFile, appID)
1414

1515
if err != nil {
@@ -23,20 +23,22 @@ func (d *DryccCmd) TagsList(appID string) error {
2323
if len(config.Tags) == 0 {
2424
d.Println(fmt.Sprintf("No tags found in %s app.", appID))
2525
} else {
26-
table := d.getDefaultFormatTable([]string{"PTYPE", "TAG"})
27-
for _, key := range *sortKeys(config.Tags) {
28-
table.Append([]string{
29-
key,
30-
fmt.Sprintf("%v", config.Tags[key]),
31-
})
26+
if tags, ok := config.Tags[procType]; ok {
27+
table := d.getDefaultFormatTable([]string{"KEY", "VALUE"})
28+
for _, key := range *sortKeys(tags) {
29+
table.Append([]string{
30+
key,
31+
fmt.Sprintf("%v", config.Tags[procType][key]),
32+
})
33+
}
34+
table.Render()
3235
}
33-
table.Render()
3436
}
3537
return nil
3638
}
3739

3840
// TagsSet sets an app's tags.
39-
func (d *DryccCmd) TagsSet(appID string, tags []string) error {
41+
func (d *DryccCmd) TagsSet(appID, procType string, tags []string) error {
4042
s, appID, err := load(d.ConfigFile, appID)
4143

4244
if err != nil {
@@ -51,8 +53,8 @@ func (d *DryccCmd) TagsSet(appID string, tags []string) error {
5153
d.Print("Applying tags... ")
5254

5355
quit := progress(d.WOut)
54-
configObj := api.Config{}
55-
configObj.Tags = tagsMap
56+
configObj := api.Config{Tags: make(map[string]api.ConfigTags)}
57+
configObj.Tags[procType] = tagsMap
5658

5759
_, err = config.Set(s.Client, appID, configObj)
5860
quit <- true
@@ -63,11 +65,11 @@ func (d *DryccCmd) TagsSet(appID string, tags []string) error {
6365

6466
d.Print("done\n\n")
6567

66-
return d.TagsList(appID)
68+
return d.TagsList(appID, procType)
6769
}
6870

6971
// TagsUnset removes an app's tags.
70-
func (d *DryccCmd) TagsUnset(appID string, tags []string) error {
72+
func (d *DryccCmd) TagsUnset(appID, procType string, tags []string) error {
7173
s, appID, err := load(d.ConfigFile, appID)
7274

7375
if err != nil {
@@ -78,15 +80,12 @@ func (d *DryccCmd) TagsUnset(appID string, tags []string) error {
7880

7981
quit := progress(d.WOut)
8082

81-
configObj := api.Config{}
82-
83-
tagsMap := make(map[string]interface{})
84-
83+
configObj := api.Config{Tags: make(map[string]api.ConfigTags)}
84+
configTags := make(api.ConfigTags)
8585
for _, tag := range tags {
86-
tagsMap[tag] = nil
86+
configTags[tag] = nil
8787
}
88-
89-
configObj.Tags = tagsMap
88+
configObj.Tags[procType] = configTags
9089

9190
_, err = config.Set(s.Client, appID, configObj)
9291
quit <- true
@@ -97,7 +96,7 @@ func (d *DryccCmd) TagsUnset(appID string, tags []string) error {
9796

9897
d.Print("done\n\n")
9998

100-
return d.TagsList(appID)
99+
return d.TagsList(appID, procType)
101100
}
102101

103102
func parseTags(tags []string) (map[string]interface{}, error) {

cmd/tags_test.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ func TestTagsList(t *testing.T) {
9191
"memory": {},
9292
"cpu": {},
9393
"tags": {
94-
"warp": "8",
95-
"ncc": "1701"
94+
"web": {
95+
"warp": "8",
96+
"ncc": "1701"
97+
}
9698
},
9799
"registry": {},
98100
"created": "2014-01-01T00:00:00UTC",
@@ -104,11 +106,11 @@ func TestTagsList(t *testing.T) {
104106
var b bytes.Buffer
105107
cmdr := DryccCmd{WOut: &b, ConfigFile: cf}
106108

107-
err = cmdr.TagsList("enterprise")
109+
err = cmdr.TagsList("enterprise", "web")
108110
assert.NoError(t, err)
109-
assert.Equal(t, b.String(), `PTYPE TAG
110-
ncc 1701
111-
warp 8
111+
assert.Equal(t, b.String(), `KEY VALUE
112+
ncc 1701
113+
warp 8
112114
`, "output")
113115
}
114116

@@ -124,8 +126,8 @@ func TestTagsSet(t *testing.T) {
124126
testutil.SetHeaders(w)
125127
if r.Method == "POST" {
126128
testutil.AssertBody(t, api.Config{
127-
Tags: map[string]interface{}{
128-
"true": "false",
129+
Tags: map[string]api.ConfigTags{
130+
"web": {"true": "false"},
129131
},
130132
}, r)
131133
}
@@ -137,7 +139,9 @@ func TestTagsSet(t *testing.T) {
137139
"memory": {},
138140
"cpu": {},
139141
"tags": {
140-
"true": "false"
142+
"web": {
143+
"true": "false"
144+
}
141145
},
142146
"registry": {},
143147
"created": "2014-01-01T00:00:00UTC",
@@ -149,13 +153,13 @@ func TestTagsSet(t *testing.T) {
149153
var b bytes.Buffer
150154
cmdr := DryccCmd{WOut: &b, ConfigFile: cf}
151155

152-
err = cmdr.TagsSet("foo", []string{"true=false"})
156+
err = cmdr.TagsSet("foo", "web", []string{"true=false"})
153157
assert.NoError(t, err)
154158

155159
assert.Equal(t, testutil.StripProgress(b.String()), `Applying tags... done
156160
157-
PTYPE TAG
158-
true false
161+
KEY VALUE
162+
true false
159163
`, "output")
160164
}
161165

@@ -171,8 +175,8 @@ func TestTagsUnset(t *testing.T) {
171175
testutil.SetHeaders(w)
172176
if r.Method == "POST" {
173177
testutil.AssertBody(t, api.Config{
174-
Tags: map[string]interface{}{
175-
"ncc": nil,
178+
Tags: map[string]api.ConfigTags{
179+
"web": {"ncc": nil},
176180
},
177181
}, r)
178182
}
@@ -184,7 +188,9 @@ func TestTagsUnset(t *testing.T) {
184188
"memory": {},
185189
"cpu": {},
186190
"tags": {
187-
"warp": 8
191+
"web": {
192+
"warp": 8
193+
}
188194
},
189195
"registry": {},
190196
"created": "2014-01-01T00:00:00UTC",
@@ -196,12 +202,12 @@ func TestTagsUnset(t *testing.T) {
196202
var b bytes.Buffer
197203
cmdr := DryccCmd{WOut: &b, ConfigFile: cf}
198204

199-
err = cmdr.TagsUnset("foo", []string{"ncc"})
205+
err = cmdr.TagsUnset("foo", "web", []string{"ncc"})
200206
assert.NoError(t, err)
201207

202208
assert.Equal(t, testutil.StripProgress(b.String()), `Applying tags... done
203209
204-
PTYPE TAG
205-
warp 8
210+
KEY VALUE
211+
warp 8
206212
`, "output")
207213
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/containerd/console v1.0.4
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
8-
github.com/drycc/controller-sdk-go v0.0.0-20240712012621-75bd5ebae3da
8+
github.com/drycc/controller-sdk-go v0.0.0-20240715005708-f3fdd9e41b77
99
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f
1010
github.com/olekukonko/tablewriter v0.0.5
1111
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
66
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
7-
github.com/drycc/controller-sdk-go v0.0.0-20240712012621-75bd5ebae3da h1:tNidQf7Aey4QTNC5oFHG8SAEwuXA74DZQjJYABKToVg=
8-
github.com/drycc/controller-sdk-go v0.0.0-20240712012621-75bd5ebae3da/go.mod h1:n6eQe1irJqjwLo/7t9+Dhdv6faSESQN+ATnZRBP3/Uc=
7+
github.com/drycc/controller-sdk-go v0.0.0-20240715005708-f3fdd9e41b77 h1:ETETjyAklTuimZ4itKzo8a6OkHo+fX1ueTa0zn/9h3M=
8+
github.com/drycc/controller-sdk-go v0.0.0-20240715005708-f3fdd9e41b77/go.mod h1:n6eQe1irJqjwLo/7t9+Dhdv6faSESQN+ATnZRBP3/Uc=
99
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f h1:kgjvUQJeAszDoU1Vo4vTTE92KI8Av3JPb6Qn890niXg=
1010
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f/go.mod h1:n+QxGif6ha9CEoxVnlipxb9IdmerybcUSzTEDFkvjiA=
1111
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=

parser/healthchecks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ func checkProbeType(probe string) error {
283283
"livenessProbe",
284284
"readinessProbe",
285285
}
286-
for _, ptype := range probeTypes {
287-
if probe == ptype {
286+
for _, probeType := range probeTypes {
287+
if probe == probeType {
288288
found = true
289289
}
290290
}

parser/tags.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func tagsList(argv []string, cmdr cmd.Commander) error {
4343
usage := `
4444
Lists tags for an application.
4545
46-
Usage: drycc tags:list [options]
46+
Usage: drycc tags:list <ptype> [options]
47+
48+
Arguments:
49+
<ptype>
50+
the process name as defined in your Procfile, such as 'web' or 'web worker'.
4751
4852
Options:
4953
-a --app=<app>
@@ -56,7 +60,10 @@ Options:
5660
return err
5761
}
5862

59-
return cmdr.TagsList(safeGetString(args, "--app"))
63+
ptype := safeGetString(args, "--ptype")
64+
appName := safeGetString(args, "--app")
65+
66+
return cmdr.TagsList(appName, ptype)
6067
}
6168

6269
func tagsSet(argv []string, cmdr cmd.Commander) error {
@@ -67,11 +74,15 @@ A tag is a key/value pair used to tag an application's containers and is passed
6774
scheduler. This is often used to restrict workloads to specific hosts matching the
6875
scheduler-configured metadata.
6976
70-
Usage: drycc tags:set [options] <key>=<value>...
77+
Usage: drycc tags:set <ptype> <key>=<value>... [options]
7178
7279
Arguments:
73-
<key> the tag key, for example: "environ" or "rack"
74-
<value> the tag value, for example: "prod" or "1"
80+
<ptype>
81+
the process name as defined in your Procfile, such as 'web' or 'web worker'.
82+
<key>
83+
the tag key, for example: "environ" or "rack"
84+
<value>
85+
the tag value, for example: "prod" or "1"
7586
7687
Options:
7788
-a --app=<app>
@@ -82,21 +93,24 @@ Options:
8293
if err != nil {
8394
return err
8495
}
85-
96+
ptype := safeGetString(args, "--ptype")
8697
app := safeGetString(args, "--app")
8798
tags := args["<key>=<value>"].([]string)
8899

89-
return cmdr.TagsSet(app, tags)
100+
return cmdr.TagsSet(app, ptype, tags)
90101
}
91102

92103
func tagsUnset(argv []string, cmdr cmd.Commander) error {
93104
usage := `
94105
Unsets tags for an application.
95106
96-
Usage: drycc tags:unset [options] <key>...
107+
Usage: drycc tags:unset <ptype> <key>... [options]
97108
98109
Arguments:
99-
<key> the tag key to unset, for example: "environ" or "rack"
110+
<ptype>
111+
the process name as defined in your Procfile, such as 'web' or 'web worker'.
112+
<key>
113+
the tag key to unset, for example: "environ" or "rack"
100114
101115
Options:
102116
-a --app=<app>
@@ -107,9 +121,9 @@ Options:
107121
if err != nil {
108122
return err
109123
}
110-
124+
ptype := safeGetString(args, "--ptype")
111125
app := safeGetString(args, "--app")
112126
tags := args["<key>"].([]string)
113127

114-
return cmdr.TagsUnset(app, tags)
128+
return cmdr.TagsUnset(app, ptype, tags)
115129
}

parser/tags_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import (
1212
// Create fake implementations of each method that return the argument
1313
// we expect to have called the function (as an error to satisfy the interface).
1414

15-
func (d FakeDryccCmd) TagsList(string) error {
15+
func (d FakeDryccCmd) TagsList(string, string) error {
1616
return errors.New("tags:list")
1717
}
1818

19-
func (d FakeDryccCmd) TagsSet(string, []string) error {
19+
func (d FakeDryccCmd) TagsSet(string, string, []string) error {
2020
return errors.New("tags:set")
2121
}
2222

23-
func (d FakeDryccCmd) TagsUnset(string, []string) error {
23+
func (d FakeDryccCmd) TagsUnset(string, string, []string) error {
2424
return errors.New("tags:unset")
2525
}
2626

@@ -42,19 +42,19 @@ func TestTags(t *testing.T) {
4242
expected string
4343
}{
4444
{
45-
args: []string{"tags:list"},
45+
args: []string{"tags:list", "web"},
4646
expected: "",
4747
},
4848
{
49-
args: []string{"tags:set", "environ", "prod"},
49+
args: []string{"tags:set", "web", "environ", "prod"},
5050
expected: "",
5151
},
5252
{
53-
args: []string{"tags:unset", "environ"},
53+
args: []string{"tags:unset", "web", "environ"},
5454
expected: "",
5555
},
5656
{
57-
args: []string{"tags"},
57+
args: []string{"tags", "web"},
5858
expected: "tags:list",
5959
},
6060
}

0 commit comments

Comments
 (0)