Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "create" actions were not awaited in some cases #589

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/cmd/firewall/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ var CreateCmd = base.Cmd{
return err
}

if err := waiter.WaitForActions(ctx, result.Actions); err != nil {
return err
}

fmt.Printf("Firewall %d created\n", result.Firewall.ID)

return nil
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/floatingip/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ var CreateCmd = base.Cmd{
return err
}

if result.Action != nil {
if err := waiter.ActionProgress(ctx, result.Action); err != nil {
return err
}
}

fmt.Printf("Floating IP %d created\n", result.FloatingIP.ID)

return changeProtection(ctx, client, waiter, result.FloatingIP, true, protectionOps)
Expand Down
8 changes: 7 additions & 1 deletion internal/cmd/placementgroup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var CreateCmd = base.Cmd{
cmd.MarkFlagRequired("type")
return cmd
},
Run: func(ctx context.Context, client hcapi2.Client, actionWaiter state.ActionWaiter, cmd *cobra.Command, args []string) error {
Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, cmd *cobra.Command, args []string) error {
name, _ := cmd.Flags().GetString("name")
labels, _ := cmd.Flags().GetStringToString("label")
placementGroupType, _ := cmd.Flags().GetString("type")
Expand All @@ -43,6 +43,12 @@ var CreateCmd = base.Cmd{
return err
}

if result.Action != nil {
if err := waiter.ActionProgress(ctx, result.Action); err != nil {
return err
}
}

fmt.Printf("Placement group %d created\n", result.PlacementGroup.ID)

return nil
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/placementgroup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func TestCreate(t *testing.T) {

fx.Client.PlacementGroupClient.EXPECT().
Create(gomock.Any(), opts).
Return(hcloud.PlacementGroupCreateResult{PlacementGroup: &placementGroup, Action: nil}, nil, nil)
Return(hcloud.PlacementGroupCreateResult{PlacementGroup: &placementGroup, Action: &hcloud.Action{ID: 321}}, nil, nil)

fx.ActionWaiter.EXPECT().
ActionProgress(gomock.Any(), &hcloud.Action{ID: 321})

out, err := fx.Run(cmd, []string{"--name", placementGroup.Name, "--type", string(placementGroup.Type)})

Expand Down
10 changes: 8 additions & 2 deletions internal/cmd/primaryip/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var CreateCmd = base.Cmd{

return cmd
},
Run: func(ctx context.Context, client hcapi2.Client, actionWaiter state.ActionWaiter, cmd *cobra.Command, args []string) error {
Run: func(ctx context.Context, client hcapi2.Client, waiter state.ActionWaiter, cmd *cobra.Command, args []string) error {
typ, _ := cmd.Flags().GetString("type")
name, _ := cmd.Flags().GetString("name")
assigneeID, _ := cmd.Flags().GetInt64("assignee-id")
Expand All @@ -68,10 +68,16 @@ var CreateCmd = base.Cmd{
return err
}

if result.Action != nil {
if err := waiter.ActionProgress(ctx, result.Action); err != nil {
return err
}
}

fmt.Printf("Primary IP %d created\n", result.PrimaryIP.ID)

if len(protection) > 0 {
if err := changeProtection(ctx, client, actionWaiter, result.PrimaryIP, true, protectionOpts); err != nil {
if err := changeProtection(ctx, client, waiter, result.PrimaryIP, true, protectionOpts); err != nil {
return err
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/primaryip/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ func TestCreate(t *testing.T) {
Return(
&hcloud.PrimaryIPCreateResult{
PrimaryIP: &hcloud.PrimaryIP{ID: 1},
Action: &hcloud.Action{ID: 321},
},
&hcloud.Response{},
nil,
)

fx.ActionWaiter.EXPECT().
ActionProgress(gomock.Any(), &hcloud.Action{ID: 321})

out, err := fx.Run(cmd, []string{"--name=my-ip", "--type=ipv4", "--datacenter=fsn1-dc14"})

expOut := "Primary IP 1 created\n"
Expand Down
Loading