Skip to content

Commit 4e43b7a

Browse files
authored
Add --allow-no-pollers flag to set-current-version and set-ramping-version (#860)
<!--- Note to EXTERNAL Contributors --> <!-- Thanks for opening a PR! If it is a significant code change, please **make sure there is an open issue** for this. We work best with you when we have accepted the idea first before you code. --> <!--- For ALL Contributors 👇 --> ## What was changed Add --allow-no-pollers flag to set-current-version and set-ramping-version ## Why? So that users can make a version current / ramping before it has pollers. ## Checklist <!--- add/delete as needed ---> 1. Closes <!-- add issue number here --> 2. How was this tested: Added tests 3. Any docs updates needed? <!--- update README if applicable or point out where to update docs.temporal.io -->
1 parent 9999fb4 commit 4e43b7a

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

temporalcli/commands.gen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,6 +3121,7 @@ type TemporalWorkerDeploymentSetCurrentVersionCommand struct {
31213121
Command cobra.Command
31223122
DeploymentVersionOrUnversionedOptions
31233123
IgnoreMissingTaskQueues bool
3124+
AllowNoPollers bool
31243125
Yes bool
31253126
}
31263127

@@ -3137,6 +3138,7 @@ func NewTemporalWorkerDeploymentSetCurrentVersionCommand(cctx *CommandContext, p
31373138
}
31383139
s.Command.Args = cobra.NoArgs
31393140
s.Command.Flags().BoolVar(&s.IgnoreMissingTaskQueues, "ignore-missing-task-queues", false, "Override protection to accidentally remove task queues.")
3141+
s.Command.Flags().BoolVar(&s.AllowNoPollers, "allow-no-pollers", false, "Override protection and set version as current even if it has no pollers.")
31403142
s.Command.Flags().BoolVarP(&s.Yes, "yes", "y", false, "Don't prompt to confirm set Current Version.")
31413143
s.DeploymentVersionOrUnversionedOptions.buildFlags(cctx, s.Command.Flags())
31423144
s.Command.Run = func(c *cobra.Command, args []string) {
@@ -3154,6 +3156,7 @@ type TemporalWorkerDeploymentSetRampingVersionCommand struct {
31543156
Percentage float32
31553157
Delete bool
31563158
IgnoreMissingTaskQueues bool
3159+
AllowNoPollers bool
31573160
Yes bool
31583161
}
31593162

@@ -3172,6 +3175,7 @@ func NewTemporalWorkerDeploymentSetRampingVersionCommand(cctx *CommandContext, p
31723175
s.Command.Flags().Float32Var(&s.Percentage, "percentage", 0, "Percentage of tasks redirected to the Ramping Version. Valid range [0,100].")
31733176
s.Command.Flags().BoolVar(&s.Delete, "delete", false, "Delete the Ramping Version.")
31743177
s.Command.Flags().BoolVar(&s.IgnoreMissingTaskQueues, "ignore-missing-task-queues", false, "Override protection to accidentally remove task queues.")
3178+
s.Command.Flags().BoolVar(&s.AllowNoPollers, "allow-no-pollers", false, "Override protection and set version as ramping even if it has no pollers.")
31753179
s.Command.Flags().BoolVarP(&s.Yes, "yes", "y", false, "Don't prompt to confirm set Ramping Version.")
31763180
s.DeploymentVersionOrUnversionedOptions.buildFlags(cctx, s.Command.Flags())
31773181
s.Command.Run = func(c *cobra.Command, args []string) {

temporalcli/commands.worker.deployment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package temporalcli
22

33
import (
4+
"errors"
45
"fmt"
56
"time"
67

78
"github.com/fatih/color"
89
"github.com/temporalio/cli/temporalcli/internal/printer"
910
"go.temporal.io/api/common/v1"
11+
"go.temporal.io/api/serviceerror"
1012
"go.temporal.io/sdk/client"
1113
"go.temporal.io/sdk/worker"
1214
)
@@ -619,7 +621,7 @@ func (c *TemporalWorkerDeploymentSetCurrentVersionCommand) run(cctx *CommandCont
619621
safeModeMessage: "Current",
620622
deploymentName: c.DeploymentName,
621623
})
622-
if err != nil {
624+
if err != nil && !(errors.As(err, new(*serviceerror.NotFound)) && c.AllowNoPollers) {
623625
return err
624626
}
625627

@@ -628,6 +630,7 @@ func (c *TemporalWorkerDeploymentSetCurrentVersionCommand) run(cctx *CommandCont
628630
BuildID: c.BuildId,
629631
Identity: c.Parent.Parent.Identity,
630632
IgnoreMissingTaskQueues: c.IgnoreMissingTaskQueues,
633+
AllowNoPollers: c.AllowNoPollers,
631634
ConflictToken: token,
632635
})
633636
if err != nil {
@@ -650,7 +653,7 @@ func (c *TemporalWorkerDeploymentSetRampingVersionCommand) run(cctx *CommandCont
650653
safeModeMessage: "Ramping",
651654
deploymentName: c.DeploymentName,
652655
})
653-
if err != nil {
656+
if err != nil && !(errors.As(err, new(*serviceerror.NotFound)) && c.AllowNoPollers) {
654657
return err
655658
}
656659

@@ -666,6 +669,7 @@ func (c *TemporalWorkerDeploymentSetRampingVersionCommand) run(cctx *CommandCont
666669
ConflictToken: token,
667670
Identity: c.Parent.Parent.Identity,
668671
IgnoreMissingTaskQueues: c.IgnoreMissingTaskQueues,
672+
AllowNoPollers: c.AllowNoPollers,
669673
})
670674
if err != nil {
671675
return fmt.Errorf("error setting the ramping worker deployment version: %w", err)

temporalcli/commands.worker.deployment_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,133 @@ func (s *SharedServerSuite) TestDeployment_Set_Current_Version() {
173173
s.Nil(jsonVersionOut.Metadata)
174174
}
175175

176+
func (s *SharedServerSuite) TestDeployment_Set_Current_Version_AllowNoPollers() {
177+
deploymentName := uuid.NewString()
178+
buildId := uuid.NewString()
179+
version := worker.WorkerDeploymentVersion{
180+
DeploymentName: deploymentName,
181+
BuildID: buildId,
182+
}
183+
184+
// with --allow-no-pollers, no need to have a worker polling on this version
185+
res := s.Execute(
186+
"worker", "deployment", "set-current-version",
187+
"--address", s.Address(),
188+
"--deployment-name", version.DeploymentName, "--build-id", version.BuildID,
189+
"--allow-no-pollers",
190+
"--yes",
191+
)
192+
s.NoError(res.Err)
193+
194+
s.EventuallyWithT(func(t *assert.CollectT) {
195+
res := s.Execute(
196+
"worker", "deployment", "list",
197+
"--address", s.Address(),
198+
)
199+
assert.NoError(t, res.Err)
200+
assert.Contains(t, res.Stdout.String(), deploymentName)
201+
}, 30*time.Second, 100*time.Millisecond)
202+
203+
s.EventuallyWithT(func(t *assert.CollectT) {
204+
res := s.Execute(
205+
"worker", "deployment", "describe-version",
206+
"--address", s.Address(),
207+
"--deployment-name", version.DeploymentName, "--build-id", version.BuildID,
208+
)
209+
assert.NoError(t, res.Err)
210+
}, 30*time.Second, 100*time.Millisecond)
211+
212+
res = s.Execute(
213+
"worker", "deployment", "describe",
214+
"--address", s.Address(),
215+
"--name", deploymentName,
216+
)
217+
s.NoError(res.Err)
218+
219+
s.ContainsOnSameLine(res.Stdout.String(), "Name", deploymentName)
220+
s.ContainsOnSameLine(res.Stdout.String(), "CurrentVersionDeploymentName", version.DeploymentName)
221+
s.ContainsOnSameLine(res.Stdout.String(), "CurrentVersionBuildID", version.BuildID)
222+
223+
// json
224+
res = s.Execute(
225+
"worker", "deployment", "describe",
226+
"--address", s.Address(),
227+
"--name", deploymentName,
228+
"--output", "json",
229+
)
230+
s.NoError(res.Err)
231+
232+
var jsonOut jsonDeploymentInfoType
233+
s.NoError(json.Unmarshal(res.Stdout.Bytes(), &jsonOut))
234+
s.Equal(deploymentName, jsonOut.Name)
235+
s.Equal(version.DeploymentName, jsonOut.RoutingConfig.CurrentVersionDeploymentName)
236+
s.Equal(version.BuildID, jsonOut.RoutingConfig.CurrentVersionBuildID)
237+
}
238+
239+
func (s *SharedServerSuite) TestDeployment_Set_Ramping_Version_AllowNoPollers() {
240+
deploymentName := uuid.NewString()
241+
buildId := uuid.NewString()
242+
version := worker.WorkerDeploymentVersion{
243+
DeploymentName: deploymentName,
244+
BuildID: buildId,
245+
}
246+
247+
// with --allow-no-pollers, no need to have a worker polling on this version
248+
res := s.Execute(
249+
"worker", "deployment", "set-ramping-version",
250+
"--address", s.Address(),
251+
"--deployment-name", version.DeploymentName, "--build-id", version.BuildID,
252+
"--percentage", "5",
253+
"--allow-no-pollers",
254+
"--yes",
255+
)
256+
s.NoError(res.Err)
257+
258+
s.EventuallyWithT(func(t *assert.CollectT) {
259+
res := s.Execute(
260+
"worker", "deployment", "list",
261+
"--address", s.Address(),
262+
)
263+
assert.NoError(t, res.Err)
264+
assert.Contains(t, res.Stdout.String(), deploymentName)
265+
}, 30*time.Second, 100*time.Millisecond)
266+
267+
s.EventuallyWithT(func(t *assert.CollectT) {
268+
res := s.Execute(
269+
"worker", "deployment", "describe-version",
270+
"--address", s.Address(),
271+
"--deployment-name", version.DeploymentName, "--build-id", version.BuildID,
272+
)
273+
assert.NoError(t, res.Err)
274+
}, 30*time.Second, 100*time.Millisecond)
275+
276+
res = s.Execute(
277+
"worker", "deployment", "describe",
278+
"--address", s.Address(),
279+
"--name", deploymentName,
280+
)
281+
s.NoError(res.Err)
282+
283+
s.ContainsOnSameLine(res.Stdout.String(), "Name", deploymentName)
284+
s.ContainsOnSameLine(res.Stdout.String(), "RampingVersionDeploymentName", version.DeploymentName)
285+
s.ContainsOnSameLine(res.Stdout.String(), "RampingVersionBuildID", version.BuildID)
286+
287+
// json
288+
res = s.Execute(
289+
"worker", "deployment", "describe",
290+
"--address", s.Address(),
291+
"--name", deploymentName,
292+
"--output", "json",
293+
)
294+
s.NoError(res.Err)
295+
296+
var jsonOut jsonDeploymentInfoType
297+
s.NoError(json.Unmarshal(res.Stdout.Bytes(), &jsonOut))
298+
s.Equal(deploymentName, jsonOut.Name)
299+
s.Equal(version.DeploymentName, jsonOut.RoutingConfig.RampingVersionDeploymentName)
300+
s.Equal(version.BuildID, jsonOut.RoutingConfig.RampingVersionBuildID)
301+
}
302+
176303
func filterByNamePrefix(jsonOut []jsonDeploymentInfoType, prefix string) []jsonDeploymentInfoType {
177304
result := []jsonDeploymentInfoType{}
178305
for i := range jsonOut {

temporalcli/commandsgen/commands.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ commands:
11371137
- name: ignore-missing-task-queues
11381138
type: bool
11391139
description: Override protection to accidentally remove task queues.
1140+
- name: allow-no-pollers
1141+
type: bool
1142+
description: Override protection and set version as current even if it has no pollers.
11401143
- name: yes
11411144
short: y
11421145
type: bool
@@ -1204,6 +1207,9 @@ commands:
12041207
- name: ignore-missing-task-queues
12051208
type: bool
12061209
description: Override protection to accidentally remove task queues.
1210+
- name: allow-no-pollers
1211+
type: bool
1212+
description: Override protection and set version as ramping even if it has no pollers.
12071213
- name: yes
12081214
short: y
12091215
type: bool

0 commit comments

Comments
 (0)