Skip to content

Commit 2e392d1

Browse files
authored
cmd: add runner list command (#156)
Adds a new `ecctl platform runner list` command which lists all existing platform runners.
1 parent 3566c0d commit 2e392d1

File tree

12 files changed

+430
-0
lines changed

12 files changed

+430
-0
lines changed

cmd/platform/platform.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
cmdproxy "github.com/elastic/ecctl/cmd/platform/proxy"
2929
cmdrepository "github.com/elastic/ecctl/cmd/platform/repository"
3030
cmdrole "github.com/elastic/ecctl/cmd/platform/role"
31+
cmdrunner "github.com/elastic/ecctl/cmd/platform/runner"
3132
cmdstack "github.com/elastic/ecctl/cmd/platform/stack"
3233
"github.com/elastic/ecctl/pkg/ecctl"
3334
"github.com/elastic/ecctl/pkg/platform"
@@ -70,6 +71,7 @@ func init() {
7071
cmdrepository.Command,
7172
cmdrole.Command,
7273
cmdstack.Command,
74+
cmdrunner.Command,
7375
)
7476

7577
Command.AddCommand(infoCmd)

cmd/platform/runner/command.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdrunner
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
)
23+
24+
// Command is the top level runner command.
25+
var Command = &cobra.Command{
26+
Use: "runner",
27+
Short: "Manages platform runners",
28+
PreRunE: cobra.MaximumNArgs(0),
29+
Run: func(cmd *cobra.Command, args []string) {
30+
cmd.Help()
31+
},
32+
}

cmd/platform/runner/list.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdrunner
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
23+
"github.com/elastic/ecctl/pkg/ecctl"
24+
"github.com/elastic/ecctl/pkg/platform/runner"
25+
)
26+
27+
var listCmd = &cobra.Command{
28+
Use: "list",
29+
Short: "Lists the existing platform runners",
30+
PreRunE: cobra.NoArgs,
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
res, err := runner.List(runner.Params{API: ecctl.Get().API})
33+
if err != nil {
34+
return err
35+
}
36+
37+
return ecctl.Get().Formatter.Format("runner/list", res)
38+
},
39+
}
40+
41+
func init() {
42+
Command.AddCommand(listCmd)
43+
}

docs/ecctl_platform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ ecctl platform [flags]
4848
* [ecctl platform proxy](ecctl_platform_proxy.md) - Manages proxies
4949
* [ecctl platform repository](ecctl_platform_repository.md) - Manages snapshot repositories
5050
* [ecctl platform role](ecctl_platform_role.md) - Manages platform roles
51+
* [ecctl platform runner](ecctl_platform_runner.md) - Manages platform runners
5152
* [ecctl platform stack](ecctl_platform_stack.md) - Manages Elastic StackPacks
5253

docs/ecctl_platform_runner.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## ecctl platform runner
2+
3+
Manages platform runners
4+
5+
### Synopsis
6+
7+
Manages platform runners
8+
9+
```
10+
ecctl platform runner [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for runner
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
23+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
24+
--force Do not ask for confirmation
25+
--format string Formats the output using a Go template
26+
--host string Base URL to use
27+
--insecure Skips all TLS validation
28+
--message string A message to set on cluster operation
29+
--output string Output format [text|json] (default "text")
30+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
31+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
32+
-q, --quiet Suppresses the configuration file used for the run, if any
33+
--timeout duration Timeout to use on all HTTP calls (default 30s)
34+
--trace Enables tracing saves the trace to trace-20060102150405
35+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
36+
--verbose Enable verbose mode
37+
```
38+
39+
### SEE ALSO
40+
41+
* [ecctl platform](ecctl_platform.md) - Manages the platform
42+
* [ecctl platform runner list](ecctl_platform_runner_list.md) - Lists the existing platform runners
43+

docs/ecctl_platform_runner_list.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## ecctl platform runner list
2+
3+
Lists the existing platform runners
4+
5+
### Synopsis
6+
7+
Lists the existing platform runners
8+
9+
```
10+
ecctl platform runner list [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for list
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
23+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
24+
--force Do not ask for confirmation
25+
--format string Formats the output using a Go template
26+
--host string Base URL to use
27+
--insecure Skips all TLS validation
28+
--message string A message to set on cluster operation
29+
--output string Output format [text|json] (default "text")
30+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
31+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
32+
-q, --quiet Suppresses the configuration file used for the run, if any
33+
--timeout duration Timeout to use on all HTTP calls (default 30s)
34+
--trace Enables tracing saves the trace to trace-20060102150405
35+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
36+
--verbose Enable verbose mode
37+
```
38+
39+
### SEE ALSO
40+
41+
* [ecctl platform runner](ecctl_platform_runner.md) - Manages platform runners
42+

pkg/formatter/templates/bindata.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
// text/platform/repositorylist.gotmpl
4141
// text/proxy/list.gotmpl
4242
// text/roles/list.gotmpl
43+
// text/runner/list.gotmpl
4344
// text/stack/list.gotmpl
4445
// text/token/create.gotmpl
4546
// text/token/list.gotmpl
@@ -583,6 +584,26 @@ func textRolesListGotmpl() (*asset, error) {
583584
return a, nil
584585
}
585586

