Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions pkg/deployment/deployment_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/deployment_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
45 changes: 38 additions & 7 deletions pkg/deployment/resources/inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}
6 changes: 3 additions & 3 deletions pkg/deployment/resources/inspector/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down Expand Up @@ -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()))
}
Expand All @@ -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()))

Expand Down
27 changes: 27 additions & 0 deletions pkg/util/k8sutil/inspector/arangodeployment/arangodeployment.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions pkg/util/k8sutil/inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -60,6 +61,8 @@ type Inspector interface {
server.Inspector
endpoints.Inspector

arangodeployment.Inspector

node.Inspector
arangoclustersynchronization.Inspector
arangotask.Inspector
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/kclient/helpers/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")()
Expand All @@ -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")()
Expand All @@ -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")()
Expand Down Expand Up @@ -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")()
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/tests/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down