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

[Feature] ConfigMap Inspector (#1696)

This commit is contained in:
Adam Janikowski 2024-08-19 18:15:47 +03:00 committed by GitHub
parent 37522ee616
commit 65ada1d111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 733 additions and 14 deletions

View file

@ -5,6 +5,7 @@
- (Feature) ArangoRoute Operator
- (Feature) Add Kubernetes Services for Group
- (Bugfix) Fix Networking Client
- (Feature) ConfigMap Inspector
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

View file

@ -0,0 +1,196 @@
//
// DISCLAIMER
//
// Copyright 2024 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(configMapsInspectorLoaderObj)
}
var configMapsInspectorLoaderObj = configMapsInspectorLoader{}
type configMapsInspectorLoader struct {
}
func (p configMapsInspectorLoader) Component() definitions.Component {
return definitions.ConfigMap
}
func (p configMapsInspectorLoader) Load(ctx context.Context, i *inspectorState) {
var q configMapsInspector
p.loadV1(ctx, i, &q)
i.configMaps = &q
q.state = i
q.last = time.Now()
}
func (p configMapsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *configMapsInspector) {
var z configMapsInspectorV1
z.configMapInspector = q
z.configMaps, z.err = p.getV1ConfigMaps(ctx, i)
q.v1 = &z
}
func (p configMapsInspectorLoader) getV1ConfigMaps(ctx context.Context, i *inspectorState) (map[string]*core.ConfigMap, error) {
objs, err := p.getV1ConfigMapsList(ctx, i)
if err != nil {
return nil, err
}
r := make(map[string]*core.ConfigMap, len(objs))
for id := range objs {
r[objs[id].GetName()] = objs[id]
}
return r, nil
}
func (p configMapsInspectorLoader) getV1ConfigMapsList(ctx context.Context, i *inspectorState) ([]*core.ConfigMap, error) {
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
defer cancel()
obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).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.ConfigMap, 0, s)
for {
for id := range items {
ptrs = append(ptrs, &items[id])
}
if cont == "" {
break
}
items, cont, err = p.getV1ConfigMapsListRequest(ctx, i, cont)
if err != nil {
return nil, err
}
}
return ptrs, nil
}
func (p configMapsInspectorLoader) getV1ConfigMapsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.ConfigMap, string, error) {
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
defer cancel()
obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).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 configMapsInspectorLoader) Verify(i *inspectorState) error {
if err := i.configMaps.v1.err; err != nil {
return err
}
return nil
}
func (p configMapsInspectorLoader) Copy(from, to *inspectorState, override bool) {
if to.configMaps != nil {
if !override {
return
}
}
to.configMaps = from.configMaps
to.configMaps.state = to
}
func (p configMapsInspectorLoader) Name() string {
return "configMaps"
}
type configMapsInspector struct {
state *inspectorState
last time.Time
v1 *configMapsInspectorV1
}
func (p *configMapsInspector) LastRefresh() time.Time {
return p.last
}
func (p *configMapsInspector) Refresh(ctx context.Context) error {
p.Throttle(p.state.throttles).Invalidate()
return p.state.refresh(ctx, configMapsInspectorLoaderObj)
}
func (p *configMapsInspector) Version() version.Version {
return version.V1
}
func (p *configMapsInspector) Throttle(c throttle.Components) throttle.Throttle {
return c.ConfigMap()
}
func (p *configMapsInspector) validate() error {
if p == nil {
return errors.Errorf("ConfigMapInspector is nil")
}
if p.state == nil {
return errors.Errorf("Parent is nil")
}
return p.v1.validate()
}

View file

@ -0,0 +1,46 @@
//
// DISCLAIMER
//
// Copyright 2024 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 *configMapsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
g := constants.ConfigMapGKv1()
if g.Kind == gvk.Kind && g.Group == gvk.Group {
switch gvk.Version {
case constants.ConfigMapVersionV1, DefaultVersion:
if p.v1 == nil || p.v1.err != nil {
return nil, false
}
return anonymous.NewAnonymous[*core.ConfigMap](g, p.state.configMaps.v1, generic.WithModStatus[*core.ConfigMap](g, p.state.ConfigMapsModInterface().V1())), true
}
}
return nil, false
}

