Skip to content

Commit a2189e0

Browse files
committed
Merge branch 'main' of github.com:coder/coder into spike/3279_post_license
2 parents ddb7332 + 7599ad4 commit a2189e0

File tree

82 files changed

+2375
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2375
-577
lines changed

.github/workflows/coder.yaml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
5353
sh: ${{ steps.filter.outputs.sh }}
5454
ts: ${{ steps.filter.outputs.ts }}
55+
k8s: ${{ steps.filter.outputs.k8s }}
5556
steps:
5657
- uses: actions/checkout@v3
5758
# For pull requests it's not necessary to checkout the code
@@ -69,6 +70,10 @@ jobs:
6970
- "**.sh"
7071
ts:
7172
- 'site/**'
73+
k8s:
74+
- 'helm/**'
75+
- Dockerfile
76+
- scripts/helm.sh
7277
- id: debug
7378
run: |
7479
echo "${{ toJSON(steps.filter )}}"
@@ -136,6 +141,26 @@ jobs:
136141
run: yarn lint
137142
working-directory: site
138143

144+
style-lint-k8s:
145+
name: "style/lint/k8s"
146+
timeout-minutes: 5
147+
needs: changes
148+
if: needs.changes.outputs.k8s == 'true'
149+
runs-on: ubuntu-latest
150+
steps:
151+
- name: Checkout
152+
uses: actions/checkout@v3
153+
154+
- name: Install helm
155+
uses: azure/setup-helm@v3
156+
with:
157+
version: v3.9.2
158+
159+
- name: cd helm && make lint
160+
run: |
161+
cd helm
162+
make lint
163+
139164
gen:
140165
name: "style/gen"
141166
timeout-minutes: 8
@@ -185,14 +210,21 @@ jobs:
185210
path: ${{ steps.go-cache-paths.outputs.go-mod }}
186211
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
187212

188-
- run: |
213+
- name: Install sqlc
214+
run: |
189215
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.13.0/sqlc_1.13.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
216+
- name: Install protoc-gen-go
217+
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
218+
- name: Install protoc-gen-go-drpc
219+
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
220+
- name: Install goimports
221+
run: go install golang.org/x/tools/cmd/goimports@latest
222+
223+
- name: make gen
224+
run: "make --output-sync -j -B gen"
190225

191-
- run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
192-
- run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
193-
- run: go install golang.org/x/tools/cmd/goimports@latest
194-
- run: "make --output-sync -j -B gen"
195-
- run: ./scripts/check_unstaged.sh
226+
- name: Check for unstaged files
227+
run: ./scripts/check_unstaged.sh
196228

197229
style-fmt:
198230
name: "style/fmt"
@@ -222,7 +254,8 @@ jobs:
222254
- name: Install shfmt
223255
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0
224256

225-
- run: |
257+
- name: make fmt
258+
run: |
226259
export PATH=${PATH}:$(go env GOPATH)/bin
227260
make --output-sync -j -B fmt
228261

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"Jobf",
3838
"Keygen",
3939
"kirsle",
40+
"Kubernetes",
4041
"ldflags",
4142
"manifoldco",
4243
"mapstructure",

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
6363
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
6464
coderd/database/generate.sh
6565

66-
# This target is deprecated, as GNU make has issues passing signals to subprocesses.
67-
dev:
68-
@echo Please run ./scripts/develop.sh manually.
69-
.PHONY: dev
70-
7166
fmt/prettier:
7267
@echo "--- prettier"
7368
cd site

cli/cliui/table.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
9090
sort = strings.ToLower(strings.ReplaceAll(sort, "_", " "))
9191
h, ok := headersMap[sort]
9292
if !ok {
93-
return "", xerrors.Errorf("specified sort column %q not found in table headers, available columns are %q", sort, strings.Join(headersRaw, `", "`))
93+
return "", xerrors.Errorf(`specified sort column %q not found in table headers, available columns are "%v"`, sort, strings.Join(headersRaw, `", "`))
9494
}
9595

