10000 [Feature] ConfigMap Inspector by ajanikow · Pull Request #1696 · arangodb/kube-arangodb · GitHub
[go: up one dir, main page]

Skip to content

[Feature] ConfigMap Inspector #1696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
196 changes: 196 additions & 0 deletions pkg/deployment/resources/inspector/configmaps.go
Original file line number Diff line number Diff line change
@@ -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()
}
46 changes: 46 additions & 0 deletions pkg/deployment/resources/inspector/configmaps_anonymous.go
< 1E0A td class="blob-code blob-code-addition js-file-line"> func (p *configMapsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
Original file line number Diff line number Diff line change
@@ -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"
)

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
}
43 changes: 43 additions & 0 deletions pkg/deployment/resources/inspector/configmaps_gvk.go
Original file line number Diff line number Diff line change
@@ -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()
}
49 changes: 49 additions & 0 deletions pkg/deployment/resources/inspector/configmaps_mod.go
Original file line number Diff line number Diff line change
@@ -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())
}
Loading
0