View file

@ -0,0 +1,43 @@
//
// DISCLAIMER
//
// Copyright 2024 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 *configMapsInspectorV1) GroupVersionKind() schema.GroupVersionKind {
return constants.ConfigMapGKv1()
}
func (p *configMapsInspectorV1) GroupVersionResource() schema.GroupVersionResource {
return constants.ConfigMapGRv1()
}
func (p *configMapsInspector) GroupKind() schema.GroupKind {
return constants.ConfigMapGK()
}
func (p *configMapsInspector) GroupResource() schema.GroupResource {
return constants.ConfigMapGR()
}

View file

@ -0,0 +1,49 @@
//
// DISCLAIMER
//
// Copyright 2024 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"
configMapv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods"
)
func (i *inspectorState) ConfigMapsModInterface() mods.ConfigMapsMods {
return configMapsMod{
i: i,
}
}
type configMapsMod struct {
i *inspectorState
}
func (p configMapsMod) V1() configMapv1.ModInterface {
return wrapMod[*core.ConfigMap](definitions.ConfigMap, p.i.GetThrottles, generic.WithModStatusGetter[*core.ConfigMap](constants.ConfigMapGKv1(), p.clientv1))
}
func (p configMapsMod) clientv1() generic.ModClient[*core.ConfigMap] {
return p.i.Client().Kubernetes().CoreV1().ConfigMaps(p.i.Namespace())
}

View file

@ -0,0 +1,118 @@
//
// DISCLAIMER
//
// Copyright 2024 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"
ins "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
)
func (p *configMapsInspector) V1() ins.Inspector {
return p.v1
}
type configMapsInspectorV1 struct {
configMapInspector *configMapsInspector
configMaps map[string]*core.ConfigMap
err error
}
func (p *configMapsInspectorV1) validate() error {
if p == nil {
return errors.Errorf("ConfigMapsV1Inspector is nil")
}
if p.configMapInspector == nil {
return errors.Errorf("Parent is nil")
}
if p.configMaps == nil {
return errors.Errorf("ConfigMaps or err should be not nil")
}
if p.err != nil {
return errors.Errorf("ConfigMaps or err cannot be not nil together")
}
return nil
}
func (p *configMapsInspectorV1) ListSimple() []*core.ConfigMap {
var r []*core.ConfigMap
for _, configMap := range p.configMaps {
r = append(r, configMap)
}
return r
}
func (p *configMapsInspectorV1) GetSimple(name string) (*core.ConfigMap, bool) {
configMap, ok := p.configMaps[name]
if !ok {
return nil, false
}
return configMap, true
}
func (p *configMapsInspectorV1) Iterate(action ins.Action, filters ...ins.Filter) error {
for _, configMap := range p.configMaps {
if err := p.iterateConfigMap(configMap, action, filters...); err != nil {
return err
}
}
return nil
}
func (p *configMapsInspectorV1) iterateConfigMap(configMap *core.ConfigMap, action ins.Action, filters ...ins.Filter) error {
for _, f := range filters {
if f == nil {
continue
}
if !f(configMap) {
return nil
}
}
return action(configMap)
}
func (p *configMapsInspectorV1) Read() ins.ReadInterface {
return p
}
func (p *configMapsInspectorV1) Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ConfigMap, error) {
if s, ok := p.GetSimple(name); !ok {
return nil, apiErrors.NewNotFound(constants.ConfigMapGR(), name)
} else {
return s, nil
}
}

View file