9696
// Autocorrect
@@ -101,7 +101,7 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
101101
column := strings.ToLower(strings.ReplaceAll(column, "_", " "))
102102
h, ok := headersMap[column]
103103
if !ok {
104-
return "", xerrors.Errorf("specified filter column %q not found in table headers, available columns are %q", sort, strings.Join(headersRaw, `", "`))
104+
return "", xerrors.Errorf(`specified filter column %q not found in table headers, available columns are "%v"`, sort, strings.Join(headersRaw, `", "`))
105105
}
106106

107107
// Autocorrect
@@ -158,6 +158,10 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
158158
if val != nil {
159159
v = val.Format(time.Stamp)
160160
}
161+
case fmt.Stringer:
162+
if val != nil {
163+
v = val.String()
164+
}
161165
}
162166

163167
rowSlice[i] = v
@@ -301,19 +305,3 @@ func valueToTableMap(val reflect.Value) (map[string]any, error) {
301305

302306
return row, nil
303307
}
304-
305-
func ValidateColumns(all, given []string) error {
306-
for _, col := range given {
307-
found := false
308-
for _, c := range all {
309-
if strings.EqualFold(strings.ReplaceAll(col, "_", " "), c) {
310-
found = true
311-
break
312-
}
313-
}
314-
if !found {
315-
return fmt.Errorf("unknown column: %s", col)
316-
}
317-
}
318-
return nil
319-
}

cli/cliui/table_test.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cliui_test
22

