Skip to content

Commit

Permalink
support multi provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKobi committed May 28, 2021
1 parent b3256ee commit b01c100
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 146 deletions.
87 changes: 45 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ profiles:
dev:
default: true
providers:
aws:
- name: aws
creds-profile: dev
region: us-west-1
region: us-east-1
vpc-id: vpc-112233445566
- name: aws
creds-profile: dev
region: eu-west-1
vpc-id: vpc-987654312876
ssh:
domain: "@dev-example.com"
user: ec2-user
prod:
providers:
aws:
- name: aws
creds-profile: prod
region: us-east-1
vpc-id: vpc-009988776655
Expand Down Expand Up @@ -103,28 +107,26 @@ Run multiple commands pre-configured, manipulate data between each command and p
```
flows:
connect-pod:
-
run: "kubectl get pods -o json -l app=microservice"
- run: kubectl get pods -ojson -l app=someapp
root: items
output_format: json
selector: name
keys:
- name: name
path: metadata.name
- name: role
path: metadata.labels.role
- run: kubectl exec -it {{.name}} -c someContainer-{{.role}} bash
print-pods:
- run: kubectl get pods -ojson -l app=someapp
root: items
selector: metadata.name
keys:
- metadata.labels.role
-
run: "kubectl exec -it {{.metadata_name}} -c microservice-{{.metadata_labels_role}} bash"
print-pods-data:
-
run: "kubectl get pods -o json -l app=microservice"
- name: name
path: metadata.name
- name: role
path: metadata.labels.role
output_format: json
root: items
print: true
selector: metadata.name
keys:
- spec.nodeName
- metadata.labels.someLabel1
- metadata.labels.someLabel2
-
run: echo name is: {{.metadata_name}} nodeName is: {{.spec_nodeName}}
```
Running flow:
Expand Down Expand Up @@ -168,32 +170,33 @@ Adding new flow low-example
Listing flows
```
xt flow list
connect-pods:
- run: kubectl get pods -o json -l app=microservice
selector: metadata.name
keys:
- metadata.labels.role
root: items
output_format: json
- run: kubectl exec -it {{.metadata_name}} -c microservice-{{.metadata_labels_role}} bash
output_format: ""
print-pods-data:
- run: kubectl get pods -o json -l app=microservice
selector: metadata.name
keys:
- spec.nodeName
- metadata.labels.role
root: items
output_format: json
print: true
- run: 'echo name is: {{.metadata_name}} nodeName is: {{.spec_nodeName}}'
output_format: ""
connect-pod:
- run: kubectl get pods -ojson -l app=someapp
root: items
output_format: json
selector: name
keys:
- name: name
path: metadata.name
- name: role
path: metadata.labels.role
- run: kubectl exec -it {{.name}} -c someContainer-{{.role}} bash
print-pods:
- run: kubectl get pods -ojson -l app=someapp
root: items
keys:
- name: name
path: metadata.name
- name: role
path: metadata.labels.role
output_format: json
print: true
```

Deleting flows
```
xt flow delete print-pods-data
flow print-pods-data deleted successfully
xt flow delete print-pods
flow print-pods deleted successfully
```
# Info
Query cloud provider instances by name and print a formated table of the data
Expand Down
17 changes: 10 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type Pair struct {
}

type ProfileOptions struct {
Default bool `yaml:"default"`
ProviderOptions ProviderOptions `yaml:"provider"`
SSHOptions SSHOptions `yaml:"ssh"`
DisplayMsg string `yaml:"message,omitempty"`
Default bool `yaml:"default"`
ProviderOptions []ProviderOptions `yaml:"providers"`
SSHOptions SSHOptions `yaml:"ssh"`
DisplayMsg string `yaml:"message,omitempty"`
}

type ProviderOptions struct {
Expand Down Expand Up @@ -136,9 +136,12 @@ func (p *ProfileOptions) Validate() error {
if err := p.SSHOptions.validate(); err != nil {
return err
}
if err := p.ProviderOptions.validate(); err != nil {
return err
for _, pr := range p.ProviderOptions {
if err := pr.validate(); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -193,7 +196,7 @@ func (p *ProviderOptions) validate() error {
}

//Provider returns the selected profile config
func (p *ProfileOptions) Provider() ProviderOptions {
func (p *ProfileOptions) Provider() []ProviderOptions {
return p.ProviderOptions
}

Expand Down
38 changes: 21 additions & 17 deletions pkg/command/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/adamkobi/xt/internal/config"
"github.com/adamkobi/xt/internal/instance"
"github.com/adamkobi/xt/pkg/cmdutil"
"github.com/adamkobi/xt/pkg/executer"
"github.com/adamkobi/xt/pkg/iostreams"
Expand Down Expand Up @@ -72,23 +73,26 @@ func runConnect(opts *Options) error {
fmt.Fprintf(opts.IO.Out, cs.Red("%s"), profile.Message())
}

providerOpts := &provider.Options{
Name: profile.ProviderOptions.Name,
VPC: profile.ProviderOptions.VPC,
Region: profile.ProviderOptions.Region,
CredsProfile: profile.ProviderOptions.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}

svc, err := provider.New(providerOpts)
if err != nil {
return err
}

instances, err := svc.Get()
if err != nil {
return err
var instances instance.XTInstances
for _, p := range profile.ProviderOptions {
opts := &provider.Options{
Name: p.Name,
VPC: p.VPC,
Region: p.Region,
CredsProfile: p.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}
svc, err := provider.New(opts)
if err != nil {
return err
}

i, err := svc.Get()
if err != nil {
return err
}
instances = append(instances, i...)
}

cmdOpts := &executer.Options{
Expand Down
36 changes: 20 additions & 16 deletions pkg/command/file/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/adamkobi/xt/internal/config"
"github.com/adamkobi/xt/internal/instance"
"github.com/adamkobi/xt/pkg/cmdutil"
"github.com/adamkobi/xt/pkg/executer"
"github.com/adamkobi/xt/pkg/iostreams"
Expand Down Expand Up @@ -79,23 +80,26 @@ func runDownload(opts *Options) error {
fmt.Fprintf(opts.IO.Out, cs.Red("%s"), profile.Message())
}

providerOpts := &provider.Options{
Name: profile.ProviderOptions.Name,
VPC: profile.ProviderOptions.VPC,
Region: profile.ProviderOptions.Region,
CredsProfile: profile.ProviderOptions.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}

svc, err := provider.New(providerOpts)
if err != nil {
return err
}
var instances instance.XTInstances
for _, p := range profile.ProviderOptions {
opts := &provider.Options{
Name: p.Name,
VPC: p.VPC,
Region: p.Region,
CredsProfile: p.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}
svc, err := provider.New(opts)
if err != nil {
return err
}

instances, err := svc.Get()
if err != nil {
return err
i, err := svc.Get()
if err != nil {
return err
}
instances = append(instances, i...)
}

cmdOpts := &executer.Options{
Expand Down
36 changes: 20 additions & 16 deletions pkg/command/file/put/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/adamkobi/xt/internal/config"
"github.com/adamkobi/xt/internal/instance"
"github.com/adamkobi/xt/pkg/cmdutil"
"github.com/adamkobi/xt/pkg/executer"
"github.com/adamkobi/xt/pkg/iostreams"
Expand Down Expand Up @@ -76,23 +77,26 @@ func runUpload(opts *Options) error {
fmt.Fprintf(opts.IO.Out, cs.Red("%s"), profile.Message())
}

providerOpts := &provider.Options{
Name: profile.ProviderOptions.Name,
VPC: profile.ProviderOptions.VPC,
Region: profile.ProviderOptions.Region,
CredsProfile: profile.ProviderOptions.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}

svc, err := provider.New(providerOpts)
if err != nil {
return err
}
var instances instance.XTInstances
for _, p := range profile.ProviderOptions {
opts := &provider.Options{
Name: p.Name,
VPC: p.VPC,
Region: p.Region,
CredsProfile: p.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}
svc, err := provider.New(opts)
if err != nil {
return err
}

instances, err := svc.Get()
if err != nil {
return err
i, err := svc.Get()
if err != nil {
return err
}
instances = append(instances, i...)
}

cmdOpts := &executer.Options{
Expand Down
36 changes: 20 additions & 16 deletions pkg/command/flow/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/adamkobi/xt/internal/config"
"github.com/adamkobi/xt/internal/instance"
"github.com/adamkobi/xt/pkg/cmdutil"
"github.com/adamkobi/xt/pkg/executer"
"github.com/adamkobi/xt/pkg/iostreams"
Expand Down Expand Up @@ -78,23 +79,26 @@ func runFlow(opts *Options) error {
fmt.Fprintf(opts.IO.Out, cs.Red("%s"), profile.Message())
}

providerOpts := &provider.Options{
Name: profile.ProviderOptions.Name,
VPC: profile.ProviderOptions.VPC,
Region: profile.ProviderOptions.Region,
CredsProfile: profile.ProviderOptions.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}

svc, err := provider.New(providerOpts)
if err != nil {
return err
}
var instances instance.XTInstances
for _, p := range profile.ProviderOptions {
opts := &provider.Options{
Name: p.Name,
VPC: p.VPC,
Region: p.Region,
CredsProfile: p.CredsProfile,
Tag: opts.Tag,
SearchPattern: opts.SearchPattern,
}
svc, err := provider.New(opts)
if err != nil {
return err
}

instances, err := svc.Get()
if err != nil {
return err
i, err := svc.Get()
if err != nil {
return err
}
instances = append(instances, i...)
}

cmdOpts := &executer.Options{
Expand Down
Loading

0 comments on commit b01c100

Please sign in to comment.