Skip to content

Commit

Permalink
Added version command (flyteorg#41)
Browse files Browse the repository at this point in the history
* wip: Added version command

Signed-off-by: Yuvraj <[email protected]>

* wip:  small fix

Signed-off-by: yuvraj <[email protected]>

* wip: version api call added

Signed-off-by: yuvraj <[email protected]>

* added docs for version

Signed-off-by: Yuvraj <[email protected]>

* wip: lint fix

Signed-off-by: yuvraj <[email protected]>

* fix testcase

Signed-off-by: yuvraj <[email protected]>

* Removed version pkg

Signed-off-by: yuvraj <[email protected]>

* added json output in version command

Signed-off-by: yuvraj <[email protected]>

* unit test added

Signed-off-by: yuvraj <[email protected]>

* Added brew install in readme

Signed-off-by: yuvraj <[email protected]>
  • Loading branch information
yindia authored Apr 2, 2021
1 parent 696065c commit 3904146
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 38 deletions.
11 changes: 10 additions & 1 deletion flytectl/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
export REPOSITORY=flytectl
include boilerplate/lyft/golang_test_targets/Makefile

GIT_VERSION := $(shell git describe --always --tags)
GIT_HASH := $(shell git rev-parse --short HEAD)
TIMESTAMP := $(shell date '+%Y-%m-%d')
PACKAGE ?=github.com/flyteorg/flytestdlib

LD_FLAGS="-s -w -X $(PACKAGE)/version.Version=$(GIT_VERSION) -X $(PACKAGE)/version.Build=$(GIT_HASH) -X $(PACKAGE)/version.BuildTime=$(TIMESTAMP)"



define PIP_COMPILE
pip-compile $(1) --upgrade --verbose
endef
Expand All @@ -9,7 +18,7 @@ generate:
go test github.com/flyteorg/flytectl/cmd --update

compile:
go build -o bin/flytectl main.go
go build -o bin/flytectl -ldflags=$(LD_FLAGS) main.go

.PHONY: update_boilerplate
update_boilerplate:
Expand Down
3 changes: 2 additions & 1 deletion flytectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Generating docs locally can be accomplished by running make gendocs from within
## Installation

```bash
curl -s https://raw.githubusercontent.com/flyteorg/flytectl/master/install.sh | bash
$ brew tap flyteorg/homebrew-tap
$ brew install flytectl
```

## Contributing
Expand Down
7 changes: 6 additions & 1 deletion flytectl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"

"github.com/flyteorg/flytectl/cmd/config"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flytectl/cmd/create"
"github.com/flyteorg/flytectl/cmd/delete"
"github.com/flyteorg/flytectl/cmd/get"
"github.com/flyteorg/flytectl/cmd/register"
"github.com/flyteorg/flytectl/cmd/update"
"github.com/flyteorg/flytectl/cmd/version"
"github.com/flyteorg/flytectl/pkg/printer"
stdConfig "github.com/flyteorg/flytestdlib/config"
"github.com/flyteorg/flytestdlib/config/viper"
Expand Down Expand Up @@ -44,12 +46,15 @@ func newRootCmd() *cobra.Command {
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())
rootCmd.AddCommand(create.RemoteCreateCommand())
rootCmd.AddCommand(update.CreateUpdateCommand())
rootCmd.AddCommand(register.RemoteRegisterCommand())
rootCmd.AddCommand(delete.RemoteDeleteCommand())
// Added version command
versioncmd := version.GetVersionCommand(rootCmd)
cmdCore.AddCommands(rootCmd, versioncmd)

config.GetConfig()

return rootCmd
Expand Down
17 changes: 0 additions & 17 deletions flytectl/cmd/version.go

This file was deleted.

82 changes: 82 additions & 0 deletions flytectl/cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package version

import (
"context"
"encoding/json"
"fmt"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
stdlibversion "github.com/flyteorg/flytestdlib/version"
"github.com/spf13/cobra"
)

// Long descriptions are whitespace sensitive when generating docs using sphinx.
const (
versionCmdShort = `Used for fetching flyte version`
versionCmdLong = `
Example version.
::
bin/flytectl version
`
)

type versionOutput struct {
// Specifies the Name of app
App string `json:"App,omitempty"`
// Specifies the GIT sha of the build
Build string `json:"Build,omitempty"`
// Version for the build, should follow a semver
Version string `json:"Version,omitempty"`
// Build timestamp
BuildTime string `json:"BuildTime,omitempty"`
}

// GetVersionCommand will return version command
func GetVersionCommand(rootCmd *cobra.Command) map[string]cmdCore.CommandEntry {
getResourcesFuncs := map[string]cmdCore.CommandEntry{
"version": {CmdFunc: getVersion, Aliases: []string{"versions"}, ProjectDomainNotRequired: true,
Short: versionCmdShort,
Long: versionCmdLong},
}
return getResourcesFuncs
}

func getVersion(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {

v, err := cmdCtx.AdminClient().GetVersion(ctx, &admin.GetVersionRequest{})
if err != nil {
return fmt.Errorf("err %v: ", err)
}

// Print Flytectl
if err := printVersion(versionOutput{
Build: stdlibversion.Build,
BuildTime: stdlibversion.BuildTime,
Version: stdlibversion.Version,
App: "flytectl",
}); err != nil {
return err
}

// Print Flyteadmin
if err := printVersion(versionOutput{
Build: v.ControlPlaneVersion.Build,
BuildTime: v.ControlPlaneVersion.BuildTime,
Version: v.ControlPlaneVersion.Version,
App: "controlPlane",
}); err != nil {
return err
}
return nil
}

func printVersion(response versionOutput) error {
b, err := json.MarshalIndent(response, "", " ")
if err != nil {
return fmt.Errorf("err %v: ", err)
}
fmt.Print(string(b))
return nil
}
34 changes: 34 additions & 0 deletions flytectl/cmd/version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package version

import (
"context"
"fmt"
"io"
"testing"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/clients/go/admin/mocks"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/stretchr/testify/assert"
)

func TestListExecutionFunc(t *testing.T) {
ctx := context.Background()
var args []string
mockClient := new(mocks.AdminServiceClient)
mockOutStream := new(io.Writer)
cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream)
versionRequest := &admin.GetVersionRequest{}
versionResponse := &admin.GetVersionResponse{
ControlPlaneVersion: &admin.Version{
Build: "",
BuildTime: "",
Version: "",
},
}
mockClient.OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, nil)
err := getVersion(ctx, args, cmdCtx)
fmt.Println(err)
assert.Nil(t, nil)
mockClient.AssertCalled(t, "GetVersion", ctx, versionRequest)
}
2 changes: 1 addition & 1 deletion flytectl/docs/source/gen/flytectl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ SEE ALSO
* :doc:`flytectl_get` - Used for fetching various flyte resources including tasks/workflows/launchplans/executions/project.
* :doc:`flytectl_register` - Registers tasks/workflows/launchplans from list of generated serialized files.
* :doc:`flytectl_update` - Used for updating flyte resources eg: project.
* :doc:`flytectl_version` - Displays version information for the client and server.
* :doc:`flytectl_version` - Used for fetching flyte version

