Skip to content

Commit

Permalink
ACP Version
Browse files Browse the repository at this point in the history
ACP version is included in the trident orchestrator and in the tridentctl version command

Co-authored-by: Rohit Arora <[email protected]>
  • Loading branch information
torirevilla and Rohit Arora authored Oct 5, 2023
1 parent ebe0be5 commit 7fea629
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 73 deletions.
23 changes: 23 additions & 0 deletions acp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ func newClient(restAPI REST, acpEnabled bool) TridentACP {
return &client{restAPI, acpEnabled}
}

func (c *client) GetVersion(ctx context.Context) (*version.Version, error) {
Logc(ctx).Debug("Getting Trident-ACP version.")

if !c.acpEnabled {
Logc(ctx).Warning("ACP not enabled.")
return nil, nil
}

acpVersion, err := c.restClient.GetVersion(ctx)
if err != nil {
Logc(ctx).Error("Could not get Trident-ACP version.")
return nil, err
}

if acpVersion == nil {
Logc(ctx).Error("No version in response from Trident-ACP REST API.")
return nil, fmt.Errorf("no version in response from Trident-ACP REST API")
}

Logc(ctx).WithField("version", acpVersion.String()).Debug("Received Trident-ACP version.")
return acpVersion, nil
}

func (c *client) GetVersionWithBackoff(ctx context.Context) (*version.Version, error) {
Logc(ctx).Debug("Checking if Trident-ACP REST API is responsive.")
var v *version.Version
Expand Down
1 change: 1 addition & 0 deletions acp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// TridentACP is a set of methods for exposing Trident-ACP REST APIs to Trident.
type TridentACP interface {
GetVersion(context.Context) (*version.Version, error)
GetVersionWithBackoff(context.Context) (*version.Version, error)
IsFeatureEnabled(context.Context, string) error
}
Expand Down
5 changes: 3 additions & 2 deletions cli/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ type Version struct {
}

type VersionResponse struct {
Server Version `json:"server"`
Client Version `json:"client"`
Server Version `json:"server"`
Client Version `json:"client"`
ACPServer Version `json:"acpServer,omitempty"`
}

type ClientVersionResponse struct {
Expand Down
53 changes: 42 additions & 11 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,24 @@ var versionCmd = &cobra.Command{
return err
}

// Add the ACP version
var parsedACPServerVersion *versionutils.Version
if serverVersion.ACPVersion != "" {
parsedACPServerVersion, err = versionutils.ParseDate(serverVersion.ACPVersion)
if err != nil {
return err
}
}

// Add the client version, which is always hardcoded at compile time
versions := addClientVersion(parsedServerVersion)
versions := addClientVersion(parsedServerVersion, parsedACPServerVersion)

// Add the server's Go version
versions.Server.GoVersion = serverVersion.GoVersion

// TODO: Add the ACP server's Go version
// versions.ACPServer.GoVersion = serverVersion.GoVersion

writeVersions(versions)
}

Expand Down Expand Up @@ -118,8 +130,9 @@ func getVersionFromTunnel() (rest.GetVersionResponse, error) {
}

version := rest.GetVersionResponse{
Version: tunnelVersionResponse.Server.Version,
GoVersion: tunnelVersionResponse.Server.GoVersion,
Version: tunnelVersionResponse.Server.Version,
GoVersion: tunnelVersionResponse.Server.GoVersion,
ACPVersion: tunnelVersionResponse.ACPServer.Version,
}
return version, nil
}
Expand All @@ -140,7 +153,7 @@ func getClientVersion() *api.ClientVersionResponse {
}

