Skip to content

Commit e642e41

Browse files
authored
cmd: Add --track flag to deployment commands (#80)
Adds the --track flag and resource tracking after a plan change to the deployment subcommands which incur plan changes: `create`, `update` and `shutdown`. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent c66d3bf commit e642e41

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

cmd/deployment/create.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import (
2626

2727
cmdutil "github.com/elastic/ecctl/cmd/util"
2828
"github.com/elastic/ecctl/pkg/deployment"
29+
"github.com/elastic/ecctl/pkg/deployment/depresource"
2930
"github.com/elastic/ecctl/pkg/ecctl"
3031
"github.com/elastic/ecctl/pkg/util"
3132
)
3233

3334
const createLong = `Creates a deployment from a file definition with an automatically generated idempotency token.
3435
On creation failure, please use the displayed idempotency token to retry the cluster creation with --request-id=<token>.
36+
To track the creation of the resources toggle the --track flag.
3537
3638
Read more about the deployment definition in https://www.elastic.co/guide/en/cloud-enterprise/current/Deployment_-_CRUD.html`
3739

@@ -167,12 +169,23 @@ var createCmd = &cobra.Command{
167169
return err
168170
}
169171

170-
return ecctl.Get().Formatter.Format("", res)
172+
var track, _ = cmd.Flags().GetBool("track")
173+
return cmdutil.Track(cmdutil.TrackParams{
174+
TrackResourcesParams: depresource.TrackResourcesParams{
175+
API: ecctl.Get().API,
176+
Resources: res.Resources,
177+
OutputDevice: ecctl.Get().Config.OutputDevice,
178+
},
179+
Formatter: ecctl.Get().Formatter,
180+
Track: track,
181+
Response: res,
182+
})
171183
},
172184
}
173185

174186
func init() {
175187
Command.AddCommand(createCmd)
188+
createCmd.Flags().BoolP("track", "t", false, cmdutil.TrackFlagMessage)
176189
createCmd.Flags().String("name", "", "Overrides the deployment name")
177190
createCmd.Flags().String("version", "", "Overrides all thee deployment's resources to the specified version")
178191
createCmd.Flags().String("request-id", "", "Optional idempotency token - Can be found in the Stderr device when a previous deployment creation failed, for more information see the examples in the help command page")

cmd/deployment/shutdown.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
cmdutil "github.com/elastic/ecctl/cmd/util"
2626
"github.com/elastic/ecctl/pkg/deployment"
27+
"github.com/elastic/ecctl/pkg/deployment/depresource"
2728
"github.com/elastic/ecctl/pkg/ecctl"
2829
)
2930

@@ -51,12 +52,24 @@ var shutdownCmd = &cobra.Command{
5152
return err
5253
}
5354

54-
return ecctl.Get().Formatter.Format("deployment/shutdown", res)
55+
var track, _ = cmd.Flags().GetBool("track")
56+
return cmdutil.Track(cmdutil.TrackParams{
57+
Template: "deployment/shutdown",
58+
TrackResourcesParams: depresource.TrackResourcesParams{
59+
API: ecctl.Get().API,
60+
Orphaned: res.Orphaned,
61+
OutputDevice: ecctl.Get().Config.OutputDevice,
62+
},
63+
Formatter: ecctl.Get().Formatter,
64+
Track: track,
65+
Response: res,
66+
})
5567
},
5668
}
5769

5870
func init() {
5971
Command.AddCommand(shutdownCmd)
72+
shutdownCmd.Flags().BoolP("track", "t", false, cmdutil.TrackFlagMessage)
6073
shutdownCmd.Flags().Bool("skip-snapshot", false, "Skips taking an Elasticsearch snapshot prior to shutting down the deployment")
6174
shutdownCmd.Flags().Bool("hide", false, "Hides the deployment and its resources after it has been shut down")
6275
}

cmd/deployment/update.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import (
2525

2626
cmdutil "github.com/elastic/ecctl/cmd/util"
2727
"github.com/elastic/ecctl/pkg/deployment"
28+
"github.com/elastic/ecctl/pkg/deployment/depresource"
2829
"github.com/elastic/ecctl/pkg/ecctl"
2930
)
3031