587+
var _textRunnerListGotmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8f\xc1\x6e\x83\x30\x10\x44\xef\xf9\x8a\x95\xef\xe5\x1f\x52\xb0\x84\xa5\xd4\x41\x94\x1c\x7a\x74\xf0\xa4\x45\x22\x4b\x45\xec\xaa\x95\xe5\x7f\xaf\x1c\x1a\x24\xd3\xd3\xae\xdf\x78\x77\x66\x43\x78\x22\x8b\xcb\xc0\x20\x31\x7d\x61\x9e\x07\x0b\x41\x31\x86\x40\xb3\xe1\x77\x50\xd1\x7a\x66\xcc\xb7\x3b\xc3\x37\x7a\xef\xd0\xe1\xfa\x39\x1a\x07\x2a\x62\xdc\x85\x40\x60\xbb\x8c\xac\xcd\x63\xa5\xc5\xc5\xf8\xd1\xa5\x8d\xbb\x64\x25\xda\x93\xd6\xb2\x25\x55\x2d\x26\xce\x9c\x53\x11\xf5\xf1\xb5\x23\xd5\x64\x90\x44\x73\x7a\x3e\xa8\x92\x92\xa8\xf7\x2f\x72\xa3\xd6\x72\x7f\xe8\xea\xb7\x0d\x2d\x8f\x5a\xcb\xb2\x93\xd5\xea\xf9\xef\x8e\x14\xf9\xef\xa9\xaa\x6c\xba\xa8\xa7\x9b\x53\x4d\xce\x1a\x7f\x1e\x87\x3e\x29\x6c\xae\xd8\xfc\x87\x19\xdd\xc7\x4f\x0e\xcb\x89\x19\xbd\x83\x7d\x24\x00\xdb\x7b\xb7\xd4\xdf\x00\x00\x00\xff\xff\x60\x8b\xf0\xd7\x73\x01\x00\x00")
588+
589+
func textRunnerListGotmplBytes() ([]byte, error) {
590+
return bindataRead(
591+
_textRunnerListGotmpl,
592+
"text/runner/list.gotmpl",
593+
)
594+
}
595+
596+
func textRunnerListGotmpl() (*asset, error) {
597+
bytes, err := textRunnerListGotmplBytes()
598+
if err != nil {
599+
return nil, err
600+
}
601+
602+
info := bindataFileInfo{name: "text/runner/list.gotmpl", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
603+
a := &asset{bytes: bytes, info: info}
604+
return a, nil
605+
}
606+
586607
var _textStackListGotmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x50\x4b\x6e\xab\x30\x14\x9d\xb3\x0a\x8b\x79\xbc\x07\xbf\x60\xbd\xa2\x7c\x5a\x05\x94\xf9\x0d\x3e\xa4\x56\xc0\x44\xc6\xa9\x2a\x5d\x79\xef\x15\x01\x22\x68\x47\xf7\xe8\x7c\x65\x33\x6f\x84\x41\x6d\x1d\x44\xda\x7d\xc1\x7b\x6b\x90\x8a\x18\x99\x85\x27\x77\x85\x90\x45\xa0\xea\xd6\x3f\x29\x7c\xa3\x7a\x04\x94\x68\xef\x0d\x05\x08\x19\x63\xc2\x2c\xe0\xcc\x98\x78\x81\xb9\xd1\xa0\xa6\x47\x13\x86\xc2\x64\x58\x4a\xcf\xfa\x54\xe4\xef\xc7\x74\x70\x05\xba\x0c\x27\xcd\xf4\x5e\x97\x3a\x1b\x57\x67\x52\xef\x55\x51\xe6\xdb\x42\xab\xd3\xf6\x4d\xe4\x07\xf5\x5f\xaf\x0d\xbb\xfc\x9f\x3a\xaa\x49\x59\x0a\xea\xe3\xf0\x62\x9f\xa3\xbf\xdf\x91\x30\xcb\x33\x7c\x6f\x3b\xb7\x6c\x94\x19\x1a\x04\x98\x15\xa7\x1b\xea\x83\xad\x7a\x90\xaf\x3e\x65\xd6\x55\x37\xf8\xbc\xa5\x2b\x56\xae\x9d\xbd\x90\xa3\xa5\x3c\x4d\x4f\x06\x61\x6b\x21\xd5\xbd\x1d\x3f\x67\x40\x7f\xaa\xd0\xf4\x88\x71\xc3\x0c\x67\xa6\xf0\x8c\xc6\xfb\x13\x00\x00\xff\xff\x34\x74\x77\x13\xa9\x01\x00\x00")
587608

588609
func textStackListGotmplBytes() ([]byte, error) {
@@ -798,6 +819,7 @@ var _bindata = map[string]func() (*asset, error){
798819
"text/platform/repositorylist.gotmpl": textPlatformRepositorylistGotmpl,
799820
"text/proxy/list.gotmpl": textProxyListGotmpl,
800821
"text/roles/list.gotmpl": textRolesListGotmpl,
822+
"text/runner/list.gotmpl": textRunnerListGotmpl,
801823
"text/stack/list.gotmpl": textStackListGotmpl,
802824
"text/token/create.gotmpl": textTokenCreateGotmpl,
803825
"text/token/list.gotmpl": textTokenListGotmpl,
@@ -896,6 +918,9 @@ var _bintree = &bintree{nil, map[string]*bintree{
896918
"roles": &bintree{nil, map[string]*bintree{
897919
"list.gotmpl": &bintree{textRolesListGotmpl, map[string]*bintree{}},
898920
}},
921+
"runner": &bintree{nil, map[string]*bintree{
922+
"list.gotmpl": &bintree{textRunnerListGotmpl, map[string]*bintree{}},
923+
}},
899924
"stack": &bintree{nil, map[string]*bintree{
900925
"list.gotmpl": &bintree{textStackListGotmpl, map[string]*bintree{}},
901926
}},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- define "override" }}{{ range .Runners }}{{executeTemplate .}}
2+
{{ end }}{{ end }}{{ define "default" }}
3+
{{- "RUNNER ID" }}{{tab}}{{"HOST IP" }}{{tab}}{{ "PUBLIC HOSTNAME" }}{{tab}}{{ "HEALTHY" }}{{tab}}{{ "CONNECTED" }}
4+
{{- range .Runners }}
5+
{{ .RunnerID }}{{tab}}{{ .HostIP }}{{tab}}{{ .PublicHostname }}{{tab}}{{ .Healthy }}{{tab}}{{ .Connected }}
6+
{{- end}}
7+
{{end}}

pkg/platform/runner/list.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package runner
19+
20+
import (
21+
"github.com/elastic/cloud-sdk-go/pkg/api"
22+
"github.com/elastic/cloud-sdk-go/pkg/client/platform_infrastructure"
23+
"github.com/elastic/cloud-sdk-go/pkg/models"
24+
)
25+
26+
// List gets the list of runners
27+
func List(params Params) (*models.RunnerOverview, error) {
28+
if err := params.Validate(); err != nil {
29+
return nil, err
30+
}
31+
32+
res, err := params.API.V1API.PlatformInfrastructure.GetRunners(
33+
platform_infrastructure.NewGetRunnersParams(),
34+
params.AuthWriter,
35+
)
36+
if err != nil {
37+
return nil, api.UnwrapError(err)
38+
}
39+
40+
return res.Payload, nil
41+
}

pkg/platform/runner/list_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package runner
19+
20+
import (
21+
"errors"
22+
"net/http"
23+
"net/url"
24+
"reflect"
25+
"testing"
26+
27+
"github.com/elastic/cloud-sdk-go/pkg/api"
28+
"github.com/elastic/cloud-sdk-go/pkg/api/mock"
29+
"github.com/elastic/cloud-sdk-go/pkg/models"
30+
"github.com/elastic/cloud-sdk-go/pkg/util/ec"
31+
)
32+
33+
func TestList(t *testing.T) {
34+
var runnerListSuccess = `
35+
{
36+
"runners": [{
37+
"connected": true,
38+
"runner_id": "192.168.44.10"
39+
}]
40+
}`
41+
type args struct {
42+
params Params
43+
}
44+
tests := []struct {
45+
name string
46+
args args
47+
want *models.RunnerOverview
48+
wantErr error
49+
}{
50+
{
51+
name: "Runner list succeeds",
52+
args: args{params: Params{
53+
API: api.NewMock(mock.Response{Response: http.Response{
54+
Body: mock.NewStringBody(runnerListSuccess),
55+
StatusCode: 200,
56+
}}),
57+
}},
58+
want: &models.RunnerOverview{
59+
Runners: []*models.RunnerInfo{
60+
{
61+
RunnerID: ec.String("192.168.44.10"),
62+
Connected: ec.Bool(true),
63+
},
64+
},
65+
},
66+
},
67+
{
68+
name: "Runner list fails",
69+
args: args{params: Params{
70+
API: api.NewMock(mock.Response{Error: errors.New("error")}),
71+
}},
72+
want: nil,
73+
wantErr: &url.Error{
74+
Op: "Get",
75+
URL: "https://mock-host/mock-path/platform/infrastructure/runners",
76+
Err: errors.New("error"),
77+
},
78+
},
79+
{
80+
name: "Runner list fails with an empty API",
81+
args: args{params: Params{
82+
API: nil,
83+
}},
84+
want: nil,
85+
wantErr: errors.New("api reference is required for command"),
86+
},
87+
}
88+
for _, tt := range tests {
89+
t.Run(tt.name, func(t *testing.T) {
90+
got, err := List(tt.args.params)
91+
if !reflect.DeepEqual(err, tt.wantErr) {
92+
t.Errorf("List() error = %v, wantErr %v", err, tt.wantErr)
93+
return
94+
}
95+
if !reflect.DeepEqual(got, tt.want) {
96+
t.Errorf("List() = %v, want %v", got, tt.want)
97+
}
98+
})
99+
}
100+
}

0 commit comments

Comments
 (0)