forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
627ed70
commit 45c3fb0
Showing
12 changed files
with
156 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters