1
0
Fork 0
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:
Nikita Vanyasin 2022-05-10 11:48:03 +04:00 committed by GitHub
parent b3b9da0574
commit 9d9d5e2dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 36 deletions

View file

@ -1,6 +1,7 @@
# Change Log # Change Log
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) ## [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) ## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10)
- (Feature) Add CoreV1 Endpoints Inspector - (Feature) Add CoreV1 Endpoints Inspector

View 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"
}

View file

@ -78,7 +78,7 @@ func (s *stateInspector) Log(logger zerolog.Logger) {
defer s.lock.Unlock() defer s.lock.Unlock()
for m, s := range s.members { 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") 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) { members.ForEach(func(id int) {
if members[id].Group.IsArangosync() { if members[id].Group.IsArangosync() {
return results[id] = s.fetchArangosyncMemberState(nctx, members[id])
}
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
} else { } 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) c, err := s.client.GetDatabaseClient(ctx)
if err != nil { if err != nil {
cs.Reachable = err cs.NotReachableErr = err
} else { } else {
v, err := c.Version(gctx) v, err := c.Version(gctx)
if err != nil { if err != nil {
cs.Reachable = err cs.NotReachableErr = err
} else { } else {
cs.Version = v cs.Version = v
} }
@ -155,6 +142,46 @@ func (s *stateInspector) RefreshState(ctx context.Context, members api.Deploymen
s.health = h 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) { func (s *stateInspector) MemberState(id string) (State, bool) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
@ -175,24 +202,15 @@ type Health struct {
} }
type State struct { type State struct {
Reachable error NotReachableErr error
Version driver.VersionInfo Version driver.VersionInfo
} }
func (s State) IsReachable() bool { func (s State) IsReachable() bool {
return s.Reachable == nil return s.NotReachableErr == nil
} }
func (s State) Log(event *zerolog.Event) *zerolog.Event { func (s State) Log(event *zerolog.Event) *zerolog.Event {
if !s.IsReachable() { return event.Bool("reachable", s.IsReachable()).AnErr("reachableError", s.NotReachableErr)
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()
} }

View file

@ -23,6 +23,8 @@ package reconciler
import ( import (
"context" "context"
core "k8s.io/api/core/v1"
"github.com/arangodb/arangosync-client/client" "github.com/arangodb/arangosync-client/client"
"github.com/arangodb/go-driver" "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/agency" "github.com/arangodb/go-driver/agency"
@ -38,7 +40,6 @@ import (
servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1" servicev1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/service/v1"
serviceaccountv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/serviceaccount/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" 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 // ServerGroupIterator provides a helper to callback on every server
@ -191,4 +192,5 @@ type DeploymentClient interface {
DeploymentAgencyClient DeploymentAgencyClient
DeploymentDatabaseClient DeploymentDatabaseClient
DeploymentMemberClient DeploymentMemberClient
DeploymentSyncClient
} }

View file

@ -29,6 +29,7 @@ import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/apis/shared" "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/server"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
) )
@ -219,11 +220,7 @@ func (d *Deployment) DatabaseURL() string {
func (d *Deployment) DatabaseVersion() (string, string) { func (d *Deployment) DatabaseVersion() (string, string) {
status, _ := d.GetStatus() status, _ := d.GetStatus()
if current := status.CurrentImage; current != nil { if current := status.CurrentImage; current != nil {
license := "community" return string(current.ArangoDBVersion), memberState.GetImageLicense(status.CurrentImage)
if current.Enterprise {
license = "enterprise"
}
return string(current.ArangoDBVersion), license
} }
return "", "" return "", ""
} }