33
import (
4+
"fmt"
45
"log"
56
"strings"
67
"testing"
@@ -12,6 +13,16 @@ import (
1213
"github.com/coder/coder/cli/cliui"
1314
)
1415

16+
type stringWrapper struct {
17+
str string
18+
}
19+
20+
var _ fmt.Stringer = stringWrapper{}
21+
22+
func (s stringWrapper) String() string {
23+
return s.str
24+
}
25+
1526
type tableTest1 struct {
1627
Name string `table:"name"`
1728
NotIncluded string // no table tag
@@ -28,9 +39,9 @@ type tableTest1 struct {
2839
}
2940

3041
type tableTest2 struct {
31-
Name string `table:"name"`
32-
Age int `table:"age"`
33-
NotIncluded string `table:"-"`
42+
Name stringWrapper `table:"name"`
43+
Age int `table:"age"`
44+
NotIncluded string `table:"-"`
3445
}
3546

3647
type tableTest3 struct {
@@ -48,21 +59,21 @@ func Test_DisplayTable(t *testing.T) {
4859
Age: 10,
4960
Roles: []string{"a", "b", "c"},
5061
Sub1: tableTest2{
51-
Name: "foo1",
62+
Name: stringWrapper{str: "foo1"},
5263
Age: 11,
5364
},
5465
Sub2: &tableTest2{
55-
Name: "foo2",
66+
Name: stringWrapper{str: "foo2"},
5667
Age: 12,
5768
},
5869
Sub3: tableTest3{
5970
Sub: tableTest2{
60-
Name: "foo3",
71+
Name: stringWrapper{str: "foo3"},
6172
Age: 13,
6273
},
6374
},
6475
Sub4: tableTest2{
65-
Name: "foo4",
76+
Name: stringWrapper{str: "foo4"},
6677
Age: 14,
6778
},
6879
Time: someTime,
@@ -73,18 +84,18 @@ func Test_DisplayTable(t *testing.T) {
7384
Age: 20,
7485
Roles: []string{"a"},
7586
Sub1: tableTest2{
76-
Name: "bar1",
87+
Name: stringWrapper{str: "bar1"},
7788
Age: 21,
7889
},
7990
Sub2: nil,
8091
Sub3: tableTest3{
8192
Sub: tableTest2{
82-
Name: "bar3",
93+
Name: stringWrapper{str: "bar3"},
8394
Age: 23,
8495
},
8596
},
8697
Sub4: tableTest2{
87-
Name: "bar4",
98+
Name: stringWrapper{str: "bar4"},
8899
Age: 24,
89100
},
90101
Time: someTime,
@@ -95,18 +106,18 @@ func Test_DisplayTable(t *testing.T) {
95106
Age: 30,
96107
Roles: nil,
97108
Sub1: tableTest2{
98-
Name: "baz1",
109+
Name: stringWrapper{str: "baz1"},
99110
Age: 31,
100111
},
101112
Sub2: nil,
102113
Sub3: tableTest3{
103114
Sub: tableTest2{
104-
Name: "baz3",
115+
Name: stringWrapper{str: "baz3"},
105116
Age: 33,
106117
},
107118
},
108119
Sub4: tableTest2{
109-
Name: "baz4",
120+
Name: stringWrapper{str: "baz4"},
110121
Age: 34,
111122
},
112123
Time: someTime,

cli/features.go

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"strings"
77

8-
"github.com/jedib0t/go-pretty/v6/table"
98
"github.com/spf13/cobra"
109
"golang.org/x/xerrors"
1110

@@ -37,10 +36,6 @@ func featuresList() *cobra.Command {
3736
Use: "list",
3837
Aliases: []string{"ls"},
3938
RunE: func(cmd *cobra.Command, args []string) error {
40-
err := cliui.ValidateColumns(featureColumns, columns)
41-
if err != nil {
42-
return err
43-
}
4439
client, err := createClient(cmd)
4540
if err != nil {
4641
return err
@@ -53,11 +48,14 @@ func featuresList() *cobra.Command {
5348
out := ""
5449
switch outputFormat {
5550
case "table", "":
56-
out = displayFeatures(columns, entitlements.Features)
51+
out, err = displayFeatures(columns, entitlements.Features)
52+
if err != nil {
53+
return xerrors.Errorf("render table: %w", err)
54+
}
5755
case "json":
5856
outBytes, err := json.Marshal(entitlements)
5957
if err != nil {
60-
return xerrors.Errorf("marshal users to JSON: %w", err)
58+
return xerrors.Errorf("marshal features to JSON: %w", err)
6159
}
6260

6361
out = string(outBytes)
@@ -77,35 +75,28 @@ func featuresList() *cobra.Command {
7775
return cmd
7876
}
7977

78+
type featureRow struct {
79+
Name string `table:"name"`
80+
Entitlement string `table:"entitlement"`
81+
Enabled bool `table:"enabled"`
82+
Limit *int64 `table:"limit"`
83+
Actual *int64 `table:"actual"`
84+
}
85+
8086
// displayFeatures will return a table displaying all features passed in.
8187
// filterColumns must be a subset of the feature fields and will determine which
8288
// columns to display
83-
func displayFeatures(filterColumns []string, features map[string]codersdk.Feature) string {
84-
tableWriter := cliui.Table()
85-
header := table.Row{}
86-
for _, h := range featureColumns {
87-
header = append(header, h)
88-
}
89-
tableWriter.AppendHeader(header)
90-
tableWriter.SetColumnConfigs(cliui.FilterTableColumns(header, filterColumns))
91-
tableWriter.SortBy([]table.SortBy{{
92-
Name: "username",
93-
}})
89+
func displayFeatures(filterColumns []string, features map[string]codersdk.Feature) (string, error) {
90+
rows := make([]featureRow, 0, len(features))
9491
for name, feat := range features {
95-
tableWriter.AppendRow(table.Row{
96-
name,
97-
feat.Entitlement,
98-
feat.Enabled,
99-
intOrNil(feat.Limit),
100-
intOrNil(feat.Actual),
92+
rows = append(rows, featureRow{
93+
Name: name,
94+
Entitlement: string(feat.Entitlement),
95+
Enabled: feat.Enabled,
96+
Limit: feat.Limit,
97+
Actual: feat.Actual,
10198
})
10299
}
103-
return tableWriter.Render()
104-
}
105100

106-
func intOrNil(i *int64) string {
107-
if i == nil {
108-
return ""
109-
}
110-
return fmt.Sprintf("%d", *i)
101+
return cliui.DisplayTable(rows, "name", filterColumns)
111102
}

0 commit comments

Comments
 (0)