diff --git a/flytectl/Makefile b/flytectl/Makefile index 2e5bcf7a82..8104b44ca9 100644 --- a/flytectl/Makefile +++ b/flytectl/Makefile @@ -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 @@ -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: diff --git a/flytectl/README.md b/flytectl/README.md index 6f46476b67..18d1afe748 100644 --- a/flytectl/README.md +++ b/flytectl/README.md @@ -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 diff --git a/flytectl/cmd/root.go b/flytectl/cmd/root.go index 26bfc2b453..8ad0fef299 100644 --- a/flytectl/cmd/root.go +++ b/flytectl/cmd/root.go @@ -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" @@ -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 diff --git a/flytectl/cmd/version.go b/flytectl/cmd/version.go deleted file mode 100644 index 647a5a1eac..0000000000 --- a/flytectl/cmd/version.go +++ /dev/null @@ -1,17 +0,0 @@ -package cmd - -import ( - "github.com/flyteorg/flytestdlib/version" - "github.com/spf13/cobra" -) - -var ( - versionCmd = &cobra.Command{ - Use: "version", - Short: "Displays version information for the client and server.", - Run: func(cmd *cobra.Command, args []string) { - version.LogBuildInformation("flytectl") - // TODO: Log Admin version - }, - } -) diff --git a/flytectl/cmd/version/version.go b/flytectl/cmd/version/version.go new file mode 100644 index 0000000000..57c7ddac08 --- /dev/null +++ b/flytectl/cmd/version/version.go @@ -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 +} diff --git a/flytectl/cmd/version/version_test.go b/flytectl/cmd/version/version_test.go new file mode 100644 index 0000000000..acaf34a829 --- /dev/null +++ b/flytectl/cmd/version/version_test.go @@ -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) +} diff --git a/flytectl/docs/source/gen/flytectl.rst b/flytectl/docs/source/gen/flytectl.rst index 70c8b01eba..89e4a4db9c 100644 --- a/flytectl/docs/source/gen/flytectl.rst +++ b/flytectl/docs/source/gen/flytectl.rst @@ -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 diff --git a/flytectl/docs/source/gen/flytectl_get_launchplan.rst b/flytectl/docs/source/gen/flytectl_get_launchplan.rst index 2746270b21..0cd64b8651 100644 --- a/flytectl/docs/source/gen/flytectl_get_launchplan.rst +++ b/flytectl/docs/source/gen/flytectl_get_launchplan.rst @@ -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. diff --git a/flytectl/docs/source/gen/flytectl_get_task.rst b/flytectl/docs/source/gen/flytectl_get_task.rst index 245de2b4f3..5ccddc30c9 100644 --- a/flytectl/docs/source/gen/flytectl_get_task.rst +++ b/flytectl/docs/source/gen/flytectl_get_task.rst @@ -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. diff --git a/flytectl/docs/source/gen/flytectl_version.rst b/flytectl/docs/source/gen/flytectl_version.rst index cbcf99db64..a56c061f65 100644 --- a/flytectl/docs/source/gen/flytectl_version.rst +++ b/flytectl/docs/source/gen/flytectl_version.rst @@ -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 + :: diff --git a/flytectl/go.mod b/flytectl/go.mod index 5723376489..4e89215bdf 100644 --- a/flytectl/go.mod +++ b/flytectl/go.mod @@ -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 @@ -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 diff --git a/flytectl/go.sum b/flytectl/go.sum index a189bc399e..cdd768fdab 100644 --- a/flytectl/go.sum +++ b/flytectl/go.sum @@ -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= @@ -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=