mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Version Endpoint (#752)
This commit is contained in:
parent
aee63c6476
commit
82ef8f3b0e
10 changed files with 181 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
# Change Log
|
||||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- Add Operator `/api/v1/version` endpoint
|
||||
|
||||
## [1.1.10](https://github.com/arangodb/kube-arangodb/tree/1.1.10) (2021-07-06)
|
||||
- Switch K8S CRD API to V1
|
||||
|
|
4
Makefile
4
Makefile
|
@ -30,6 +30,8 @@ GOVERSION := 1.10.0-alpine
|
|||
PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)
|
||||
GOASSETSBUILDER := $(GOBUILDDIR)/bin/go-assets-builder$(shell go env GOEXE)
|
||||
|
||||
BUILDTIME = $(shell go run "$(ROOT)/tools/dategen/")
|
||||
|
||||
DOCKERFILE := Dockerfile
|
||||
|
||||
HELM ?= $(shell which helm)
|
||||
|
@ -236,7 +238,7 @@ bin: $(BIN)
|
|||
|
||||
$(BIN): $(SOURCES) dashboard/assets.go VERSION
|
||||
@mkdir -p $(BINDIR)
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix netgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o $(BIN) $(REPOPATH)
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix netgo -ldflags "-X $(REPOPATH)/pkg/version.version=$(VERSION) -X $(REPOPATH)/pkg/version.buildDate=$(BUILDTIME) -X $(REPOPATH)/pkg/version.build=$(COMMIT)" -o $(BIN) $(REPOPATH)
|
||||
|
||||
.PHONY: docker
|
||||
docker: check-vars $(BIN)
|
||||
|
|
|
@ -29,6 +29,8 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/version"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
|
@ -70,7 +72,8 @@ func init() {
|
|||
|
||||
// Wait until all finalizers of the current pod have been removed.
|
||||
func cmdLifecyclePreStopRun(cmd *cobra.Command, args []string) {
|
||||
cliLog.Info().Msgf("Starting arangodb-operator, lifecycle preStop, version %s build %s", projectVersion, projectBuild)
|
||||
|
||||
cliLog.Info().Msgf("Starting arangodb-operator (%s), lifecycle preStop, version %s build %s", version.GetVersionV1().Edition.Title(), version.GetVersionV1().Version, version.GetVersionV1().Build)
|
||||
|
||||
// Get environment
|
||||
namespace := os.Getenv(constants.EnvOperatorPodNamespace)
|
||||
|
@ -119,7 +122,7 @@ func cmdLifecyclePreStopRun(cmd *cobra.Command, args []string) {
|
|||
|
||||
// Copy the executable to a given place.
|
||||
func cmdLifecycleCopyRun(cmd *cobra.Command, args []string) {
|
||||
cliLog.Info().Msgf("Starting arangodb-operator, lifecycle copy, version %s build %s", projectVersion, projectBuild)
|
||||
cliLog.Info().Msgf("Starting arangodb-operator (%s), lifecycle copy, version %s build %s", version.GetVersionV1().Edition.Title(), version.GetVersionV1().Version, version.GetVersionV1().Build)
|
||||
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
|
|
7
main.go
7
main.go
|
@ -33,6 +33,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/version"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
|
||||
|
@ -86,9 +88,6 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
projectVersion = "dev"
|
||||
projectBuild = "dev"
|
||||
|
||||
maskAny = errors.WithStack
|
||||
|
||||
cmdMain = cobra.Command{
|
||||
|
@ -206,7 +205,7 @@ func cmdMainRun(cmd *cobra.Command, args []string) {
|
|||
cliLog.Info().
|
||||
Str("pod-name", name).
|
||||
Str("pod-namespace", namespace).
|
||||
Msgf("Starting arangodb-operator, version %s build %s", projectVersion, projectBuild)
|
||||
Msgf("Starting arangodb-operator (%s), version %s build %s", version.GetVersionV1().Edition.Title(), version.GetVersionV1().Version, version.GetVersionV1().Build)
|
||||
|
||||
// Check environment
|
||||
if len(namespace) == 0 {
|
||||
|
|
|
@ -29,6 +29,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
|
||||
"github.com/arangodb/kube-arangodb/pkg/version"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/errors"
|
||||
|
||||
"github.com/arangodb-helper/go-certificates"
|
||||
|
@ -157,6 +160,13 @@ func NewServer(cli corev1.CoreV1Interface, cfg Config, deps Dependencies) (*Serv
|
|||
r.Use(gin.Recovery())
|
||||
r.GET("/health", gin.WrapF(deps.LivenessProbe.LivenessHandler))
|
||||
|
||||
versionV1Responser, err := operatorHTTP.NewSimpleJSONResponse(version.GetVersionV1())
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
r.GET("/_api/version", gin.WrapF(versionV1Responser.ServeHTTP))
|
||||
r.GET("/api/v1/version", gin.WrapF(versionV1Responser.ServeHTTP))
|
||||
|
||||
var readyProbes []*probe.ReadyProbe
|
||||
if deps.Deployment.Enabled {
|
||||
r.GET("/ready/deployment", gin.WrapF(deps.Deployment.Probe.ReadyHandler))
|
||||
|
|
53
pkg/util/http/response.go
Normal file
53
pkg/util/http/response.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Author Adam Janikowski
|
||||
//
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// NewSimpleJSONResponse returns handler which server static json on GET request
|
||||
func NewSimpleJSONResponse(obj interface{}) (http.Handler, error) {
|
||||
data, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return simpleJSONResponse{data: data}, nil
|
||||
}
|
||||
|
||||
type simpleJSONResponse struct {
|
||||
data []byte
|
||||
}
|
||||
|
||||
func (s simpleJSONResponse) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||
if strings.ToUpper(request.Method) != http.MethodGet {
|
||||
writer.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
writer.Write(s.data)
|
||||
}
|
66
pkg/version/version.go
Normal file
66
pkg/version/version.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2021 ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Author Adam Janikowski
|
||||
//
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/arangodb/go-driver"
|
||||
)
|
||||
|
||||
type License string
|
||||
|
||||
const (
|
||||
CommunityEdition License = "community"
|
||||
)
|
||||
|
||||
func (s License) Title() string {
|
||||
return strings.Title(string(s))
|
||||
}
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
build = "dev"
|
||||
buildDate = ""
|
||||
edition = CommunityEdition
|
||||
goVersion = runtime.Version()
|
||||
)
|
||||
|
||||
type InfoV1 struct {
|
||||
Version driver.Version `json:"version"`
|
||||
Build string `json:"build"`
|
||||
Edition License `json:"edition"`
|
||||
GoVersion string `json:"go_version"`
|
||||
BuildDate string `json:"build_date,omitempty"`
|
||||
}
|
||||
|
||||
func GetVersionV1() InfoV1 {
|
||||
return InfoV1{
|
||||
Version: driver.Version(version),
|
||||
Build: build,
|
||||
Edition: edition,
|
||||
GoVersion: goVersion,
|
||||
BuildDate: buildDate,
|
||||
}
|
||||
}
|
|
@ -28,6 +28,8 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/version"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/logging"
|
||||
|
@ -70,7 +72,8 @@ func cmdStorageProvisionerRun(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// Log version
|
||||
cliLog.Info().Msgf("Starting arangodb local storage provisioner, version %s build %s", projectVersion, projectBuild)
|
||||
|
||||
cliLog.Info().Msgf("Starting arangodb local storage provisioner (%s), version %s build %s", version.GetVersionV1().Edition.Title(), version.GetVersionV1().Version, version.GetVersionV1().Build)
|
||||
|
||||
// Get environment
|
||||
nodeName := os.Getenv(constants.EnvOperatorNodeName)
|
||||
|
|
33
tools/dategen/main.go
Normal file
33
tools/dategen/main.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2021 ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
//
|
||||
// Author Adam Janikowski
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
io.WriteString(os.Stdout, time.Now().UTC().Format(time.RFC3339))
|
||||
}
|
|
@ -24,8 +24,8 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/arangodb/kube-arangodb/pkg/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -39,5 +39,6 @@ var cmdVersion = &cobra.Command{
|
|||
}
|
||||
|
||||
func versionRun(cmd *cobra.Command, args []string) {
|
||||
println(fmt.Sprintf("Version: %s, Build: %s, Go: %s", projectVersion, projectBuild, runtime.Version()))
|
||||
v := version.GetVersionV1()
|
||||
println(fmt.Sprintf("Version: %s %s, Build: %s, Go: %s, Build Date: %s", v.Edition.Title(), v.Version, v.Build, v.GoVersion, v.BuildDate))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue