This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
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