8000 [Feature] ConfigMap Inspector · arangodb/kube-arangodb@0ff1fe5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ff1fe5

Browse files
committed
[Feature] ConfigMap Inspector
1 parent 37522ee commit 0ff1fe5

21 files changed

+733
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- (Feature) ArangoRoute Operator
66
- (Feature) Add Kubernetes Services for Group
77
- (Bugfix) Fix Networking Client
8+
- (Feature) ConfigMap Inspector
89

910
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
1011
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"context"
25+
"time"
26+
27+
core "k8s.io/api/core/v1"
28+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
31+
"github.com/arangodb/kube-arangodb/pkg/util/globals"
32+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
34+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/version"
35+
)
36+
37+
func init() {
38+
requireRegisterInspectorLoader(configMapsInspectorLoaderObj)
39+
}
40+
41+
var configMapsInspectorLoaderObj = configMapsInspectorLoader{}
42+
43+
type configMapsInspectorLoader struct {
44+
}
45+
46+
func (p configMapsInspectorLoader) Component() definitions.Component {
47+
return definitions.ConfigMap
48+
}
49+
50+
func (p configMapsInspectorLoader) Load(ctx context.Context, i *inspectorState) {
51+
var q configMapsInspector
52+
p.loadV1(ctx, i, &q)
53+
i.configMaps = &q
54+
q.state = i
55+
q.last = time.Now()
56+
}
57+
58+
func (p configMapsInspectorLoader) loadV1(ctx context.Context, i *inspectorState, q *configMapsInspector) {
59+
var z configMapsInspectorV1
60+
61+
z.configMapInspector = q
62+
63+
z.configMaps, z.err = p.getV1ConfigMaps(ctx, i)
64+
65+
q.v1 = &z
66+
}
67+
68+
func (p configMapsInspectorLoader) getV1ConfigMaps(ctx context.Context, i *inspectorState) (map[string]*core.ConfigMap, error) {
69+
objs, err := p.getV1ConfigMapsList(ctx, i)
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
r := make(map[string]*core.ConfigMap, len(objs))
75+
76+
for id := range objs {
77+
r[objs[id].GetName()] = objs[id]
78+
}
79+
80+
return r, nil
81+
}
82+
83+
func (p configMapsInspectorLoader) getV1ConfigMapsList(ctx context.Context, i *inspectorState) ([]*core.ConfigMap, error) {
84+
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
85+
defer cancel()
86+
obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).List(ctxChild, meta.ListOptions{
87+
Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(),
88+
})
89+
90+
if err != nil {
91+
return nil, err
92+
}
93+
94+
items := obj.Items
95+
cont := obj.Continue
96+
var s = int64(len(items))
97+
98+
if z := obj.RemainingItemCount; z != nil {
99+
s += *z
100+
}
101+
102+
ptrs := make([]*core.ConfigMap, 0, s)
103+
104+
for {
105+
for id := range items {
106+
ptrs = append(ptrs, &items[id])
107+
}
108+
109+
if cont == "" {
110+
break
111+
}
112+
113+
items, cont, err = p.getV1ConfigMapsListRequest(ctx, i, cont)
114+
115+
if err != nil {
116+
return nil, err
117+
}
118+
}
119+
120+
return ptrs, nil
121+
}
122+
123+
func (p configMapsInspectorLoader) getV1ConfigMapsListRequest(ctx context.Context, i *inspectorState, cont string) ([]core.ConfigMap, string, error) {
124+
ctxChild, cancel := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx)
125+
defer cancel()
126+
obj, err := i.client.Kubernetes().CoreV1().ConfigMaps(i.namespace).List(ctxChild, meta.ListOptions{
127+
Limit: globals.GetGlobals().Kubernetes().RequestBatchSize().Get(),
128+
Continue: cont,
129+
})
130+
131+
if err != nil {
132+
return nil, "", err
133+
}
134+
135+
return obj.Items, obj.Continue, err
136+
}
137+
138+
func (p configMapsInspectorLoader) Verify(i *inspectorState) error {
139+
if err := i.configMaps.v1.err; err != nil {
140+
return err
141+
}
142+
143+
return nil
144+
}
145+
146+
func (p configMapsInspectorLoader) Copy(from, to *inspectorState, override bool) {
147+
if to.configMaps != nil {
148+
if !override {
149+
return
150+
}
151+
}
152+
153+
to.configMaps = from.configMaps
154+
to.configMaps.state = to
155+
}
156+
157+
func (p configMapsInspectorLoader) Name() string {
158+
return "configMaps"
159+
}
160+
161+
type configMapsInspector struct {
162+
state *inspectorState
163+
164+
last time.Time
165+
166+
v1 *configMapsInspectorV1
167+
}
168+
169+
func (p *configMapsInspector) LastRefresh() time.Time {
170+
return p.last
171+
}
172+
173+
func (p *configMapsInspector) Refresh(ctx context.Context) error {
174+
p.Throttle(p.state.throttles).Invalidate()
175+
return p.state.refresh(ctx, configMapsInspectorLoaderObj)
176+
}
177+
178+
func (p *configMapsInspector) Version() version.Version {
179+
return version.V1
180+
}
181+
182+
func (p *configMapsInspector) Throttle(c throttle.Components) throttle.Throttle {
183+
return c.ConfigMap()
184+
}
185+
186+
func (p *configMapsInspector) validate() error {
187+
if p == nil {
188+
return errors.Errorf("ConfigMapInspector is nil")
189+
}
190+
191+
if p.state == nil {
192+
return errors.Errorf("Parent is nil")
193+
}
194+
195+
return p.v1.validate()
196+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
core "k8s.io/api/core/v1"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
26+
27+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/anonymous"
28+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
29+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic"
30+
)
31+
32+
func (p *configMapsInspector) Anonymous(gvk schema.GroupVersionKind) (anonymous.Interface, bool) {
33+
g := constants.ConfigMapGKv1()
34+
35+
if g.Kind == gvk.Kind && g.Group == gvk.Group {
36+
switch gvk.Version {
37+
case constants.ConfigMapVersionV1, DefaultVersion:
38+
if p.v1 == nil || p.v1.err != nil {
39+
return nil, false
40+
}
41+
return anonymous.NewAnonymous[*core.ConfigMap](g, p.state.configMaps.v1, generic.WithModStatus[*core.ConfigMap](g, p.state.ConfigMapsModInterface().V1())), true
42+
}
43+
}
44+
45+
return nil, false
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"k8s.io/apimachinery/pkg/runtime/schema"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
27+
)
28+
29+
func (p *configMapsInspectorV1) GroupVersionKind() schema.GroupVersionKind {
30+
return constants.ConfigMapGKv1()
31+
}
32+
33+
func (p *configMapsInspectorV1) GroupVersionResource() schema.GroupVersionResource {
34+
return constants.ConfigMapGRv1()
35+
}
36+
37+
func (p *configMapsInspector) GroupKind() schema.GroupKind {
38+
return constants.ConfigMapGK()
39+
}
40+
41+
func (p *configMapsInspector) GroupResource() schema.GroupResource {
42+
return constants.ConfigMapGR()
43+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
core "k8s.io/api/core/v1"
25+
26+
configMapv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/configmap/v1"
27+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/constants"
28+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions"
29+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/generic"
30+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/mods"
31+
)
32+
33+
func (i *inspectorState) ConfigMapsModInterface() mods.ConfigMapsMods {
34+
return configMapsMod{
35+
i: i,
36+
}
37+
}
38+
39+
type configMapsMod struct {
40+
i *inspectorState
41+
}
42+
43+
func (p configMapsMod) V1() configMapv1.ModInterface {
44+
return wrapMod[*core.ConfigMap](definitions.ConfigMap, p.i.GetThrottles, generic.WithModStatusGetter[*core.ConfigMap](constants.ConfigMapGKv1(), p.clientv1))
45+
}
46+
47+
func (p configMapsMod) clientv1() generic.ModClient[*core.ConfigMap] {
48+
return p.i.Client().Kubernetes().CoreV1().ConfigMaps(p.i.Namespace())
49+
}

0 commit comments

Comments
 (0)
0