mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Fix arangosync members state inspection (#970)
This commit is contained in:
parent
b3b9da0574
commit
9d9d5e2dce
5 changed files with 86 additions and 36 deletions
|
@ -1,6 +1,7 @@
|
|||
# Change Log
|
||||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- (Bugfix) Fix arangosync members state inspection
|
||||
|
||||
## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10)
|
||||
- (Feature) Add CoreV1 Endpoints Inspector
|
||||
|
|
32
pkg/deployment/member/image.go
Normal file
32
pkg/deployment/member/image.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2016-2022 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
|
||||
//
|
||||
|
||||
package member
|
||||
|
||||
import (
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
)
|
||||
|
||||
func GetImageLicense(image *api.ImageInfo) string {
|
||||
if image.Enterprise {
|
||||
return "enterprise"
|
||||
}
|
||||
return "community"
|
||||
}
|
|
@ -78,7 +78,7 @@ func (s *stateInspector) Log(logger zerolog.Logger) {
|
|||
defer s.lock.Unlock()
|
||||
|
||||
for m, s := range s.members {
|
||||
if s.IsInvalid() {
|
||||
if !s.IsReachable() {
|
||||
s.Log(logger.Info()).Str("member", m).Msgf("Member is in invalid state")
|
||||
}
|
||||
}
|
||||
|
@ -95,22 +95,9 @@ func (s *stateInspector) RefreshState(ctx context.Context, members api.Deploymen
|
|||
|
||||
members.ForEach(func(id int) {
|
||||
if members[id].Group.IsArangosync() {
|
||||
return
|
||||
}
|
||||
|
||||
results[id] = State{}
|
||||
|
||||
c, err := s.client.GetServerClient(nctx, members[id].Group, members[id].Member.ID)
|
||||
if err != nil {
|
||||
results[id].Reachable = err
|
||||
return
|
||||
}
|
||||
|
||||
if v, err := c.Version(nctx); err != nil {
|
||||
results[id].Reachable = err
|
||||
return
|
||||
results[id] = s.fetchArangosyncMemberState(nctx, members[id])
|
||||
} else {
|
||||
results[id].Version = v
|
||||
results[id] = s.fetchServerMemberState(nctx, members[id])
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -122,11 +109,11 @@ func (s *stateInspector) RefreshState(ctx context.Context, members api.Deploymen
|
|||
|
||||
c, err := s.client.GetDatabaseClient(ctx)
|
||||
if err != nil {
|
||||
cs.Reachable = err
|
||||
cs.NotReachableErr = err
|
||||
} else {
|
||||
v, err := c.Version(gctx)
|
||||
if err != nil {
|
||||
cs.Reachable = err
|
||||
cs.NotReachableErr = err
|
||||
} else {
|
||||
cs.Version = v
|
||||
}
|
||||
|
@ -155,6 +142,46 @@ func (s *stateInspector) RefreshState(ctx context.Context, members api.Deploymen
|
|||
s.health = h
|
||||
}
|
||||
|
||||
func (s *stateInspector) fetchArangosyncMemberState(ctx context.Context, m api.DeploymentStatusMemberElement) State {
|
||||
var state State
|
||||
c, err := s.client.GetSyncServerClient(ctx, m.Group, m.Member.ID)
|
||||
if err != nil {
|
||||
state.NotReachableErr = err
|
||||
return state
|
||||
}
|
||||
|
||||
if v, err := c.Version(ctx); err != nil {
|
||||
state.NotReachableErr = err
|
||||
} else {
|
||||
// convert arangosync VersionInfo to go-driver VersionInfo for simplicity:
|
||||
state.Version = driver.VersionInfo{
|
||||
Server: m.Group.AsRole(),
|
||||
Version: driver.Version(v.Version),
|
||||
License: GetImageLicense(m.Member.Image),
|
||||
Details: map[string]interface{}{
|
||||
"arangosync-build": v.Build,
|
||||
},
|
||||
}
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
func (s *stateInspector) fetchServerMemberState(ctx context.Context, m api.DeploymentStatusMemberElement) State {
|
||||
var state State
|
||||
c, err := s.client.GetServerClient(ctx, m.Group, m.Member.ID)
|
||||
if err != nil {
|
||||
state.NotReachableErr = err
|
||||
return state
|
||||
}
|
||||
|
||||
if v, err := c.Version(ctx); err != nil {
|
||||
state.NotReachableErr = err
|
||||
} else {
|
||||
state.Version = v
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
func (s *stateInspector) MemberState(id string) (State, bool) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
@ -175,24 +202,15 @@ type Health struct {
|
|||
}
|
||||
|
||||
type State struct {
|
||||
Reachable error
|
||||
NotReachableErr error
|
||||
|
||||
Version driver.VersionInfo
|
||||
}
|
||||
|
||||
func (s State) IsReachable() bool {
|
||||
return s.Reachable == nil
|
||||
return s.NotReachableErr == nil
|
||||
}
|
||||
|
||||
func (s State) Log(event *zerolog.Event) *zerolog.Event {
|
||||
if !s.IsReachable() {
|
||||
event = event.Bool("reachable", false).AnErr("reachableError", s.Reachable)
|
||||
} else {
|
||||
event = event.Bool("reachable", false)
|
||||
}
|
||||
return event
|
||||
}
|
||||
|
||||
func (s State) IsInvalid() bool {
|
||||
return !s.IsReachable()
|
||||
return event.Bool("reachable", s.IsReachable()).AnErr("reachableError", s.NotReachableErr)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ package reconciler
|
|||
import (
|
||||
"context"
|
||||
|
||||
core "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/arangodb/arangosync-client/client"
|
||||
"github.com/arangodb/go-driver"
|
||||
"github.com/arangodb/go-driver/agency"
|
||||
|
@ -38,7 +40,6 @@ import (
|
|||
servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1"
|
||||
serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/v1"
|
||||
servicemonitorv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/servicemonitor/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// ServerGroupIterator provides a helper to callback on every server
|
||||
|
@ -191,4 +192,5 @@ type DeploymentClient interface {
|
|||
DeploymentAgencyClient
|
||||
DeploymentDatabaseClient
|
||||
DeploymentMemberClient
|
||||
DeploymentSyncClient
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
|
||||
memberState "github.com/arangodb/kube-arangodb/pkg/deployment/member"
|
||||
"github.com/arangodb/kube-arangodb/pkg/server"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
||||
)
|
||||
|
@ -219,11 +220,7 @@ func (d *Deployment) DatabaseURL() string {
|
|||
func (d *Deployment) DatabaseVersion() (string, string) {
|
||||
status, _ := d.GetStatus()
|
||||
if current := status.CurrentImage; current != nil {
|
||||
license := "community"
|
||||
if current.Enterprise {
|
||||
license = "enterprise"
|
||||
}
|
||||
return string(current.ArangoDBVersion), license
|
||||
return string(current.ArangoDBVersion), memberState.GetImageLicense(status.CurrentImage)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue