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

[Refactoring] Extract Inspector Definitions package (#1163)

This commit is contained in:
Adam Janikowski 2022-11-02 04:38:37 -04:00 committed by GitHub
parent 5a229fa7f8
commit fe434ef24a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 169 additions and 101 deletions

View file

@ -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

View file

@ -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)))
}
}

View file

@ -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 {

View file

@ -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,
}
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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 {

View file

@ -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{}) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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,
}
}

View file

@ -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"
)

View file

@ -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()