@ -44,6 +44,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap"
"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"
@ -126,6 +127,7 @@ type inspectorState struct {
pods *podsInspector
secrets *secretsInspector
configMaps *configMapsInspector
persistentVolumeClaims *persistentVolumeClaimsInspector
services *servicesInspector
serviceAccounts *serviceAccountsInspector
@ -158,6 +160,7 @@ func (i *inspectorState) RegisterInformers(k8s informers.SharedInformerFactory,
k8s.Core().V1().Pods().Informer().AddEventHandler(i.eventHandler(definitions.Pod))
k8s.Core().V1().Secrets().Informer().AddEventHandler(i.eventHandler(definitions.Secret))
k8s.Core().V1().ConfigMaps().Informer().AddEventHandler(i.eventHandler(definitions.ConfigMap))
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))
@ -222,6 +225,7 @@ func (i *inspectorState) AnonymousObjects() []anonymous.Impl {
return []anonymous.Impl{
i.pods,
i.secrets,
i.configMaps,
i.persistentVolumeClaims,
i.services,
i.serviceAccounts,
@ -280,6 +284,10 @@ func (i *inspectorState) Secret() secret.Definition {
return i.secrets
}
func (i *inspectorState) ConfigMap() configmap.Definition {
return i.configMaps
}
func (i *inspectorState) PersistentVolumeClaim() persistentvolumeclaim.Definition {
return i.persistentVolumeClaims
}
@ -443,6 +451,10 @@ func (i *inspectorState) validate() error {
return err
}
if err := i.configMaps.validate(); err != nil {
return err
}
if err := i.serviceAccounts.validate(); err != nil {
return err
}
@ -501,6 +513,7 @@ func (i *inspectorState) copyCore() *inspectorState {
client: i.client,
pods: i.pods,
secrets: i.secrets,
configMaps: i.configMaps,
persistentVolumeClaims: i.persistentVolumeClaims,
services: i.services,
serviceAccounts: i.serviceAccounts,

View file

@ -142,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, 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, time.Hour, time.Hour)
i := NewInspector(tc, c, "test", "test")
@ -302,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, 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, 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, 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, time.Hour, time.Hour)
i := NewInspector(tc, c, "test", "test")
require.NoError(t, i.Refresh(context.Background()))

View file

@ -63,15 +63,6 @@ func (p *servicesInspectorV1) validate() error {
return nil
}
func (p *servicesInspectorV1) Services() []*core.Service {
var r []*core.Service
for _, service := range p.services {
r = append(r, service)
}
return r
}
func (p *servicesInspectorV1) GetSimple(name string) (*core.Service, bool) {
service, ok := p.services[name]
if !ok {

View file

@ -38,6 +38,7 @@ func NewDefaultThrottle() throttle.Components {
time.Second, // Pod
30*time.Second, // PDB
10*time.Second, // Secret
30*time.Second, // ConfigMap
10*time.Second, // Service
30*time.Second, // SA
30*time.Second, // ServiceMonitor

View file

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

View file

@ -0,0 +1,40 @@
//
// DISCLAIMER
//
// Copyright 2024 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"
)
// Inspector for configmaps
type Inspector interface {
gvk.GVK
ListSimple() []*core.ConfigMap
GetSimple(name string) (*core.ConfigMap, bool)
Iterate(action Action, filters ...Filter) error
Read() ReadInterface
}
type Filter func(pod *core.ConfigMap) bool
type Action func(pod *core.ConfigMap) error

View file

@ -0,0 +1,48 @@
//
// DISCLAIMER
//
// Copyright 2024 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"
"k8s.io/apimachinery/pkg/types"
)
// ModInterface has methods to work with ConfigMap resources only for creation
type ModInterface interface {
Create(ctx context.Context, configmap *core.ConfigMap, opts meta.CreateOptions) (*core.ConfigMap, error)
Update(ctx context.Context, configmap *core.ConfigMap, opts meta.UpdateOptions) (*core.ConfigMap, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta.PatchOptions, subresources ...string) (result *core.ConfigMap, err error)
Delete(ctx context.Context, name string, opts meta.DeleteOptions) error
}
// Interface has methods to work with ConfigMap resources.
type Interface interface {
ModInterface
ReadInterface
}
// ReadInterface has methods to work with ConfigMap resources with ReadOnly mode.
type ReadInterface interface {
Get(ctx context.Context, name string, opts meta.GetOptions) (*core.ConfigMap, error)
}

View file

@ -0,0 +1,64 @@
//
// DISCLAIMER
//
// Copyright 2024 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"
)
// ConfigMap
const (
ConfigMapGroup = core.GroupName
ConfigMapResource = "configmaps"
ConfigMapKind = "ConfigMap"
ConfigMapVersionV1 = "v1"
)
func ConfigMapGK() schema.GroupKind {
return schema.GroupKind{
Group: ConfigMapGroup,
Kind: ConfigMapKind,
}
}
func ConfigMapGKv1() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: ConfigMapGroup,
Kind: ConfigMapKind,
Version: ConfigMapVersionV1,
}
}
func ConfigMapGR() schema.GroupResource {
return schema.GroupResource{
Group: ConfigMapGroup,
Resource: ConfigMapResource,
}
}
func ConfigMapGRv1() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: ConfigMapGroup,
Resource: ConfigMapResource,
Version: ConfigMapVersionV1,
}
}

View file

@ -35,6 +35,7 @@ const (
Pod Component = "Pod"
PodDisruptionBudget Component = "PodDisruptionBudget"
Secret Component = "Secret"
ConfigMap Component = "ConfigMap"
Service Component = "Service"
ServiceAccount Component = "ServiceAccount"
ServiceMonitor Component = "ServiceMonitor"
@ -53,6 +54,7 @@ func AllComponents() []Component {
Pod,
PodDisruptionBudget,
Secret,
ConfigMap,
Service,
ServiceAccount,
ServiceMonitor,

View file

@ -34,6 +34,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap"
"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"
@ -76,6 +77,7 @@ type Inspector interface {
pod.Inspector
secret.Inspector
configmap.Inspector
persistentvolumeclaim.Inspector
service.Inspector
poddisruptionbudget.Inspector

View file

@ -25,6 +25,7 @@ import (
arangomemberv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangomember/v1"
arangoroutev1alpha1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangoroute/v1alpha1"
arangotaskv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/arangotask/v1"
configMapv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1"
endpointsv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/endpoints/v1"
persistentvolumeclaimv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/persistentvolumeclaim/v1"
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
@ -47,6 +48,10 @@ type SecretsMods interface {
V1() secretv1.ModInterface
}
type ConfigMapsMods interface {
V1() configMapv1.ModInterface
}
type PersistentVolumeClaimsMods interface {
V1() persistentvolumeclaimv1.ModInterface
}
@ -87,6 +92,7 @@ type Mods interface {
PodsModInterface() PodsMods
ServiceAccountsModInterface() ServiceAccountsMods
SecretsModInterface() SecretsMods
ConfigMapsModInterface() ConfigMapsMods
PersistentVolumeClaimsModInterface() PersistentVolumeClaimsMods
ServicesModInterface() ServicesMods
EndpointsModInterface() EndpointsMods

View file

@ -32,10 +32,10 @@ type Inspector interface {
}
func NewAlwaysThrottleComponents() Components {
return NewThrottleComponents(0, 0, 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, 0, 0)
}
func NewThrottleComponents(acs, am, at, ar, node, pvc, pod, pv, pdb, secret, service, serviceAccount, sm, endpoints time.Duration) Components {
func NewThrottleComponents(acs, am, at, ar, node, pvc, pod, pv, pdb, secret, cm, service, serviceAccount, sm, endpoints time.Duration) Components {
return &throttleComponents{
arangoClusterSynchronization: NewThrottle(acs),
arangoMember: NewThrottle(am),
@ -47,6 +47,7 @@ func NewThrottleComponents(acs, am, at, ar, node, pvc, pod, pv, pdb, secret, ser
pod: NewThrottle(pod),
podDisruptionBudget: NewThrottle(pdb),
secret: NewThrottle(secret),
configMap: NewThrottle(cm),
service: NewThrottle(service),
serviceAccount: NewThrottle(serviceAccount),
serviceMonitor: NewThrottle(sm),
@ -65,6 +66,7 @@ type Components interface {
Pod() Throttle
PodDisruptionBudget() Throttle
Secret() Throttle
ConfigMap() Throttle
Service() Throttle
ServiceAccount() Throttle
ServiceMonitor() Throttle
@ -88,12 +90,17 @@ type throttleComponents struct {
pod Throttle
podDisruptionBudget Throttle
secret Throttle
configMap Throttle
service Throttle
serviceAccount Throttle
serviceMonitor Throttle
endpoints Throttle
}
func (t *throttleComponents) ConfigMap() Throttle {
return t.configMap
}
func (t *throttleComponents) PersistentVolume() Throttle {
return t.persistentVolume
}
@ -143,6 +150,8 @@ func (t *throttleComponents) Get(c definitions.Component) Throttle {
return t.podDisruptionBudget
case definitions.Secret:
return t.secret
case definitions.ConfigMap:
return t.configMap
case definitions.Service:
return t.service
case definitions.ServiceAccount:
@ -168,6 +177,7 @@ func (t *throttleComponents) Copy() Components {
pod: t.pod.Copy(),
podDisruptionBudget: t.podDisruptionBudget.Copy(),
secret: t.secret.Copy(),
configMap: t.configMap.Copy(),
service: t.service.Copy(),
serviceAccount: t.serviceAccount.Copy(),
serviceMonitor: t.serviceMonitor.Copy(),

View file

@ -131,6 +131,12 @@ func CreateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
_, err := k8s.CoreV1().Secrets(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **core.ConfigMap:
require.NotNil(t, v)
vl := *v
_, err := k8s.CoreV1().ConfigMaps(vl.GetNamespace()).Create(context.Background(), vl, meta.CreateOptions{})
require.NoError(t, err)
case **core.Service:
require.NotNil(t, v)
@ -292,6 +298,12 @@ func UpdateObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
_, err := k8s.CoreV1().Secrets(vl.GetNamespace()).Update(context.Background(), vl, meta.UpdateOptions{})
require.NoError(t, err)
case **core.ConfigMap:
require.NotNil(t, v)
vl := *v
_, err := k8s.CoreV1().ConfigMaps(vl.GetNamespace()).Update(context.Background(), vl, meta.UpdateOptions{})
require.NoError(t, err)
case **core.Service:
require.NotNil(t, v)
@ -444,6 +456,11 @@ func DeleteObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientSe
vl := *v
require.NoError(t, k8s.CoreV1().Secrets(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{}))
case **core.ConfigMap:
require.NotNil(t, v)
vl := *v
require.NoError(t, k8s.CoreV1().ConfigMaps(vl.GetNamespace()).Delete(context.Background(), vl.GetName(), meta.DeleteOptions{}))
case **core.Service:
require.NotNil(t, v)
@ -617,6 +634,21 @@ func RefreshObjects(t *testing.T, k8s kubernetes.Interface, arango arangoClientS
} else {
*v = vn
}
case **core.ConfigMap:
require.NotNil(t, v)
vl := *v
vn, err := k8s.CoreV1().ConfigMaps(vl.GetNamespace()).Get(context.Background(), vl.GetName(), meta.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
*v = nil
} else {
require.NoError(t, err)
}
} else {
*v = vn
}
case **core.Service:
require.NotNil(t, v)
@ -950,6 +982,12 @@ func SetMetaBasedOnType(t *testing.T, object meta.Object) {
v.SetSelfLink(fmt.Sprintf("/api/v1/secrets/%s/%s",
object.GetNamespace(),
object.GetName()))
case *core.ConfigMap:
v.Kind = "ConfigMap"
v.APIVersion = "v1"
v.SetSelfLink(fmt.Sprintf("/api/v1/configmaps/%s/%s",
object.GetNamespace(),
object.GetName()))
case *core.Service:
v.Kind = "Service"
v.APIVersion = "v1"
@ -1164,6 +1202,12 @@ func GVK(t *testing.T, object meta.Object) schema.GroupVersionKind {
Version: "v1",
Kind: "Secret",
}
case *core.ConfigMap:
return schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "ConfigMap",
}
case *core.Service:
return schema.GroupVersionKind{
Group: "",

View file

@ -70,6 +70,7 @@ func Test_NewMetaObject(t *testing.T) {
NewMetaObjectRun[*batch.Job](t)
NewMetaObjectRun[*core.Pod](t)
NewMetaObjectRun[*core.Secret](t)
NewMetaObjectRun[*core.ConfigMap](t)
NewMetaObjectRun[*core.ServiceAccount](t)
NewMetaObjectRun[*core.Service](t)
NewMetaObjectRun[*apps.StatefulSet](t)