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

[Feature] PersistentVolume Inspector (#1309)

This commit is contained in:
Adam Janikowski 2023-05-19 09:18:25 +02:00 committed by GitHub
parent 2da8a752be
commit 7a806359af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 634 additions and 10 deletions

View file

@ -3,6 +3,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) ArangoBackup create retries and MaxIterations limit
- (Feature) Add Reason in OOM Metric
- (Feature) PersistentVolume Inspector
## [1.2.27](https://github.com/arangodb/kube-arangodb/tree/1.2.27) (2023-04-27)
- (Feature) Add InSync Cache

View file

@ -46,6 +46,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget"
@ -128,6 +129,7 @@ type inspectorState struct {
services *servicesInspector
serviceAccounts *serviceAccountsInspector
nodes *nodesInspector
persistentVolumes *persistentVolumesInspector
podDisruptionBudgets *podDisruptionBudgetsInspector
serviceMonitors *serviceMonitorsInspector
arangoMembers *arangoMembersInspector
@ -218,6 +220,7 @@ func (i *inspectorState) AnonymousObjects() []anonymous.Impl {
i.services,
i.serviceAccounts,
i.nodes,
i.persistentVolumes,
i.podDisruptionBudgets,
i.serviceMonitors,
i.arangoMembers,
@ -302,6 +305,10 @@ func (i *inspectorState) Node() node.Definition {
return i.nodes
}
func (i *inspectorState) PersistentVolume() persistentvolume.Definition {
return i.persistentVolumes
}
func (i *inspectorState) ArangoClusterSynchronization() arangoclustersynchronization.Definition {
return i.arangoClusterSynchronizations
}
@ -441,6 +448,10 @@ func (i *inspectorState) validate() error {
return err
}
if err := i.persistentVolumes.validate(); err != nil {
return err
}
if err := i.podDisruptionBudgets.validate(); err != nil {
return err
}
@ -479,6 +490,7 @@ func (i *inspectorState) copyCore() *inspectorState {
services: i.services,
serviceAccounts: i.serviceAccounts,
nodes: i.nodes,
persistentVolumes: i.persistentVolumes,
podDisruptionBudgets: i.podDisruptionBudgets,
serviceMonitors: i.serviceMonitors,
arangoMembers: i.arangoMembers,

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 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.
@ -71,6 +71,14 @@ var loaderTestDefinitions = map[string]loaderTestDefinition{
return i.Node()
},
},
"PersistentVolume": {
tg: func(t throttle.Components) throttle.Throttle {
return t.PersistentVolume()
},
get: func(i inspector.Inspector) refresh.Inspector {
return i.PersistentVolume()
},
},
"Pod": {
tg: func(t throttle.Components) throttle.Throttle {
return t.Pod()
@ -134,7 +142,7 @@ func getAllTypes() []string {
func Test_Inspector_RefreshMatrix(t *testing.T) {
c := kclient.NewFakeClient()
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)
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, time.Hour)
i := NewInspector(tc, c, "test", "test")
@ -294,7 +302,7 @@ func Test_Inspector_Load(t *testing.T) {
func Test_Inspector_Invalidate(t *testing.T) {
c := kclient.NewFakeClient()
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)
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, time.Hour)
i := NewInspector(tc, c, "test", "test")

View file

@ -52,7 +52,7 @@ func Test_PDB_Versions(t *testing.T) {
GitVersion: v,
})
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)
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, time.Hour)
i := NewInspector(tc, c, "test", "test")
require.NoError(t, i.Refresh(context.Background()))

View file

@ -0,0 +1,192 @@
//
// DISCLAIMER
//
// Copyright 2023 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 inspector
import (
"context"
"time"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version"
)
func init() {
requireRegisterInspectorLoader(persistentVolumesInspectorLoaderObj)
}
var persistentVolumesInspectorLoaderObj = persistentVolumesInspectorLoader{}
type persistentVolumesInspectorLoader struct {
}
func (p persistentVolumesInspectorLoader) Component() definitions.Component {
return definitions.PersistentVolume
}
func (p persistentVolumesInspectorLoader) Load(ctx context.Context, i *inspectorState) {
var q persistentVolumesInspector
p.loadV1(ctx, i, &q)
i.persistentVolumes = &q
q.state = i
q.last = time.Now()
}
func (p persistentVolumesInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *persistentVolumesInspector) {
var z persistentVolumesInspectorV1
z.persistentVolumeInspector = q
z.persistentVolumes, z.err = p.getV1PersistentVolumes(ctx, i)
q.v1 = &z
}
func (p persistentVolumesInspectorLoader) getV1PersistentVolumes(ctx context.Context, i *inspectorState) (map[string]*core.PersistentVolume, error) {
objs, err := p.getV1PersistentVolumesList(ctx, i)
if err != nil {
return nil, err
}
r := make(map[string]*core.PersistentVolume, len(objs))
for id := range objs {
r[objs[id].GetName()] = objs[id]
}
return r, nil
}
func (p persistentVolumesInspectorLoader) getV1PersistentVolumesList(ctx context.Context, i *inspectorState) ([]*core.PersistentVolume, error) {
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
defer cancel()
obj, err := i.client.Kubernetes().CoreV1().PersistentVolumes().List(ctxChild, meta.ListOptions{
Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(),
})
if err != nil {
return nil, err
}
items := obj.Items
cont := obj.Continue
var s = int64(len(items))
if z := obj.RemainingItemCount; z != nil {
s += *z
}
ptrs := make([]*core.PersistentVolume, 0, s)
for {
for id := range items {
ptrs = append(ptrs, &items[id])
}
if cont == "" {
break
}
items, cont, err = p.getV1PersistentVolumesListRequest(ctx, i, cont)
if err != nil {
return nil, err
}
}
return ptrs, nil
}
func (p persistentVolumesInspectorLoader) getV1PersistentVolumesListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.PersistentVolume, string, error) {
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
defer cancel()
obj, err := i.client.Kubernetes().CoreV1().PersistentVolumes().List(ctxChild, meta.ListOptions{
Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(),
Continue: cont,
})
if err != nil {
return nil, "", err
}
return obj.Items, obj.Continue, err
}
func (p persistentVolumesInspectorLoader) Verify(i *inspectorState) error {
return nil
}
func (p persistentVolumesInspectorLoader) Copy(from, to *inspectorState, override bool) {
if to.persistentVolumes != nil {
if !override {
return
}
}
to.persistentVolumes = from.persistentVolumes
to.persistentVolumes.state = to
}
func (p persistentVolumesInspectorLoader) Name() string {
return "persistentVolumes"
}
type persistentVolumesInspector struct {
state *inspectorState
last time.Time
v1 *persistentVolumesInspectorV1
}
func (p *persistentVolumesInspector) LastRefresh() time.Time {
return p.last
}
func (p *persistentVolumesInspector) Refresh(ctx context.Context) error {
p.Throttle(p.state.throttles).Invalidate()
return p.state.refresh(ctx, persistentVolumesInspectorLoaderObj)
}
func (p *persistentVolumesInspector) Version() version.Version {
return version.V1
}
func (p *persistentVolumesInspector) Throttle(c throttle.Components) throttle.Throttle {
return c.PersistentVolume()
}
func (p *persistentVolumesInspector) validate() error {
if p == nil {
return errors.Newf("PersistentVolumeInspector is nil")
}
if p.state == nil {
return errors.Newf("Parent is nil")
}
return p.v1.validate()
}