12 changes: 6 additions & 6 deletions flytectl/docs/source/gen/flytectl_get_launchplan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ The generated file would look similar to this
iamRoleARN: ""
inputs:
numbers:
- 0
numbers_count: 0
run_local_at_count: 10
numbers:
- 0
numbers_count: 0
run_local_at_count: 10
kubeServiceAcct: ""
targetDomain: ""
targetProject: ""
workflow: core.advanced.run_merge_sort.merge
version: "v3"
version: v3
workflow: core.advanced.run_merge_sort.merge_sort
Check the create execution section on how to launch one using the generated file.

Expand Down
2 changes: 1 addition & 1 deletion flytectl/docs/source/gen/flytectl_get_task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The generated file would look similar to this
targetDomain: ""
targetProject: ""
task: core.advanced.run_merge_sort.merge
version: "v2"
version: v2
Check the create execution section on how to launch one using the generated file.

Expand Down
9 changes: 7 additions & 2 deletions flytectl/docs/source/gen/flytectl_version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
flytectl version
----------------

Displays version information for the client and server.
Used for fetching flyte version

Synopsis
~~~~~~~~


Displays version information for the client and server.

Example version.
::

bin/flytectl version


::

Expand Down
7 changes: 3 additions & 4 deletions flytectl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ go 1.13

require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/flyteorg/flyteidl v0.18.15
github.com/flyteorg/flytestdlib v0.3.13
github.com/flyteorg/flyteidl v0.18.25
github.com/flyteorg/flytestdlib v0.3.15
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.4.3
github.com/google/uuid v1.1.2
github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23
github.com/kr/text v0.2.0 // indirect
github.com/landoop/tableprinter v0.0.0-20180806200924-8bd8c2576d27
github.com/magiconair/properties v1.8.4
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
Expand All @@ -26,5 +27,3 @@ require (
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.2.0
)

replace github.com/flyteorg/flyteidl => github.com/flyteorg/flyteidl v0.18.21-0.20210317055906-f2ce9eb7bd1f
8 changes: 4 additions & 4 deletions flytectl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/flyteorg/flyteidl v0.18.21-0.20210317055906-f2ce9eb7bd1f h1:7qRMZRPQXUVpebBt92msIzQBRtJ4fraWhd75qA6oqaE=
github.com/flyteorg/flyteidl v0.18.21-0.20210317055906-f2ce9eb7bd1f/go.mod h1:b5Fq4Z8a5b0mF6pEwTd48ufvikUGVkWSjZiMT0ZtqKI=
github.com/flyteorg/flytestdlib v0.3.13 h1:5ioA/q3ixlyqkFh5kDaHgmPyTP/AHtqq1K/TIbVLUzM=
github.com/flyteorg/flyteidl v0.18.25 h1:XbHwM4G1u5nGAcdKod+ENgbL84cHdNzQIWY+NajuHs8=
github.com/flyteorg/flyteidl v0.18.25/go.mod h1:b5Fq4Z8a5b0mF6pEwTd48ufvikUGVkWSjZiMT0ZtqKI=
github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220=
github.com/flyteorg/flytestdlib v0.3.15 h1:vzsfqriENyavv6EBwsIm55di2wC+j0jkmjw30JGHAkM=
github.com/flyteorg/flytestdlib v0.3.15/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
Expand Down Expand Up @@ -230,7 +231,6 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down

0 comments on commit 3904146

Please sign in to comment.