Skip to content

Commit 2cd4069

Browse files
committed
Merge remote-tracking branch 'origin/main' into cj/populate-provisionerdaemons
2 parents d50cfaf + eb78175 commit 2cd4069

File tree

90 files changed

+1777
-1463
lines changed

Some content is hidden

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

90 files changed

+1777
-1463
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ jobs:
775775
uses: fluxcd/flux2/action@main
776776
with:
777777
# Keep this up to date with the version of flux installed in dogfood cluster
778-
version: "2.2.0"
778+
version: "2.2.1"
779779

780780
- name: Get Cluster Credentials
781781
uses: "google-github-actions/get-gke-credentials@v2"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ docs/cli.md: scripts/clidocgen/main.go examples/examples.gen.json $(GO_SRC_FILES
588588
CI=true BASE_PATH="." go run ./scripts/clidocgen
589589
pnpm run format:write:only ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json
590590

591-
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
591+
docs/admin/audit-logs.md: coderd/database/querier.go scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
592592
go run scripts/auditdocgen/main.go
593593
pnpm run format:write:only ./docs/admin/audit-logs.md
594594

cli/rename_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func TestRename(t *testing.T) {
1616
t.Parallel()
1717

18-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
18+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true, AllowWorkspaceRenames: true})
1919
owner := coderdtest.CreateFirstUser(t, client)
2020
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
2121
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)

cli/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
583583
HostnamePrefix: vals.SSHConfig.DeploymentName.String(),
584584
SSHConfigOptions: configSSHOptions,
585585
},
586+
AllowWorkspaceRenames: vals.AllowWorkspaceRenames.Value(),
586587
}
587588
if httpServers.TLSConfig != nil {
588589
options.TLSCertificates = httpServers.TLSConfig.Certificates

cli/templatecreate.go

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8-
"os"
9-
"path/filepath"
108
"strings"
119
"time"
1210
"unicode/utf8"
@@ -27,7 +25,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
2725
provisioner string
2826
provisionerTags []string
2927
variablesFile string
30-
variables []string
28+
commandLineVariables []string
3129
disableEveryone bool
3230
requireActiveVersion bool
3331

@@ -129,15 +127,21 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
129127
return err
130128
}
131129

