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

feat: improve runtime command usage #130

Merged
merged 3 commits into from
Nov 28, 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
26 changes: 25 additions & 1 deletion docs/30_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,31 @@ Available flags for the command:
- `--company-id`, to set the ID of the desired Company
- `--project-id`, to set the ID of the desired Project

### api-resources

The `runtime api-resources` subcommand allows you to list all the currently supported resources that you can use on
the `list` command.

Usage:

```sh
miactl runtime api-resources [flags]
```

Available flags for the command:

- `--endpoint`, to set the Console endpoint (default is `https://console.cloud.mia-platform.eu`)
- `--certificate-authority`, to provide the path to a custom CA certificate
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
- `--context`, to specify a different context from the currently selected one

### list RESOURCE-TYPE

The `runtime list` subcommand allows you to list all resources of a specific type that are running for the
environment associated to a given Project.

Use `miactl runtime api-resources` for a complete list of currently supported resources.

Usage:

```sh
Expand Down Expand Up @@ -277,7 +297,11 @@ Available flags for the command:

### logs

The `runtime logs` subcommand allows you to fetch or stream logs for a given regex of services
The `runtime logs` subcommand allows you to fetch or stream logs of running pods in the current context using a
regex query.

You can write any regex compatible with RE2 excluding -C. The regex than will be used to filter down the list of
pods available in the current context and then the logs of all their containers will be displayed.

Usage:

Expand Down
12 changes: 11 additions & 1 deletion internal/cmd/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ func Command(o *clioptions.CLIOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "logs resource-query",
Short: "Show logs related to a runtime resource using a regex query",
Long: "Show logs related to a runtime resource using a regex query.",
Long: `Show logs related to a runtime resource using a regex query.

You can write any regex compatible with RE2 excluding -C. The regex than will
be used to filter down the list of pods available in the current context and
then the logs of all their containers will be displayed.`,

Example: `# Get all logs for pods that begin with api-gateway
miactl runtime logs api-gateway

# Get all logs for pods named exactly job-name
miactl runtime logs "^job-name$"`,

Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
41 changes: 38 additions & 3 deletions internal/cmd/resources/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,44 @@ var resourcesAvailable = []string{
ServicesResourceType,
}

var autocompletableResources = []string{
CronJobsResourceType,
DeploymentsResourceType,
JobsResourceType,
PodsResourceType,
ServicesResourceType,
}

func APIResourcesCommand(_ *clioptions.CLIOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "api-resources",
Short: "List Mia-Platform Console supported runtime resources",
Long: "List Mia-Platform Console supported runtime resources.",

Run: func(cmd *cobra.Command, args []string) {
writer := cmd.OutOrStdout()
fmt.Fprint(writer, "NAME")
fmt.Fprintln(writer)
for _, resource := range autocompletableResources {
fmt.Fprint(writer, resource)
fmt.Fprintln(writer)
}
},
}

return cmd
}

func ListCommand(o *clioptions.CLIOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "list RESOURCE-TYPE",
Short: "List Mia-Platform Console runtime resources",
Long: `List Mia-Platform Console runtime resources.

A project on Mia-Platform Console once deployed can have one or more resource of different kinds associcated with one
or more of its environments.`,
A project on Mia-Platform Console once deployed can have one or more resource
of different kinds associcated with one or more of its environments.

Use "miactl runtime api-resources" for a complete list of currently supported resources.`,
Args: cobra.ExactArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return resourcesCompletions(args, toComplete), cobra.ShellCompDirectiveNoFileComp
Expand All @@ -80,6 +110,11 @@ or more of its environments.`,
cobra.CheckErr(err)
return printList(client, restConfig.ProjectID, args[0], restConfig.Environment)
},
Example: `# List all pods in current context
miactl runtime list pods

# List all service in 'development' environment
miactl runtime list services --environment development`,
}

o.AddEnvironmentFlags(cmd.Flags())
Expand All @@ -93,7 +128,7 @@ func resourcesCompletions(args []string, toComplete string) []string {
return resources
}

for _, resource := range resourcesAvailable {
for _, resource := range autocompletableResources {
if strings.HasPrefix(resource, toComplete) {
resources = append(resources, resource)
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ the resources generated, like Pods, Cronjobs and logs.

// add sub commands
cmd.AddCommand(
runtimeresources.APIResourcesCommand(o),
runtimeresources.ListCommand(o),
runtimeresources.CreateCommand(o),
environments.EnvironmentCmd(o),
Expand Down