Skip to content

Commit

Permalink
launch plan command added (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yindia authored Oct 22, 2020
1 parent 1d96987 commit 73aa818
Show file tree
Hide file tree
Showing 22 changed files with 515 additions and 28 deletions.
26 changes: 26 additions & 0 deletions flytectl/.github.com/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# TL;DR
_Please replace this text with a description of what this PR accomplishes._

## Type
- [ ] Bug Fix
- [ ] Feature
- [ ] Plugin

## Are all requirements met?

- [ ] Code completed
- [ ] Smoke tested
- [ ] Unit tests added
- [ ] Code documentation added
- [ ] Any pending items have an associated Issue

## Complete description
_How did you fix the bug, make the feature etc. Link to any design docs etc_

## Tracking Issue
https://github.com/lyft/flyte/issues/<number>

## Follow-up issue
_NA_
OR
_https://github.com/lyft/flyte/issues/<number>_
Empty file.
6 changes: 5 additions & 1 deletion flytectl/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# flytectl
Flyte CLI
Install Flyte CLI

```bash
curl -s https://github.com/lyft/flytectl/blob/master/install.sh | bash
```

[Contribution guidelines for this project](docs/CONTRIBUTING.md)

6 changes: 5 additions & 1 deletion flytectl/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/lyft/flytestdlib/config"

"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/printer"
)

//go:generate pflags Config
Expand All @@ -16,16 +16,19 @@ var (
section = config.MustRegisterSection("root", defaultConfig)
)

// Config hold configration for flytectl flag
type Config struct {
Project string `json:"project" pflag:",Specifies the project to work on."`
Domain string `json:"domain" pflag:",Specified the domain to work on."`
Output string `json:"output" pflag:",Specified the output type."`
}

// OutputFormat will return output formate
func (cfg Config) OutputFormat() (printer.OutputFormat, error) {
return printer.OutputFormatString(strings.ToUpper(cfg.Output))
}