130+
userVariableValues, err := ParseUserVariableValues(
131+
variablesFile,
132+
commandLineVariables)
133+
if err != nil {
134+
return err
135+
}
136+
132137
job, err := createValidTemplateVersion(inv, createValidTemplateVersionArgs{
133-
Message: message,
134-
Client: client,
135-
Organization: organization,
136-
Provisioner: codersdk.ProvisionerType(provisioner),
137-
FileID: resp.ID,
138-
ProvisionerTags: tags,
139-
VariablesFile: variablesFile,
140-
Variables: variables,
138+
Message: message,
139+
Client: client,
140+
Organization: organization,
141+
Provisioner: codersdk.ProvisionerType(provisioner),
142+
FileID: resp.ID,
143+
ProvisionerTags: tags,
144+
UserVariableValues: userVariableValues,
141145
})
142146
if err != nil {
143147
return err
@@ -197,12 +201,12 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
197201
{
198202
Flag: "variable",
199203
Description: "Specify a set of values for Terraform-managed variables.",
200-
Value: clibase.StringArrayOf(&variables),
204+
Value: clibase.StringArrayOf(&commandLineVariables),
201205
},
202206
{
203207
Flag: "var",
204208
Description: "Alias of --variable.",
205-
Value: clibase.StringArrayOf(&variables),
209+
Value: clibase.StringArrayOf(&commandLineVariables),
206210
},
207211
{
208212
Flag: "provisioner-tag",
@@ -267,40 +271,27 @@ type createValidTemplateVersionArgs struct {
267271
Provisioner codersdk.ProvisionerType
268272
FileID uuid.UUID
269273

270-
VariablesFile string
271-
Variables []string
272-
273274
// Template is only required if updating a template's active version.
274275
Template *codersdk.Template
275276
// ReuseParameters will attempt to reuse params from the Template field
276277
// before prompting the user. Set to false to always prompt for param
277278
// values.
278-
ReuseParameters bool
279-
ProvisionerTags map[string]string
279+
ReuseParameters bool
280+
ProvisionerTags map[string]string
281+
UserVariableValues []codersdk.VariableValue
280282
}
281283

282284
func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplateVersionArgs) (*codersdk.TemplateVersion, error) {
283285
client := args.Client
284286

285-
variableValues, err := loadVariableValuesFromFile(args.VariablesFile)
286-
if err != nil {
287-
return nil, err
288-
}
289-
290-
variableValuesFromKeyValues, err := loadVariableValuesFromOptions(args.Variables)
291-
if err != nil {
292-
return nil, err
293-
}
294-
variableValues = append(variableValues, variableValuesFromKeyValues...)
295-
296287
req := codersdk.CreateTemplateVersionRequest{
297288
Name: args.Name,
298289
Message: args.Message,
299290
StorageMethod: codersdk.ProvisionerStorageMethodFile,
300291
FileID: args.FileID,
301292
Provisioner: args.Provisioner,
302293
ProvisionerTags: args.ProvisionerTags,
303-
UserVariableValues: variableValues,
294+
UserVariableValues: args.UserVariableValues,
304295
}
305296
if args.Template != nil {
306297
req.TemplateID = args.Template.ID
@@ -364,23 +355,6 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
364355
return &version, nil
365356
}
366357

367-
// prettyDirectoryPath returns a prettified path when inside the users
368-
// home directory. Falls back to dir if the users home directory cannot
369-
// discerned. This function calls filepath.Clean on the result.
370-
func prettyDirectoryPath(dir string) string {
371-
dir = filepath.Clean(dir)
372-
homeDir, err := os.UserHomeDir()
373-
if err != nil {
374-
return dir
375-
}
376-
prettyDir := dir
377-
if strings.HasPrefix(prettyDir, homeDir) {
378-
prettyDir = strings.TrimPrefix(prettyDir, homeDir)
379-
prettyDir = "~" + prettyDir
380-
}
381-
return prettyDir
382-
}
383-
384358
func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
385359
tags := map[string]string{}
386360
for _, rawTag := range rawTags {

cli/templatepush.go

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"io"
7+
"os"
78
"path/filepath"
89
"strings"
910
"time"
@@ -78,7 +79,7 @@ func (pf *templateUploadFlags) upload(inv *clibase.Invocation, client *codersdk.
7879

7980
pipeReader, pipeWriter := io.Pipe()
8081
go func() {
81-
err := provisionersdk.Tar(pipeWriter, pf.directory, provisionersdk.TemplateArchiveLimit)
82+
err := provisionersdk.Tar(pipeWriter, inv.Logger, pf.directory, provisionersdk.TemplateArchiveLimit)
8283
_ = pipeWriter.CloseWithError(err)
8384
}()
8485
defer pipeReader.Close()
@@ -155,16 +156,16 @@ func (pf *templateUploadFlags) templateName(args []string) (string, error) {
155156

156157
func (r *RootCmd) templatePush() *clibase.Cmd {
157158
var (
158-
versionName string
159-
provisioner string
160-
workdir string
161-
variablesFile string
162-
variables []string
163-
alwaysPrompt bool
164-
provisionerTags []string
165-
uploadFlags templateUploadFlags
166-
activate bool
167-
create bool
159+
versionName string
160+
provisioner string
161+
workdir string
162+
variablesFile string
163+
commandLineVariables []string
164+
alwaysPrompt bool
165+
provisionerTags []string
166+
uploadFlags templateUploadFlags
167+
activate bool
168+
create bool
168169
)
169170
client := new(codersdk.Client)
170171
cmd := &clibase.Cmd{
@@ -213,15 +214,21 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
213214
return err
214215
}
215216

217+
userVariableValues, err := ParseUserVariableValues(
218+
variablesFile,
219+
commandLineVariables)
220+
if err != nil {
221+
return err
222+
}
223+
216224
args := createValidTemplateVersionArgs{
217-
Message: message,
218-
Client: client,
219-
Organization: organization,
220-
Provisioner: codersdk.ProvisionerType(provisioner),
221-
FileID: resp.ID,
222-
ProvisionerTags: tags,
223-
VariablesFile: variablesFile,
224-
Variables: variables,
225+
Message: message,
226+
Client: client,
227+
Organization: organization,
228+
Provisioner: codersdk.ProvisionerType(provisioner),
229+
FileID: resp.ID,
230+
ProvisionerTags: tags,
231+
UserVariableValues: userVariableValues,
225232
}
226233

227234
if !createTemplate {
@@ -291,12 +298,12 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
291298
{
292299
Flag: "variable",
293300
Description: "Specify a set of values for Terraform-managed variables.",
294-
Value: clibase.StringArrayOf(&variables),
301+
Value: clibase.StringArrayOf(&commandLineVariables),
295302
},
296303
{
297304
Flag: "var",
298305
Description: "Alias of --variable.",
299-
Value: clibase.StringArrayOf(&variables),
306+
Value: clibase.StringArrayOf(&commandLineVariables),
300307
},
301308
{
302309
Flag: "provisioner-tag",
@@ -330,3 +337,20 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
330337
cmd.Options = append(cmd.Options, uploadFlags.options()...)
331338
return cmd
332339
}
340+
341+
// prettyDirectoryPath returns a prettified path when inside the users
342+
// home directory. Falls back to dir if the users home directory cannot
343+
// discerned. This function calls filepath.Clean on the result.
344+
func prettyDirectoryPath(dir string) string {
345+
dir = filepath.Clean(dir)
346+
homeDir, err := os.UserHomeDir()
347+
if err != nil {
348+
return dir
349+
}
350+
prettyDir := dir
351+
if strings.HasPrefix(prettyDir, homeDir) {
352+
prettyDir = strings.TrimPrefix(prettyDir, homeDir)
353+
prettyDir = "~" + prettyDir
354+
}
355+
return prettyDir
356+
}

cli/templatevariables.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ import (
1010
"github.com/coder/coder/v2/codersdk"
1111
)
1212

13-
func loadVariableValuesFromFile(variablesFile string) ([]codersdk.VariableValue, error) {
13+
func ParseUserVariableValues(variablesFile string, commandLineVariables []string) ([]codersdk.VariableValue, error) {
14+
fromFile, err := parseVariableValuesFromFile(variablesFile)
15+
if err != nil {
16+
return nil, err
17+
}
18+
19+
fromCommandLine, err := parseVariableValuesFromCommandLine(commandLineVariables)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
return combineVariableValues(fromFile, fromCommandLine), nil
25+
}
26+
27+
func parseVariableValuesFromFile(variablesFile string) ([]codersdk.VariableValue, error) {
1428
var values []codersdk.VariableValue
1529
if variablesFile == "" {
1630
return values, nil
@@ -50,7 +64,7 @@ func createVariablesMapFromFile(variablesFile string) (map[string]string, error)
5064
return variablesMap, nil
5165
}
5266

53-
func loadVariableValuesFromOptions(variables []string) ([]codersdk.VariableValue, error) {
67+
func parseVariableValuesFromCommandLine(variables []string) ([]codersdk.VariableValue, error) {
5468
var values []codersdk.VariableValue
5569
for _, keyValue := range variables {
5670
split := strings.SplitN(keyValue, "=", 2)
@@ -65,3 +79,20 @@ func loadVariableValuesFromOptions(variables []string) ([]codersdk.VariableValue
6579
}
6680
return values, nil
6781
}
82+
83+
func combineVariableValues(valuesSets ...[]codersdk.VariableValue) []codersdk.VariableValue {
84+
combinedValues := make(map[string]string)
85+
86+
for _, values := range valuesSets {
87+
for _, v := range values {
88+
combinedValues[v.Name] = v.Value
89+
}
90+
}
91+
92+
var result []codersdk.VariableValue
93+
for name, value := range combinedValues {
94+
result = append(result, codersdk.VariableValue{Name: name, Value: value})
95+
}
96+
97+
return result
98+
}

cli/testdata/coder_list_--output_json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"healthy": true,
6161
"failing_agents": []
6262
},
63-
"automatic_updates": "never"
63+
"automatic_updates": "never",
64+
"allow_renames": false
6465
}
6566
]

cli/testdata/coder_server_--help.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ SUBCOMMANDS:
1414
PostgreSQL deployment.
1515

1616
OPTIONS:
17+
--allow-workspace-renames bool, $CODER_ALLOW_WORKSPACE_RENAMES (default: false)
18+
DEPRECATED: Allow users to rename their workspaces. Use only for
19+
temporary compatibility reasons, this will be removed in a future
20+
release.
21+
1722
--cache-dir string, $CODER_CACHE_DIRECTORY (default: [cache dir])
1823
The directory to cache temporary files. If unspecified and
1924
$CACHE_DIRECTORY is set, it will be used for compatibility with

cli/testdata/coder_templates_init_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Get started with a templated template.
77

88
OPTIONS:
9-
--id aws-ecs-container|aws-linux|aws-windows|azure-linux|do-linux|docker|docker-with-dotfiles|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker
9+
--id aws-linux|aws-windows|azure-linux|do-linux|docker|gcp-linux|gcp-vm-container|gcp-windows|kubernetes|nomad-docker
1010
Specify a given example template by ID.
1111

1212
———

0 commit comments

Comments
 (0)