// addClientVersion accepts the server version and fills in the client version
func addClientVersion(serverVersion *versionutils.Version) *api.VersionResponse {
func addClientVersion(serverVersion, acpServerVersion *versionutils.Version) *api.VersionResponse {
versions := api.VersionResponse{}

versions.Server.Version = serverVersion.String()
Expand All @@ -151,6 +164,16 @@ func addClientVersion(serverVersion *versionutils.Version) *api.VersionResponse
versions.Server.BuildMetadata = serverVersion.BuildMetadata()
versions.Server.APIVersion = config.OrchestratorAPIVersion

if acpServerVersion != nil {
versions.ACPServer.Version = acpServerVersion.String()
versions.ACPServer.MajorVersion = acpServerVersion.MajorVersion()
versions.ACPServer.MinorVersion = acpServerVersion.MinorVersion()
versions.ACPServer.PatchVersion = acpServerVersion.PatchVersion()
versions.ACPServer.PreRelease = acpServerVersion.PreRelease()
versions.ACPServer.BuildMetadata = acpServerVersion.BuildMetadata()
versions.ACPServer.APIVersion = config.OrchestratorAPIVersion
}

versions.Client = getClientVersion().Client

return &versions
Expand Down Expand Up @@ -195,13 +218,21 @@ func writeVersionTable(version *api.ClientVersionResponse) {

func writeVersionsTable(versions *api.VersionResponse) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Server Version", "Client Version"})

table.Append([]string{
versions.Server.Version,
versions.Client.Version,
})

if versions.ACPServer.Version != "" {
table.SetHeader([]string{"Server Version", "Client Version", "ACP Version"})
table.Append([]string{
versions.Server.Version,
versions.Client.Version,
versions.ACPServer.Version,
})
} else {
table.SetHeader([]string{"Server Version", "Client Version"})

table.Append([]string{
versions.Server.Version,
versions.Client.Version,
})
}
table.Render()
}

Expand Down
31 changes: 26 additions & 5 deletions frontend/rest/controller_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/google/uuid"
"github.com/gorilla/mux"

"github.com/netapp/trident/acp"
"github.com/netapp/trident/config"
"github.com/netapp/trident/frontend"
"github.com/netapp/trident/frontend/common"
Expand Down Expand Up @@ -244,9 +245,10 @@ func (r *AddBackendResponse) logFailure(ctx context.Context) {
}

type GetVersionResponse struct {
Version string `json:"version"`
GoVersion string `json:"goVersion"`
Error string `json:"error,omitempty"`
Version string `json:"version"`
GoVersion string `json:"goVersion"`
Error string `json:"error,omitempty"`
ACPVersion string `json:"acpVersion,omitempty"`
}

func GetVersion(w http.ResponseWriter, r *http.Request) {
Expand All @@ -261,11 +263,28 @@ func GetVersion(w http.ResponseWriter, r *http.Request) {
response.Error = err.Error()
}
response.Version = version

response.ACPVersion = GetACPVersion(ctx)
return httpStatusCodeForGetUpdateList(err)
},
)
}

func GetACPVersion(ctx context.Context) string {
version, err := acp.API().GetVersion(ctx)
if err != nil {
Logc(ctx).WithError(err).Error("Could not get trident-acp version.")
return ""
}

if version == nil {
Logc(ctx).WithError(err).Error("trident-acp version is empty.")
return ""
}

return version.String()
}

func AddBackend(w http.ResponseWriter, r *http.Request) {
response := &AddBackendResponse{}
AddGeneric(w, r, response,
Expand Down Expand Up @@ -351,7 +370,8 @@ func UpdateBackendState(w http.ResponseWriter, r *http.Request) {
}
ctx := GenerateRequestContext(r.Context(), "", "", WorkflowBackendUpdate, LogLayerRESTFrontend)

backend, err := orchestrator.UpdateBackendState(ctx, vars["backend"], request.BackendState, request.UserBackendState)
backend, err := orchestrator.UpdateBackendState(ctx, vars["backend"], request.BackendState,
request.UserBackendState)
if err != nil {
updateResponse.Error = err.Error()
}
Expand Down Expand Up @@ -622,7 +642,8 @@ func volumeLUKSPassphraseNamesUpdater(_ http.ResponseWriter, r *http.Request, re

err = orchestrator.UpdateVolumeLUKSPassphraseNames(r.Context(), vars["volume"], passphraseNames)
if err != nil {
response.setError(fmt.Errorf("failed to update LUKS passphrase names for volume %s: %s", vars["volume"], err.Error()))
response.setError(fmt.Errorf("failed to update LUKS passphrase names for volume %s: %s", vars["volume"],
err.Error()))
if errors.IsNotFoundError(err) {
return http.StatusNotFound
}
Expand Down
15 changes: 15 additions & 0 deletions mocks/mock_acp/mock_acp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7fea629

Please sign in to comment.