Update version info endpoint

This commits updates version endpoint to use ProviderInfo and VersionInfo structs from
faas-provider.GatewayInfo now uses ProviderInfo and VersionInfo structs. GatewayInfo is
left within gateway. Consumer of this endpoint should use typed struct GatewayInfo to
parse response.

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
Vivek Singh 2021-01-18 09:34:54 +05:30 committed by Alex Ellis
parent 11d28b14cc
commit 82cd46ef2a
4 changed files with 12 additions and 32 deletions

View File

@ -3,7 +3,7 @@ NS?=openfaas
.PHONY: build-gateway
build-gateway:
(cd gateway; docker buildx build --platform linux/amd64 -t $NS/gateway:latest-dev .)
(cd gateway; docker buildx build --platform linux/amd64 -t ${NS}/gateway:latest-dev .)
# .PHONY: test-ci
# test-ci:

View File

@ -11,6 +11,7 @@ import (
"io/ioutil"
"net/http/httptest"
providerTypes "github.com/openfaas/faas-provider/types"
"github.com/openfaas/faas/gateway/types"
"github.com/openfaas/faas/gateway/version"
)
@ -24,8 +25,7 @@ func MakeInfoHandler(h http.Handler) http.HandlerFunc {
defer upstreamCall.Body.Close()
provider := make(map[string]interface{})
providerVersion := &types.VersionInfo{}
var provider *providerTypes.ProviderInfo
upstreamBody, _ := ioutil.ReadAll(upstreamCall.Body)
err := json.Unmarshal(upstreamBody, &provider)
@ -33,22 +33,14 @@ func MakeInfoHandler(h http.Handler) http.HandlerFunc {
log.Printf("Error unmarshalling provider json from body %s. Error %s\n", upstreamBody, err.Error())
}
versionMap := provider["version"].(map[string]interface{})
providerVersion.SHA = versionMap["sha"].(string)
providerVersion.Release = versionMap["release"].(string)
gatewayInfo := &types.GatewayInfo{
Version: &types.VersionInfo{
Version: &providerTypes.VersionInfo{
CommitMessage: version.GitCommitMessage,
Release: version.BuildVersion(),
SHA: version.GitCommitSHA,
},
Provider: &types.ProviderInfo{
Version: providerVersion,
Name: provider["provider"].(string),
Orchestration: provider["orchestration"].(string),
},
Arch: types.Arch,
Provider: provider,
Arch: types.Arch,
}
jsonOut, marshalErr := json.Marshal(gatewayInfo)

View File

@ -1,25 +1,13 @@
package types
import providerTypes "github.com/openfaas/faas-provider/types"
// Platform architecture the gateway is running on
var Arch string
// GatewayInfo provides information about the gateway and it's connected components
type GatewayInfo struct {
Provider *ProviderInfo `json:"provider"`
Version *VersionInfo `json:"version"`
Arch string `json:"arch"`
}
// ProviderInfo provides information about the configured provider
type ProviderInfo struct {
Name string `json:"provider"`
Version *VersionInfo `json:"version"`
Orchestration string `json:"orchestration"`
}
// VersionInfo provides the commit message, sha and release version number
type VersionInfo struct {
CommitMessage string `json:"commit_message,omitempty"`
SHA string `json:"sha"`
Release string `json:"release"`
Provider *providerTypes.ProviderInfo `json:"provider"`
Version *providerTypes.VersionInfo `json:"version"`
Arch string `json:"arch"`
}

View File

@ -111,4 +111,4 @@ google.golang.org/protobuf/runtime/protoiface
google.golang.org/protobuf/runtime/protoimpl
google.golang.org/protobuf/types/known/anypb
google.golang.org/protobuf/types/known/durationpb
google.golang.org/protobuf/types/known/timestamppb
google.golang.org/protobuf/types/known/timestamppb