3132
const updateLong = `updates a deployment from a file definition, defaulting prune_orphans=false, making the default
3233
update action safe for partial updates, to override this behavior toggle --prune-orphans.
34+
To track the changes toggle the --track flag.
3335
3436
Read more about the deployment definition in https://www.elastic.co/guide/en/cloud-enterprise/current/Deployment_-_CRUD.html`
3537

@@ -164,12 +166,24 @@ var updateCmd = &cobra.Command{
164166
return err
165167
}
166168

167-
return ecctl.Get().Formatter.Format("", res)
169+
var track, _ = cmd.Flags().GetBool("track")
170+
return cmdutil.Track(cmdutil.TrackParams{
171+
TrackResourcesParams: depresource.TrackResourcesParams{
172+
API: ecctl.Get().API,
173+
Resources: res.Resources,
174+
Orphaned: res.ShutdownResources,
175+
OutputDevice: ecctl.Get().Config.OutputDevice,
176+
},
177+
Formatter: ecctl.Get().Formatter,
178+
Track: track,
179+
Response: res,
180+
})
168181
},
169182
}
170183

171184
func init() {
172185
Command.AddCommand(updateCmd)
186+
updateCmd.Flags().BoolP("track", "t", false, cmdutil.TrackFlagMessage)
173187
updateCmd.Flags().Bool("prune-orphans", false, "When set to true, it will remove any resources not specified in the update request, treating the json file contents as the authoritative deployment definition")
174188
updateCmd.Flags().Bool("skip-snapshot", false, "Skips taking an Elasticsearch snapshot prior to shutting down the deployment")
175189
updateCmd.Flags().Bool("hide-pruned-orphans", false, "Hides orphaned resources that were shut down (only relevant if --prune-orphans=true)")

docs/ecctl_deployment_create.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Creates a deployment from a file definition, allowing certain flag overrides
66

77
Creates a deployment from a file definition with an automatically generated idempotency token.
88
On creation failure, please use the displayed idempotency token to retry the cluster creation with --request-id=<token>.
9+
To track the creation of the resources toggle the --track flag.
910

1011
Read more about the deployment definition in https://www.elastic.co/guide/en/cloud-enterprise/current/Deployment_-_CRUD.html
1112

@@ -110,6 +111,7 @@ $ ecctl deployment create -f deployment_example.json --name adeploy --version=7.
110111
-h, --help help for create
111112
--name string Overrides the deployment name
112113
--request-id string Optional idempotency token - Can be found in the Stderr device when a previous deployment creation failed, for more information see the examples in the help command page
114+
-t, --track Tracks the progress of the performed task
113115
--version string Overrides all thee deployment's resources to the specified version
114116
```
115117

docs/ecctl_deployment_shutdown.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ecctl deployment shutdown <deployment-id> [flags]
1616
-h, --help help for shutdown
1717
--hide Hides the deployment and its resources after it has been shut down
1818
--skip-snapshot Skips taking an Elasticsearch snapshot prior to shutting down the deployment
19+
-t, --track Tracks the progress of the performed task
1920
```
2021

2122
### Options inherited from parent commands

docs/ecctl_deployment_update.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Updates a deployment from a file definition, allowing certain flag overrides
66

77
updates a deployment from a file definition, defaulting prune_orphans=false, making the default
88
update action safe for partial updates, to override this behavior toggle --prune-orphans.
9+
To track the changes toggle the --track flag.
910

1011
Read more about the deployment definition in https://www.elastic.co/guide/en/cloud-enterprise/current/Deployment_-_CRUD.html
1112

@@ -112,6 +113,7 @@ setting --prune-orphans to "true" will cause any resources not specified in the
112113
--hide-pruned-orphans Hides orphaned resources that were shut down (only relevant if --prune-orphans=true)
113114
--prune-orphans When set to true, it will remove any resources not specified in the update request, treating the json file contents as the authoritative deployment definition
114115
--skip-snapshot Skips taking an Elasticsearch snapshot prior to shutting down the deployment
116+
-t, --track Tracks the progress of the performed task
115117
```
116118

117119
### Options inherited from parent commands

0 commit comments

Comments
 (0)