Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

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

Signed-off-by: Yuvraj <evalsocket@gmail.com>

* wip:  small fix

Signed-off-by: yuvraj <evalsocket@gmail.com>

* wip: version api call added

Signed-off-by: yuvraj <evalsocket@gmail.com>

* added docs for version

Signed-off-by: Yuvraj <yuvraj.yad001@gmail.com>

* wip: lint fix

Signed-off-by: yuvraj <evalsocket@gmail.com>

* fix testcase

Signed-off-by: yuvraj <evalsocket@gmail.com>

* Removed version pkg

Signed-off-by: yuvraj <evalsocket@gmail.com>

* added json output in version command

Signed-off-by: yuvraj <evalsocket@gmail.com>

* unit test added

Signed-off-by: yuvraj <evalsocket@gmail.com>

* Added brew install in readme

Signed-off-by: yuvraj <evalsocket@gmail.com>
  • Loading branch information
yindia authored Apr 2, 2021
1 parent bbfdfb7 commit e14d7b1
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 38 deletions.
11 changes: 10 additions & 1 deletion 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 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 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 cmd/version.go

This file was deleted.

82 changes: 82 additions & 0 deletions 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 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 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 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 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 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 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 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 e14d7b1

Please sign in to comment.