From fe434ef24a12c7b3b6d604943824eb8c81bfb802 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Wed, 2 Nov 2022 04:38:37 -0400 Subject: [PATCH] [Refactoring] Extract Inspector Definitions package (#1163) --- CHANGELOG.md | 1 + pkg/deployment/old_metrics.go | 4 +- pkg/deployment/reconcile/action.go | 6 +- .../action_runtime_container_args_udpate.go | 8 +- pkg/deployment/resources/inspector/acs.go | 5 +- pkg/deployment/resources/inspector/am.go | 5 +- pkg/deployment/resources/inspector/at.go | 5 +- .../resources/inspector/endpoints.go | 5 +- .../resources/inspector/inspector.go | 19 ++--- .../resources/inspector/k8s_informer.go | 6 +- pkg/deployment/resources/inspector/nodes.go | 5 +- pkg/deployment/resources/inspector/pdbs.go | 5 +- pkg/deployment/resources/inspector/pods.go | 5 +- pkg/deployment/resources/inspector/pvcs.go | 5 +- pkg/deployment/resources/inspector/sa.go | 5 +- pkg/deployment/resources/inspector/secrets.go | 5 +- .../resources/inspector/services.go | 5 +- pkg/deployment/resources/inspector/sm.go | 5 +- .../inspector/definitions/components.go | 57 ++++++++++++++ .../k8sutil/inspector/definitions/verbs.go | 31 ++++++++ .../k8sutil/inspector/throttle/throttle.go | 78 ++++++------------- 21 files changed, 169 insertions(+), 101 deletions(-) create mode 100644 pkg/util/k8sutil/inspector/definitions/components.go create mode 100644 pkg/util/k8sutil/inspector/definitions/verbs.go diff --git a/CHANGELOG.md b/CHANGELOG.md index ac1044fd9..d8effcc57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - (Documentation) (1.3.0) EE & CE Definitions - (Improvement) Arango Kubernetes Client Mod Implementation - (Refactoring) Extract kerrors package +- (Refactoring) Extract Inspector Definitions package ## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25) - (Feature) Add action progress diff --git a/pkg/deployment/old_metrics.go b/pkg/deployment/old_metrics.go index 2ef32bdd0..c40d16088 100644 --- a/pkg/deployment/old_metrics.go +++ b/pkg/deployment/old_metrics.go @@ -28,7 +28,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/features" "github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" "github.com/arangodb/kube-arangodb/pkg/util/metrics" ) @@ -89,7 +89,7 @@ func (i *inventory) Collect(m chan<- prometheus.Metric) { if state := deployment.acs.CurrentClusterCache(); state != nil { t := state.GetThrottles() - for _, c := range throttle.AllComponents() { + for _, c := range definitions.AllComponents() { p.Push(i.operatorStateRefreshMetric.Gauge(float64(t.Get(c).Count()), deployment.GetNamespace(), deployment.GetName(), string(c))) } } diff --git a/pkg/deployment/reconcile/action.go b/pkg/deployment/reconcile/action.go index 16c1451a8..0690dcb89 100644 --- a/pkg/deployment/reconcile/action.go +++ b/pkg/deployment/reconcile/action.go @@ -29,7 +29,7 @@ import ( "k8s.io/apimachinery/pkg/types" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) const ( @@ -86,10 +86,10 @@ type ActionReloadCachedStatus interface { Action // ReloadComponents return cache components to be reloaded - ReloadComponents() (types.UID, []throttle.Component) + ReloadComponents() (types.UID, []definitions.Component) } -func getActionReloadCachedStatus(a Action) (types.UID, []throttle.Component) { +func getActionReloadCachedStatus(a Action) (types.UID, []definitions.Component) { if c, ok := a.(ActionReloadCachedStatus); !ok { return "", nil } else { diff --git a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go index 79db138ec..2c802a767 100644 --- a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go +++ b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go @@ -32,7 +32,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/rotation" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) func newRuntimeContainerArgsLogLevelUpdateAction(action api.Action, actionCtx ActionContext) Action { @@ -114,9 +114,9 @@ func (a actionRuntimeContainerArgsLogLevelUpdate) Post(ctx context.Context) erro return nil } -func (a *actionRuntimeContainerArgsLogLevelUpdate) ReloadComponents() []throttle.Component { - return []throttle.Component{ - throttle.Pod, +func (a *actionRuntimeContainerArgsLogLevelUpdate) ReloadComponents() []definitions.Component { + return []definitions.Component{ + definitions.Pod, } } diff --git a/pkg/deployment/resources/inspector/acs.go b/pkg/deployment/resources/inspector/acs.go index e66b657fd..3a0d656ca 100644 --- a/pkg/deployment/resources/inspector/acs.go +++ b/pkg/deployment/resources/inspector/acs.go @@ -29,6 +29,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/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" ) @@ -41,8 +42,8 @@ var arangoClusterSynchronizationsInspectorLoaderObj = arangoClusterSynchronizati type arangoClusterSynchronizationsInspectorLoader struct { } -func (p arangoClusterSynchronizationsInspectorLoader) Component() throttle.Component { - return throttle.ArangoClusterSynchronization +func (p arangoClusterSynchronizationsInspectorLoader) Component() definitions.Component { + return definitions.ArangoClusterSynchronization } func (p arangoClusterSynchronizationsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/am.go b/pkg/deployment/resources/inspector/am.go index 8a6d13ccb..ee2a547fc 100644 --- a/pkg/deployment/resources/inspector/am.go +++ b/pkg/deployment/resources/inspector/am.go @@ -29,6 +29,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/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" ) @@ -41,8 +42,8 @@ var arangoMembersInspectorLoaderObj = arangoMembersInspectorLoader{} type arangoMembersInspectorLoader struct { } -func (p arangoMembersInspectorLoader) Component() throttle.Component { - return throttle.ArangoMember +func (p arangoMembersInspectorLoader) Component() definitions.Component { + return definitions.ArangoMember } func (p arangoMembersInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/at.go b/pkg/deployment/resources/inspector/at.go index e6d604bde..2bb4d9b90 100644 --- a/pkg/deployment/resources/inspector/at.go +++ b/pkg/deployment/resources/inspector/at.go @@ -29,6 +29,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/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" ) @@ -41,8 +42,8 @@ var arangoTasksInspectorLoaderObj = arangoTasksInspectorLoader{} type arangoTasksInspectorLoader struct { } -func (p arangoTasksInspectorLoader) Component() throttle.Component { - return throttle.ArangoTask +func (p arangoTasksInspectorLoader) Component() definitions.Component { + return definitions.ArangoTask } func (p arangoTasksInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/endpoints.go b/pkg/deployment/resources/inspector/endpoints.go index ad3a0b9ce..bb8a6b3a6 100644 --- a/pkg/deployment/resources/inspector/endpoints.go +++ b/pkg/deployment/resources/inspector/endpoints.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var endpointsInspectorLoaderObj = endpointsInspectorLoader{} type endpointsInspectorLoader struct { } -func (p endpointsInspectorLoader) Component() throttle.Component { - return throttle.Endpoints +func (p endpointsInspectorLoader) Component() definitions.Component { + return definitions.Endpoints } func (p endpointsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/inspector.go b/pkg/deployment/resources/inspector/inspector.go index a3a595bbc..f2cb4d223 100644 --- a/pkg/deployment/resources/inspector/inspector.go +++ b/pkg/deployment/resources/inspector/inspector.go @@ -43,6 +43,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoclustersynchronization" "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/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/persistentvolumeclaim" @@ -81,7 +82,7 @@ func (i inspectorLoaders) Get(name string) int { type inspectorLoader interface { Name() string - Component() throttle.Component + Component() definitions.Component Load(context context.Context, i *inspectorState) @@ -145,14 +146,14 @@ type inspectorState struct { } func (i *inspectorState) RegisterInformers(k8s informers.SharedInformerFactory, arango arangoInformer.SharedInformerFactory) { - k8s.Core().V1().Nodes().Informer().AddEventHandler(i.eventHandler(throttle.Node)) - k8s.Core().V1().PersistentVolumeClaims().Informer().AddEventHandler(i.eventHandler(throttle.PersistentVolumeClaim)) - k8s.Policy().V1().PodDisruptionBudgets().Informer().AddEventHandler(i.eventHandler(throttle.PodDisruptionBudget)) - k8s.Policy().V1beta1().PodDisruptionBudgets().Informer().AddEventHandler(i.eventHandler(throttle.PodDisruptionBudget)) - k8s.Core().V1().Secrets().Informer().AddEventHandler(i.eventHandler(throttle.Secret)) - k8s.Core().V1().Services().Informer().AddEventHandler(i.eventHandler(throttle.Service)) - k8s.Core().V1().ServiceAccounts().Informer().AddEventHandler(i.eventHandler(throttle.ServiceAccount)) - k8s.Core().V1().Endpoints().Informer().AddEventHandler(i.eventHandler(throttle.Endpoints)) + k8s.Core().V1().Nodes().Informer().AddEventHandler(i.eventHandler(definitions.Node)) + k8s.Core().V1().PersistentVolumeClaims().Informer().AddEventHandler(i.eventHandler(definitions.PersistentVolumeClaim)) + k8s.Policy().V1().PodDisruptionBudgets().Informer().AddEventHandler(i.eventHandler(definitions.PodDisruptionBudget)) + k8s.Policy().V1beta1().PodDisruptionBudgets().Informer().AddEventHandler(i.eventHandler(definitions.PodDisruptionBudget)) + k8s.Core().V1().Secrets().Informer().AddEventHandler(i.eventHandler(definitions.Secret)) + k8s.Core().V1().Services().Informer().AddEventHandler(i.eventHandler(definitions.Service)) + k8s.Core().V1().ServiceAccounts().Informer().AddEventHandler(i.eventHandler(definitions.ServiceAccount)) + k8s.Core().V1().Endpoints().Informer().AddEventHandler(i.eventHandler(definitions.Endpoints)) } func extractGVKFromOwnerReference(o meta.OwnerReference) schema.GroupVersionKind { diff --git a/pkg/deployment/resources/inspector/k8s_informer.go b/pkg/deployment/resources/inspector/k8s_informer.go index af457e2a7..c5649416e 100644 --- a/pkg/deployment/resources/inspector/k8s_informer.go +++ b/pkg/deployment/resources/inspector/k8s_informer.go @@ -23,10 +23,10 @@ package inspector import ( "k8s.io/client-go/tools/cache" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) -func (i *inspectorState) eventHandler(component throttle.Component) cache.ResourceEventHandler { +func (i *inspectorState) eventHandler(component definitions.Component) cache.ResourceEventHandler { return eventHandler{ i: i, component: component, @@ -35,7 +35,7 @@ func (i *inspectorState) eventHandler(component throttle.Component) cache.Resour type eventHandler struct { i *inspectorState - component throttle.Component + component definitions.Component } func (e eventHandler) OnAdd(obj interface{}) { diff --git a/pkg/deployment/resources/inspector/nodes.go b/pkg/deployment/resources/inspector/nodes.go index e8f9775cc..4227ee04d 100644 --- a/pkg/deployment/resources/inspector/nodes.go +++ b/pkg/deployment/resources/inspector/nodes.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var nodesInspectorLoaderObj = nodesInspectorLoader{} type nodesInspectorLoader struct { } -func (p nodesInspectorLoader) Component() throttle.Component { - return throttle.Node +func (p nodesInspectorLoader) Component() definitions.Component { + return definitions.Node } func (p nodesInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/pdbs.go b/pkg/deployment/resources/inspector/pdbs.go index c1d4a2b29..c07b3e2e0 100644 --- a/pkg/deployment/resources/inspector/pdbs.go +++ b/pkg/deployment/resources/inspector/pdbs.go @@ -32,6 +32,7 @@ import ( "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" ) @@ -44,8 +45,8 @@ var podDisruptionBudgetsInspectorLoaderObj = podDisruptionBudgetsInspectorLoader type podDisruptionBudgetsInspectorLoader struct { } -func (p podDisruptionBudgetsInspectorLoader) Component() throttle.Component { - return throttle.PodDisruptionBudget +func (p podDisruptionBudgetsInspectorLoader) Component() definitions.Component { + return definitions.PodDisruptionBudget } func (p podDisruptionBudgetsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/pods.go b/pkg/deployment/resources/inspector/pods.go index e14d4a00c..7623aac8d 100644 --- a/pkg/deployment/resources/inspector/pods.go +++ b/pkg/deployment/resources/inspector/pods.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var podsInspectorLoaderObj = podsInspectorLoader{} type podsInspectorLoader struct { } -func (p podsInspectorLoader) Component() throttle.Component { - return throttle.Pod +func (p podsInspectorLoader) Component() definitions.Component { + return definitions.Pod } func (p podsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/pvcs.go b/pkg/deployment/resources/inspector/pvcs.go index 5cdd2ad6c..3885e0e3a 100644 --- a/pkg/deployment/resources/inspector/pvcs.go +++ b/pkg/deployment/resources/inspector/pvcs.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var persistentVolumeClaimsInspectorLoaderObj = persistentVolumeClaimsInspectorLo type persistentVolumeClaimsInspectorLoader struct { } -func (p persistentVolumeClaimsInspectorLoader) Component() throttle.Component { - return throttle.PersistentVolumeClaim +func (p persistentVolumeClaimsInspectorLoader) Component() definitions.Component { + return definitions.PersistentVolumeClaim } func (p persistentVolumeClaimsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/sa.go b/pkg/deployment/resources/inspector/sa.go index 8b5245e91..f825eaf6f 100644 --- a/pkg/deployment/resources/inspector/sa.go +++ b/pkg/deployment/resources/inspector/sa.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var serviceAccountsInspectorLoaderObj = serviceAccountsInspectorLoader{} type serviceAccountsInspectorLoader struct { } -func (p serviceAccountsInspectorLoader) Component() throttle.Component { - return throttle.ServiceAccount +func (p serviceAccountsInspectorLoader) Component() definitions.Component { + return definitions.ServiceAccount } func (p serviceAccountsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/secrets.go b/pkg/deployment/resources/inspector/secrets.go index 5045afc25..13dbc9555 100644 --- a/pkg/deployment/resources/inspector/secrets.go +++ b/pkg/deployment/resources/inspector/secrets.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var secretsInspectorLoaderObj = secretsInspectorLoader{} type secretsInspectorLoader struct { } -func (p secretsInspectorLoader) Component() throttle.Component { - return throttle.Secret +func (p secretsInspectorLoader) Component() definitions.Component { + return definitions.Secret } func (p secretsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/services.go b/pkg/deployment/resources/inspector/services.go index 5911a3882..86f978d39 100644 --- a/pkg/deployment/resources/inspector/services.go +++ b/pkg/deployment/resources/inspector/services.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var servicesInspectorLoaderObj = servicesInspectorLoader{} type servicesInspectorLoader struct { } -func (p servicesInspectorLoader) Component() throttle.Component { - return throttle.Service +func (p servicesInspectorLoader) Component() definitions.Component { + return definitions.Service } func (p servicesInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/deployment/resources/inspector/sm.go b/pkg/deployment/resources/inspector/sm.go index 15d02cebf..2e7bcbb1f 100644 --- a/pkg/deployment/resources/inspector/sm.go +++ b/pkg/deployment/resources/inspector/sm.go @@ -29,6 +29,7 @@ import ( "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" ) @@ -41,8 +42,8 @@ var serviceMonitorsInspectorLoaderObj = serviceMonitorsInspectorLoader{} type serviceMonitorsInspectorLoader struct { } -func (p serviceMonitorsInspectorLoader) Component() throttle.Component { - return throttle.ServiceMonitor +func (p serviceMonitorsInspectorLoader) Component() definitions.Component { + return definitions.ServiceMonitor } func (p serviceMonitorsInspectorLoader) Load(ctx context.Context, i *inspectorState) { diff --git a/pkg/util/k8sutil/inspector/definitions/components.go b/pkg/util/k8sutil/inspector/definitions/components.go new file mode 100644 index 000000000..e68d483c2 --- /dev/null +++ b/pkg/util/k8sutil/inspector/definitions/components.go @@ -0,0 +1,57 @@ +// +// 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 definitions + +type ComponentCount map[Component]int + +type Component string + +const ( + ArangoClusterSynchronization Component = "ArangoClusterSynchronization" + ArangoMember Component = "ArangoMember" + ArangoTask Component = "ArangoTask" + Node Component = "Node" + PersistentVolumeClaim Component = "PersistentVolumeClaim" + Pod Component = "Pod" + PodDisruptionBudget Component = "PodDisruptionBudget" + Secret Component = "Secret" + Service Component = "Service" + ServiceAccount Component = "ServiceAccount" + ServiceMonitor Component = "ServiceMonitor" + Endpoints Component = "Endpoints" +) + +func AllComponents() []Component { + return []Component{ + ArangoClusterSynchronization, + ArangoMember, + ArangoTask, + Node, + PersistentVolumeClaim, + Pod, + PodDisruptionBudget, + Secret, + Service, + ServiceAccount, + ServiceMonitor, + Endpoints, + } +} diff --git a/pkg/util/k8sutil/inspector/definitions/verbs.go b/pkg/util/k8sutil/inspector/definitions/verbs.go new file mode 100644 index 000000000..24e60807c --- /dev/null +++ b/pkg/util/k8sutil/inspector/definitions/verbs.go @@ -0,0 +1,31 @@ +// +// 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 definitions + +type Verb string + +const ( + Create Verb = "create" + Delete Verb = "delete" + Get Verb = "get" + Patch Verb = "patch" + Update Verb = "update" +) diff --git a/pkg/util/k8sutil/inspector/throttle/throttle.go b/pkg/util/k8sutil/inspector/throttle/throttle.go index f042c36fd..96ae590df 100644 --- a/pkg/util/k8sutil/inspector/throttle/throttle.go +++ b/pkg/util/k8sutil/inspector/throttle/throttle.go @@ -23,6 +23,8 @@ package throttle import ( "sync" "time" + + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) type Inspector interface { @@ -50,42 +52,6 @@ func NewThrottleComponents(acs, am, at, node, pvc, pod, pdb, secret, service, se } } -type ComponentCount map[Component]int - -type Component string - -const ( - ArangoClusterSynchronization Component = "ArangoClusterSynchronization" - ArangoMember Component = "ArangoMember" - ArangoTask Component = "ArangoTask" - Node Component = "Node" - PersistentVolumeClaim Component = "PersistentVolumeClaim" - Pod Component = "Pod" - PodDisruptionBudget Component = "PodDisruptionBudget" - Secret Component = "Secret" - Service Component = "Service" - ServiceAccount Component = "ServiceAccount" - ServiceMonitor Component = "ServiceMonitor" - Endpoints Component = "Endpoints" -) - -func AllComponents() []Component { - return []Component{ - ArangoClusterSynchronization, - ArangoMember, - ArangoTask, - Node, - PersistentVolumeClaim, - Pod, - PodDisruptionBudget, - Secret, - Service, - ServiceAccount, - ServiceMonitor, - Endpoints, - } -} - type Components interface { ArangoClusterSynchronization() Throttle ArangoMember() Throttle @@ -100,10 +66,10 @@ type Components interface { ServiceMonitor() Throttle Endpoints() Throttle - Get(c Component) Throttle - Invalidate(components ...Component) + Get(c definitions.Component) Throttle + Invalidate(components ...definitions.Component) - Counts() ComponentCount + Counts() definitions.ComponentCount Copy() Components } @@ -126,50 +92,50 @@ func (t *throttleComponents) Endpoints() Throttle { return t.endpoints } -func (t *throttleComponents) Counts() ComponentCount { - z := ComponentCount{} +func (t *throttleComponents) Counts() definitions.ComponentCount { + z := definitions.ComponentCount{} - for _, c := range AllComponents() { + for _, c := range definitions.AllComponents() { z[c] = t.Get(c).Count() } return z } -func (t *throttleComponents) Invalidate(components ...Component) { +func (t *throttleComponents) Invalidate(components ...definitions.Component) { for _, c := range components { t.Get(c).Invalidate() } } -func (t *throttleComponents) Get(c Component) Throttle { +func (t *throttleComponents) Get(c definitions.Component) Throttle { if t == nil { return NewAlwaysThrottle() } switch c { - case ArangoClusterSynchronization: + case definitions.ArangoClusterSynchronization: return t.arangoClusterSynchronization - case ArangoMember: + case definitions.ArangoMember: return t.arangoMember - case ArangoTask: + case definitions.ArangoTask: return t.arangoTask - case Node: + case definitions.Node: return t.node - case PersistentVolumeClaim: + case definitions.PersistentVolumeClaim: return t.persistentVolumeClaim - case Pod: + case definitions.Pod: return t.pod - case PodDisruptionBudget: + case definitions.PodDisruptionBudget: return t.podDisruptionBudget - case Secret: + case definitions.Secret: return t.secret - case Service: + case definitions.Service: return t.service - case ServiceAccount: + case definitions.ServiceAccount: return t.serviceAccount - case ServiceMonitor: + case definitions.ServiceMonitor: return t.serviceMonitor - case Endpoints: + case definitions.Endpoints: return t.endpoints default: return NewAlwaysThrottle()