Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f113c8

Browse files
committed
fix(cli): allow specifying empty provisioner tag set with --provisioner-tag="-"
1 parent4a2b243 commit9f113c8

File tree

4 files changed

+117
-19
lines changed

4 files changed

+117
-19
lines changed

‎cli/templatepush.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"path/filepath"
11+
"slices"
1112
"strings"
1213
"time"
1314

@@ -80,6 +81,46 @@ func (r *RootCmd) templatePush() *serpent.Command {
8081
createTemplate=true
8182
}
8283

84+
vartagsmap[string]string
85+
// Passing --provisioner-tag="-" allows the user to clear all provisioner tags.
86+
iflen(provisionerTags)==1&&strings.TrimSpace(provisionerTags[0])=="-" {
87+
cliui.Warn(inv.Stderr,"Not reusing provisioner tags from the previous template version.")
88+
tags=map[string]string{}
89+
}else {
90+
tags,err=ParseProvisionerTags(provisionerTags)
91+
iferr!=nil {
92+
returnerr
93+
}
94+
95+
// If user hasn't provided new provisioner tags, inherit ones from the active template version.
96+
iflen(tags)==0&&template.ActiveVersionID!=uuid.Nil {
97+
templateVersion,err:=client.TemplateVersion(inv.Context(),template.ActiveVersionID)
98+
iferr!=nil {
99+
returnerr
100+
}
101+
tags=templateVersion.Job.Tags
102+
cliui.Info(inv.Stderr,"Re-using provisioner tags from the active template version.")
103+
cliui.Info(inv.Stderr,"Tip: You can override these tags by passing "+cliui.Code(`--provisioner-tag="key=value"`)+".")
104+
cliui.Info(inv.Stderr," You can also clear all provisioner tags by passing "+cliui.Code(`--provisioner-tag="-"`)+".")
105+
}
106+
}
107+
108+
{// For clarity, display provisioner tags to the user.
109+
vartmp []string
110+
fork,v:=rangetags {
111+
ifk==provisionersdk.TagScope||k==provisionersdk.TagOwner {
112+
continue
113+
}
114+
tmp=append(tmp,fmt.Sprintf("%s=%q",k,v))
115+
}
116+
slices.Sort(tmp)
117+
tagStr:=strings.Join(tmp," ")
118+
iflen(tmp)==0 {
119+
tagStr="<none>"
120+
}
121+
cliui.Info(inv.Stderr,"Provisioner tags: "+cliui.Code(tagStr))
122+
}
123+
83124
err=uploadFlags.checkForLockfile(inv)
84125
iferr!=nil {
85126
returnxerrors.Errorf("check for lockfile: %w",err)
@@ -104,21 +145,6 @@ func (r *RootCmd) templatePush() *serpent.Command {
104145
returnerr
105146
}
106147

107-
tags,err:=ParseProvisionerTags(provisionerTags)
108-
iferr!=nil {
109-
returnerr
110-
}
111-
112-
// If user hasn't provided new provisioner tags, inherit ones from the active template version.
113-
iflen(tags)==0&&template.ActiveVersionID!=uuid.Nil {
114-
templateVersion,err:=client.TemplateVersion(inv.Context(),template.ActiveVersionID)
115-
iferr!=nil {
116-
returnerr
117-
}
118-
tags=templateVersion.Job.Tags
119-
inv.Logger.Info(inv.Context(),"reusing existing provisioner tags","tags",tags)
120-
}
121-
122148
userVariableValues,err:=codersdk.ParseUserVariableValues(
123149
varsFiles,
124150
variablesFile,
@@ -214,7 +240,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
214240
},
215241
{
216242
Flag:"provisioner-tag",
217-
Description:"Specify a set of tags to target provisioner daemons.",
243+
Description:"Specify a set of tags to target provisioner daemons. If you do not specify any tags, the tags from the active template version will be reused, if available. To override this behavior, use --provisioner-tag=\"-\".",
218244
Value:serpent.StringArrayOf(&provisionerTags),
219245
},
220246
{

‎cli/templatepush_test.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func TestTemplatePush(t *testing.T) {
602602
templateVersion=coderdtest.AwaitTemplateVersionJobCompleted(t,client,templateVersion.ID)
603603
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,templateVersion.ID)
604604

605-
// Push new template versionwithoutprovisioner tags. CLI should reuse tags from the previous version.
605+
// Push new template versionwith differentprovisioner tags.
606606
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
607607
Parse:echo.ParseComplete,
608608
ProvisionApply:echo.ApplyComplete,
@@ -639,6 +639,75 @@ func TestTemplatePush(t *testing.T) {
639639
require.EqualValues(t,map[string]string{"foobar":"foobaz","owner":"","scope":"organization"},templateVersion.Job.Tags)
640640
})
641641

642+
t.Run("DeleteTags",func(t*testing.T) {
643+
t.Parallel()
644+
645+
ctx:=testutil.Context(t,testutil.WaitLong)
646+
647+
// Start the first provisioner with no tags.
648+
client,provisionerDocker,api:=coderdtest.NewWithAPI(t,&coderdtest.Options{
649+
IncludeProvisionerDaemon:true,
650+
ProvisionerDaemonTags:map[string]string{},
651+
})
652+
deferprovisionerDocker.Close()
653+
654+
// Start the second provisioner with a tag set.
655+
provisionerFoobar:=coderdtest.NewTaggedProvisionerDaemon(t,api,"provisioner-foobar",map[string]string{
656+
"foobar":"foobaz",
657+
})
658+
deferprovisionerFoobar.Close()
659+
660+
owner:=coderdtest.CreateFirstUser(t,client)
661+
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
662+
663+
// Create the template with initial tagged template version.
664+
templateVersion:=coderdtest.CreateTemplateVersion(t,client,owner.OrganizationID,nil,func(ctvr*codersdk.CreateTemplateVersionRequest) {
665+
ctvr.ProvisionerTags=map[string]string{
666+
"foobar":"foobaz",
667+
}
668+
})
669+
templateVersion=coderdtest.AwaitTemplateVersionJobCompleted(t,client,templateVersion.ID)
670+
template:=coderdtest.CreateTemplate(t,client,owner.OrganizationID,templateVersion.ID)
671+
672+
// Stop the tagged provisioner daemon.
673+
provisionerFoobar.Close()
674+
675+
// Push new template version with no provisioner tags.
676+
source:=clitest.CreateTemplateVersionSource(t,&echo.Responses{
677+
Parse:echo.ParseComplete,
678+
ProvisionApply:echo.ApplyComplete,
679+
})
680+
inv,root:=clitest.New(t,"templates","push",template.Name,"--directory",source,"--test.provisioner",string(database.ProvisionerTypeEcho),"--name",template.Name,"--provisioner-tag=\"-\"")
681+
clitest.SetupConfig(t,templateAdmin,root)
682+
pty:=ptytest.New(t).Attach(inv)
683+
684+
execDone:=make(chanerror)
685+
gofunc() {
686+
execDone<-inv.WithContext(ctx).Run()
687+
}()
688+
689+
matches:= []struct {
690+
matchstring
691+
writestring
692+
}{
693+
{match:"Upload",write:"yes"},
694+
}
695+
for_,m:=rangematches {
696+
pty.ExpectMatch(m.match)
697+
pty.WriteLine(m.write)
698+
}
699+
700+
require.NoError(t,<-execDone)
701+
702+
// Verify template version tags
703+
template,err:=client.Template(ctx,template.ID)
704+
require.NoError(t,err)
705+
706+
templateVersion,err=client.TemplateVersion(ctx,template.ActiveVersionID)
707+
require.NoError(t,err)
708+
require.EqualValues(t,map[string]string{"owner":"","scope":"organization"},templateVersion.Job.Tags)
709+
})
710+
642711
t.Run("DoNotChangeTags",func(t*testing.T) {
643712
t.Parallel()
644713

‎cli/testdata/coder_templates_push_--help.golden

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ OPTIONS:
3333
generated if not provided.
3434

3535
--provisioner-tag string-array
36-
Specify a set of tags to target provisioner daemons.
36+
Specify a set of tags to target provisioner daemons. If you do not
37+
specify any tags, the tags from the active template version will be
38+
reused, if available. To override this behavior, use
39+
--provisioner-tag="-".
3740

3841
--var string-array
3942
Alias of --variable.

‎docs/reference/cli/templates_push.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp