1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] ArangoDeployment Inspector (#972)

This commit is contained in:
Adam Janikowski 2022-05-02 09:52:00 +02:00 committed by GitHub
parent b7f720492a
commit 45fefbaf1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 80 additions and 24 deletions

View file

@ -2,6 +2,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) Add CoreV1 Endpoints Inspector
- (Feature) Add Current ArangoDeployment Inspector
## [1.2.11](https://github.com/arangodb/kube-arangodb/tree/1.2.11) (2022-04-30)
- (Bugfix) Orphan PVC are not removed

View file

@ -245,7 +245,7 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
eventCh: make(chan *deploymentEvent, deploymentEventQueueSize),
stopCh: make(chan struct{}),
agencyCache: agency.NewCache(apiObject.Spec.Mode),
currentState: inspector.NewInspector(newDeploymentThrottle(), deps.Client, apiObject.GetNamespace()),
currentState: inspector.NewInspector(newDeploymentThrottle(), deps.Client, apiObject.GetNamespace(), apiObject.GetName()),
}
d.memberState = memberState.NewStateInspector(d)

View file

@ -44,7 +44,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/upgrade"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
@ -81,12 +80,7 @@ func (d *Deployment) inspectDeployment(lastInterval util.Interval) util.Interval
}
// Check deployment still exists
var updated *api.ArangoDeployment
err = globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctxReconciliation, func(ctxChild context.Context) error {
var err error
updated, err = d.deps.Client.Arango().DatabaseV1().ArangoDeployments(d.GetNamespace()).Get(ctxChild, deploymentName, meta.GetOptions{})
return err
})
updated, err := d.currentState.GetCurrentArangoDeployment()
if k8sutil.IsNotFound(err) {
// Deployment is gone
log.Info().Msg("Deployment is gone")

View file

@ -487,7 +487,7 @@ func createTestDeployment(t *testing.T, config Config, arangoDeployment *api.Ara
deps: deps,
eventCh: make(chan *deploymentEvent, deploymentEventQueueSize),
stopCh: make(chan struct{}),
currentState: inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), deps.Client, arangoDeployment.GetNamespace()),
currentState: inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), deps.Client, arangoDeployment.GetNamespace(), arangoDeployment.GetName()),
}
d.clientCache = client.NewClientCache(d, conn.NewFactory(d.getAuth, d.getConnConfig))

View file

@ -27,8 +27,10 @@ import (
"time"
"github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember"
@ -45,6 +47,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/rs/zerolog"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var (
@ -99,26 +102,36 @@ type inspectorLoader interface {
var _ inspector.Inspector = &inspectorState{}
func NewInspector(throttles throttle.Components, client kclient.Client, namespace string) inspector.Inspector {
func NewInspector(throttles throttle.Components, client kclient.Client, namespace, deploymentName string) inspector.Inspector {
if throttles == nil {
throttles = throttle.NewAlwaysThrottleComponents()
}
i := &inspectorState{
namespace: namespace,
client: client,
throttles: throttles,
logger: logging.GlobalLogger().MustGetLogger(logging.LoggerNameInspector),
namespace: namespace,
deploymentName: deploymentName,
client: client,
throttles: throttles,
logger: logging.GlobalLogger().MustGetLogger(logging.LoggerNameInspector),
}
return i
}
type inspectorStateDeploymentResult struct {
depl *api.ArangoDeployment
err error
}
type inspectorState struct {
lock sync.Mutex
namespace string
client kclient.Client
namespace string
deploymentName string
deploymentResult *inspectorStateDeploymentResult
client kclient.Client
last time.Time
@ -144,6 +157,14 @@ type inspectorState struct {
initialised bool
}
func (i *inspectorState) GetCurrentArangoDeployment() (*api.ArangoDeployment, error) {
if i.deploymentResult == nil {
return nil, errors.Newf("Deployment not initialised")
}
return i.deploymentResult.depl, i.deploymentResult.err
}
func (i *inspectorState) Endpoints() endpoints.Definition {
return i.endpoints
}
@ -248,6 +269,12 @@ func (i *inspectorState) refreshInThreads(ctx context.Context, threads int, load
}
start := time.Now()
i.logger.Debug().Msg("Pre-inspector refresh start")
d, err := i.client.Arango().DatabaseV1().ArangoDeployments(i.namespace).Get(context.Background(), i.deploymentName, meta.GetOptions{})
n.deploymentResult = &inspectorStateDeploymentResult{
depl: d,
err: err,
}
i.logger.Debug().Msg("Inspector refresh start")
@ -298,6 +325,8 @@ func (i *inspectorState) refreshInThreads(ctx context.Context, threads int, load
loaders[id].Copy(n, i, true)
}
i.deploymentResult = n.deploymentResult
i.throttles = n.throttles
i.last = time.Now()
@ -361,6 +390,7 @@ func (i *inspectorState) validate() error {
func (i *inspectorState) copyCore() *inspectorState {
return &inspectorState{
namespace: i.namespace,
deploymentName: i.deploymentName,
client: i.client,
pods: i.pods,
secrets: i.secrets,
@ -376,6 +406,7 @@ func (i *inspectorState) copyCore() *inspectorState {
throttles: i.throttles.Copy(),
versionInfo: i.versionInfo,
endpoints: i.endpoints,
deploymentResult: i.deploymentResult,
logger: i.logger,
}
}

View file

@ -135,7 +135,7 @@ func Test_Inspector_RefreshMatrix(t *testing.T) {
tc := throttle.NewThrottleComponents(time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour)
i := NewInspector(tc, c, "test")
i := NewInspector(tc, c, "test", "test")
require.NoError(t, i.Refresh(context.Background()))
@ -285,7 +285,7 @@ func getTimes(i inspector.Inspector) map[string]time.Time {
func Test_Inspector_Load(t *testing.T) {
c := kclient.NewFakeClient()
i := NewInspector(throttle.NewAlwaysThrottleComponents(), c, "test")
i := NewInspector(throttle.NewAlwaysThrottleComponents(), c, "test", "test")
require.NoError(t, i.Refresh(context.Background()))
}
@ -295,7 +295,7 @@ func Test_Inspector_Invalidate(t *testing.T) {
tc := throttle.NewThrottleComponents(time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour, time.Hour)
i := NewInspector(tc, c, "test")
i := NewInspector(tc, c, "test", "test")
require.NoError(t, i.Refresh(context.Background()))

View file

@ -0,0 +1,27 @@
//
// 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 arangodeployment
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
type Inspector interface {
GetCurrentArangoDeployment() (*api.ArangoDeployment, error)
}

View file

@ -26,6 +26,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/server"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangodeployment"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints"
@ -60,6 +61,8 @@ type Inspector interface {
server.Inspector
endpoints.Inspector
arangodeployment.Inspector
node.Inspector
arangoclustersynchronization.Inspector
arangotask.Inspector

View file

@ -36,7 +36,7 @@ func Test_SecretConfigGetter(t *testing.T) {
t.Run("Missing secret", func(t *testing.T) {
c := kclient.NewFakeClient()
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default")
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default", "default")
require.NoError(t, i.Refresh(context.Background()))
_, _, err := SecretConfigGetter(i, "secret", "key")()
@ -56,7 +56,7 @@ func Test_SecretConfigGetter(t *testing.T) {
_, err := c.Kubernetes().CoreV1().Secrets("default").Create(context.Background(), &s, meta.CreateOptions{})
require.NoError(t, err)
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default")
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default", "default")
require.NoError(t, i.Refresh(context.Background()))
_, _, err = SecretConfigGetter(i, "secret", "key")()
@ -81,7 +81,7 @@ random data
_, err := c.Kubernetes().CoreV1().Secrets("default").Create(context.Background(), &s, meta.CreateOptions{})
require.NoError(t, err)
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default")
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default", "default")
require.NoError(t, i.Refresh(context.Background()))
_, _, err = SecretConfigGetter(i, "secret", "key")()
@ -123,7 +123,7 @@ users:
_, err := c.Kubernetes().CoreV1().Secrets("default").Create(context.Background(), &s, meta.CreateOptions{})
require.NoError(t, err)
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default")
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, "default", "default")
require.NoError(t, i.Refresh(context.Background()))
_, _, err = SecretConfigGetter(i, "secret", "key")()

View file

@ -33,7 +33,7 @@ import (
const FakeNamespace = "fake"
func NewInspector(t *testing.T, c kclient.Client) inspectorInterface.Inspector {
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, FakeNamespace)
i := inspector.NewInspector(throttle.NewAlwaysThrottleComponents(), c, FakeNamespace, FakeNamespace)
require.NoError(t, i.Refresh(context.Background()))
return i