View file

@ -0,0 +1,46 @@
//
// DISCLAIMER
//
// Copyright 2023 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 inspector
import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic"
)
func (p *persistentVolumesInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
g := constants.PersistentVolumeGKv1()
if g.Kind == gvk.Kind && g.Group == gvk.Group {
switch gvk.Version {
case constants.PersistentVolumeVersionV1, DefaultVersion:
if p.v1 == nil || p.v1.err != nil {
return nil, false
}
return anonymous.NewAnonymous[*core.PersistentVolume](g, p.state.persistentVolumes.v1, generic.WithModStatus[*core.PersistentVolume](g, generic.WithEmptyMod[*core.PersistentVolume](g))), true
}
}
return nil, false
}

View file

@ -0,0 +1,43 @@
//
// DISCLAIMER
//
// Copyright 2023 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 inspector
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
)
func (p *persistentVolumesInspectorV1) GroupVersionKind() schema.GroupVersionKind {
return constants.PersistentVolumeGKv1()
}
func (p *persistentVolumesInspectorV1) GroupVersionResource() schema.GroupVersionResource {
return constants.PersistentVolumeGRv1()
}
func (p *persistentVolumesInspector) GroupKind() schema.GroupKind {
return constants.PersistentVolumeGK()
}
func (p *persistentVolumesInspector) GroupResource() schema.GroupResource {
return constants.PersistentVolumeGR()
}

View file

@ -0,0 +1,122 @@
//
// DISCLAIMER
//
// Copyright 2023 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 inspector
import (
"context"
core "k8s.io/api/core/v1"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume/v1"
)
func (p *persistentVolumesInspector) V1() (ins.Inspector, error) {
if p.v1.err != nil {
return nil, p.v1.err
}
return p.v1, nil
}
type persistentVolumesInspectorV1 struct {
persistentVolumeInspector *persistentVolumesInspector
persistentVolumes map[string]*core.PersistentVolume
err error
}
func (p *persistentVolumesInspectorV1) validate() error {
if p == nil {
return errors.Newf("PersistentVolumesV1Inspector is nil")
}
if p.persistentVolumeInspector == nil {
return errors.Newf("Parent is nil")
}
if p.persistentVolumes == nil && p.err == nil {
return errors.Newf("PersistentVolumes or err should be not nil")
}
if p.persistentVolumes != nil && p.err != nil {
return errors.Newf("PersistentVolumes or err cannot be not nil together")
}
return nil
}
func (p *persistentVolumesInspectorV1) ListSimple() []*core.PersistentVolume {
var r []*core.PersistentVolume
for _, persistentVolume := range p.persistentVolumes {
r = append(r, persistentVolume)
}
return r
}
func (p *persistentVolumesInspectorV1) GetSimple(name string) (*core.PersistentVolume, bool) {
persistentVolume, ok := p.persistentVolumes[name]
if !ok {
return nil, false
}
return persistentVolume, true
}
func (p *persistentVolumesInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error {
for _, persistentVolume := range p.persistentVolumes {
if err := p.iteratePersistentVolume(persistentVolume, action, filters...); err != nil {
return err
}
}
return nil
}
func (p *persistentVolumesInspectorV1) iteratePersistentVolume(persistentVolume *core.PersistentVolume, action ins.Action, filters ...ins.Filter) error {
for _, f := range filters {
if f == nil {
continue
}
if !f(persistentVolume) {
return nil
}
}
return action(persistentVolume)
}
func (p *persistentVolumesInspectorV1) Read() ins.ReadInterface {
return p
}
func (p *persistentVolumesInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolume, error) {
if s, ok := p.GetSimple(name); !ok {
return nil, apiErrors.NewNotFound(constants.PersistentVolumeGR(), name)
} else {
return s, nil
}
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 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.
@ -32,6 +32,7 @@ func NewDefaultThrottle() throttle.Components {
30*time.Second, // ArangoMember
30*time.Second, // ArangoTask
30*time.Second, // Node
30*time.Second, // PV
15*time.Second, // PVC
time.Second, // Pod
30*time.Second, // PDB

View file

@ -0,0 +1,64 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 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 constants
import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// PersistentVolume
const (
PersistentVolumeGroup = core.GroupName
PersistentVolumeResource = "persistentvolumes"
PersistentVolumeKind = "PersistentVolume"
PersistentVolumeVersionV1 = "v1"
)
func PersistentVolumeGK() schema.GroupKind {
return schema.GroupKind{
Group: PersistentVolumeGroup,
Kind: PersistentVolumeKind,
}
}
func PersistentVolumeGKv1() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: PersistentVolumeGroup,
Kind: PersistentVolumeKind,
Version: PersistentVolumeVersionV1,
}
}
func PersistentVolumeGR() schema.GroupResource {
return schema.GroupResource{
Group: PersistentVolumeGroup,
Resource: PersistentVolumeResource,
}
}
func PersistentVolumeGRv1() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: PersistentVolumeGroup,
Resource: PersistentVolumeResource,
Version: PersistentVolumeVersionV1,
}
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 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.
@ -29,6 +29,7 @@ const (
ArangoMember Component = "ArangoMember"
ArangoTask Component = "ArangoTask"
Node Component = "Node"
PersistentVolume Component = "PersistentVolume"
PersistentVolumeClaim Component = "PersistentVolumeClaim"
Pod Component = "Pod"
PodDisruptionBudget Component = "PodDisruptionBudget"
@ -45,6 +46,7 @@ func AllComponents() []Component {
ArangoMember,
ArangoTask,
Node,
PersistentVolume,
PersistentVolumeClaim,
Pod,
PodDisruptionBudget,

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 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.
@ -36,6 +36,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/node"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/poddisruptionbudget"
@ -86,6 +87,7 @@ type Inspector interface {
arangodeployment.Inspector
node.Inspector
persistentvolume.Inspector
arangoclustersynchronization.Inspector
arangotask.Inspector

View file

@ -0,0 +1,44 @@
//
// DISCLAIMER
//
// Copyright 2023 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 persistentvolume
import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk"
v1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolume/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/refresh"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version"
)
type Inspector interface {
PersistentVolume() Definition
}
type Definition interface {
refresh.Inspector
gvk.GK
anonymous.Impl
Version() version.Version
V1() (v1.Inspector, error)
}

View file

@ -0,0 +1,39 @@
//
// DISCLAIMER
//
// Copyright 2023 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 v1
import (
core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/gvk"
)
type Inspector interface {
gvk.GVK
ListSimple() []*core.PersistentVolume
GetSimple(name string) (*core.PersistentVolume, bool)
Iterate(action Action, filters ...Filter) error
Read() ReadInterface
}
type Filter func(pv *core.PersistentVolume) bool
type Action func(pv *core.PersistentVolume) error

View file

@ -0,0 +1,38 @@
//
// DISCLAIMER
//
// Copyright 2023 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 v1
import (
"context"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Interface has methods to work with PersistentVolume resources.
type Interface interface {
ReadInterface
}
// ReadInterface has methods to work with PersistentVolume resources with ReadOnly mode.
type ReadInterface interface {
Get(ctx context.Context, name string, opts meta.GetOptions) (*core.PersistentVolume, error)
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 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.
@ -32,15 +32,16 @@ type Inspector interface {
}
func NewAlwaysThrottleComponents() Components {
return NewThrottleComponents(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
return NewThrottleComponents(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}
func NewThrottleComponents(acs, am, at, node, pvc, pod, pdb, secret, service, serviceAccount, sm, endpoints time.Duration) Components {
func NewThrottleComponents(acs, am, at, node, pvc, pod, pv, pdb, secret, service, serviceAccount, sm, endpoints time.Duration) Components {
return &throttleComponents{
arangoClusterSynchronization: NewThrottle(acs),
arangoMember: NewThrottle(am),
arangoTask: NewThrottle(at),
node: NewThrottle(node),
persistentVolume: NewThrottle(pv),
persistentVolumeClaim: NewThrottle(pvc),
pod: NewThrottle(pod),
podDisruptionBudget: NewThrottle(pdb),
@ -57,6 +58,7 @@ type Components interface {
ArangoMember() Throttle
ArangoTask() Throttle
Node() Throttle
PersistentVolume() Throttle
PersistentVolumeClaim() Throttle
Pod() Throttle
PodDisruptionBudget() Throttle
@ -78,6 +80,7 @@ type throttleComponents struct {
arangoMember Throttle
arangoTask Throttle
node Throttle
persistentVolume Throttle
persistentVolumeClaim Throttle
pod Throttle
podDisruptionBudget Throttle
@ -88,6 +91,10 @@ type throttleComponents struct {
endpoints Throttle
}
func (t *throttleComponents) PersistentVolume() Throttle {
return t.persistentVolume
}
func (t *throttleComponents) Endpoints() Throttle {
return t.endpoints
}
@ -121,6 +128,8 @@ func (t *throttleComponents) Get(c definitions.Component) Throttle {
return t.arangoTask
case definitions.Node:
return t.node
case definitions.PersistentVolume:
return t.persistentVolume
case definitions.PersistentVolumeClaim:
return t.persistentVolumeClaim
case definitions.Pod:
@ -148,6 +157,7 @@ func (t *throttleComponents) Copy() Components {
arangoMember: t.arangoMember.Copy(),
arangoTask: t.arangoTask.Copy(),
node: t.node.Copy(),
persistentVolume: t.persistentVolume.Copy(),
persistentVolumeClaim: t.persistentVolumeClaim.Copy(),
pod: t.pod.Copy(),
podDisruptionBudget: t.podDisruptionBudget.Copy(),