// MustOutputFormat will validate the supported output formate and return output formate
func (cfg Config) MustOutputFormat() printer.OutputFormat {
f, err := cfg.OutputFormat()
if err != nil {
Expand All @@ -34,6 +37,7 @@ func (cfg Config) MustOutputFormat() printer.OutputFormat {
return f
}

// GetConfig will return the config
func GetConfig() *Config {
return section.GetConfig().(*Config)
}
8 changes: 5 additions & 3 deletions flytectl/cmd/core/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import (
type CommandEntry struct {
ProjectDomainNotRequired bool
CmdFunc CommandFunc
Aliases []string
}

func AddCommands(rootCmd *cobra.Command, cmdFuncs map[string]CommandEntry) {
for resource, cmdEntry := range cmdFuncs {
cmd := &cobra.Command{
Use: resource,
Short: fmt.Sprintf("Retrieves %v resources.", resource),
RunE: generateCommandFunc(cmdEntry),
Use: resource,
Short: fmt.Sprintf("Retrieves %v resources.", resource),
Aliases: cmdEntry.Aliases,
RunE: generateCommandFunc(cmdEntry),
}

rootCmd.AddCommand(cmd)
Expand Down
8 changes: 5 additions & 3 deletions flytectl/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import (
"github.com/spf13/cobra"
)

// CreateGetCommand will return get command
func CreateGetCommand() *cobra.Command {
getCmd := &cobra.Command{
Use: "get",
Short: "Retrieve various resource.",
}

getResourcesFuncs := map[string]cmdcore.CommandEntry{
"projects": {CmdFunc: getProjectsFunc, ProjectDomainNotRequired: true},
"tasks": {CmdFunc: getTaskFunc},
"workflows": {CmdFunc: getWorkflowFunc},
"project": {CmdFunc: getProjectsFunc, Aliases: []string{"projects"}, ProjectDomainNotRequired: true},
"task": {CmdFunc: getTaskFunc, Aliases: []string{"tasks"}},
"workflow": {CmdFunc: getWorkflowFunc, Aliases: []string{"workflows"}},
"launchplan": {CmdFunc: getLaunchPlanFunc, Aliases: []string{"launchplans"}},
}

cmdcore.AddCommands(getCmd, getResourcesFuncs)
Expand Down
61 changes: 61 additions & 0 deletions flytectl/cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package get

import (
"context"
"github.com/golang/protobuf/proto"
"github.com/lyft/flytectl/cmd/config"
cmdCore "github.com/lyft/flytectl/cmd/core"
"github.com/lyft/flytectl/pkg/adminutils"
"github.com/lyft/flytectl/pkg/printer"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/lyft/flytestdlib/logger"
)

var launchplanColumns = []printer.Column{
{"Version", "$.id.version"},
{"Name", "$.id.name"},
{"Type", "$.closure.compiledTask.template.type"},
{"State", "$.spec.state"},
{"Schedule", "$.spec.entityMetadata.schedule"},
}

func LaunchplanToProtoMessages(l []*admin.LaunchPlan) []proto.Message {
messages := make([]proto.Message, 0, len(l))
for _, m := range l {
messages = append(messages, m)
}
return messages
}

func getLaunchPlanFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
launchPlanPrinter := printer.Printer{}

if len(args) == 1 {
name := args[0]
launchPlan, err := cmdCtx.AdminClient().ListLaunchPlans(ctx, &admin.ResourceListRequest{
Limit: 10,
Id: &admin.NamedEntityIdentifier{
Project: config.GetConfig().Project,
Domain: config.GetConfig().Domain,
Name: name,
},
})
if err != nil {
return err
}
logger.Debugf(ctx, "Retrieved %v excutions", len(launchPlan.LaunchPlans))
err = launchPlanPrinter.Print(config.GetConfig().MustOutputFormat(), launchplanColumns, LaunchplanToProtoMessages(launchPlan.LaunchPlans)...)
if err != nil {
return err
}
return nil
}

launchPlans, err := adminutils.GetAllNamedEntities(ctx, cmdCtx.AdminClient().ListLaunchPlanIds, adminutils.ListRequest{Project: config.GetConfig().Project, Domain: config.GetConfig().Domain})
if err != nil {
return err
}
logger.Debugf(ctx, "Retrieved %v launch plans", len(launchPlans))
return launchPlanPrinter.Print(config.GetConfig().MustOutputFormat(), entityColumns, adminutils.NamedEntityToProtoMessage(launchPlans)...)
return nil
}
2 changes: 1 addition & 1 deletion flytectl/cmd/get/named_entity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package get

import (
"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/printer"
)

var entityColumns = []printer.Column{
Expand Down
12 changes: 5 additions & 7 deletions flytectl/cmd/get/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/lyft/flytectl/cmd/config"
cmdCore "github.com/lyft/flytectl/cmd/core"
"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/printer"
)

var projectColumns = []printer.Column{
Expand All @@ -28,10 +28,12 @@ func ProjectToProtoMessages(l []*admin.Project) []proto.Message {

func getProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
adminPrinter := printer.Printer{}

projects, err := cmdCtx.AdminClient().ListProjects(ctx, &admin.ProjectListRequest{})
if err != nil {
return err
}
if len(args) == 1 {
name := args[0]
projects, err := cmdCtx.AdminClient().ListProjects(ctx, &admin.ProjectListRequest{})
if err != nil {
return err
}
Expand All @@ -47,10 +49,6 @@ func getProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandC
}
return nil
}
projects, err := cmdCtx.AdminClient().ListProjects(ctx, &admin.ProjectListRequest{})
if err != nil {
return err
}
logger.Debugf(ctx, "Retrieved %v projects", len(projects.Projects))
return adminPrinter.Print(config.GetConfig().MustOutputFormat(), projectColumns, ProjectToProtoMessages(projects.Projects)...)
}
7 changes: 3 additions & 4 deletions flytectl/cmd/get/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package get

import (
"context"

"github.com/golang/protobuf/proto"
"github.com/lyft/flytestdlib/logger"

"github.com/lyft/flytectl/adminutils"
"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/adminutils"
"github.com/lyft/flytectl/pkg/printer"

"github.com/lyft/flytectl/cmd/config"
cmdCore "github.com/lyft/flytectl/cmd/core"
Expand Down Expand Up @@ -45,7 +44,7 @@ func getTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandConte
},
// TODO Sorting and limits should be parameters
SortBy: &admin.Sort{
Key: "created_at",
Key: "created_at",
Direction: admin.Sort_DESCENDING,
},
Limit: 100,
Expand Down
7 changes: 3 additions & 4 deletions flytectl/cmd/get/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package get

import (
"context"

"github.com/golang/protobuf/proto"
"github.com/lyft/flytestdlib/logger"

"github.com/lyft/flytectl/adminutils"
"github.com/lyft/flytectl/cmd/config"
cmdCore "github.com/lyft/flytectl/cmd/core"
"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/adminutils"
"github.com/lyft/flytectl/pkg/printer"

"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
)
Expand Down Expand Up @@ -39,7 +38,7 @@ func getWorkflowFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandC
},
// TODO Sorting and limits should be parameters
SortBy: &admin.Sort{
Key: "created_at",
Key: "created_at",
Direction: admin.Sort_DESCENDING,
},
Limit: 100,
Expand Down
3 changes: 1 addition & 2 deletions flytectl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/lyft/flytectl/cmd/get"
"github.com/lyft/flytectl/printer"
"github.com/lyft/flytectl/pkg/printer"

stdConfig "github.com/lyft/flytestdlib/config"
"github.com/lyft/flytestdlib/config/viper"
Expand Down Expand Up @@ -34,7 +34,6 @@ func newRootCmd() *cobra.Command {
rootCmd.PersistentFlags().StringVarP(&(config.GetConfig().Project), "project", "p", "", "Specifies the Flyte project.")
rootCmd.PersistentFlags().StringVarP(&(config.GetConfig().Domain), "domain", "d", "", "Specifies the Flyte project's domain.")
rootCmd.PersistentFlags().StringVarP(&(config.GetConfig().Output), "output", "o", printer.OutputFormatTABLE.String(), fmt.Sprintf("Specifies the output type - supported formats %s", printer.OutputFormats()))

rootCmd.AddCommand(viper.GetConfigCommand())
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(get.CreateGetCommand())
Expand Down
4 changes: 2 additions & 2 deletions flytectl/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
admin:
# For GRPC endpoints you might want to use dns:///flyte.myexample.com
# endpoint: http://localhost:30082
endpoint: dns:///flyte.lyft.net
insecure: false
# endpoint: dns:///flyte.lyft.net
insecure: true
logger:
show-source: true
level: 1
1 change: 1 addition & 0 deletions flytectl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/lyft/flytestdlib v0.3.10-0.20200619054107-45f341b716fa
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
Expand Down
Loading

0 comments on commit 73aa818

Please sign in to comment.