Skip to content

Commit 3c34c2e

Browse files
authored
[Feature] [LM] Inventory CLI (#1974)
1 parent f6e20dd commit 3c34c2e

29 files changed

+2063
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) (Platform) Increase memory limit for Inventory
5+
- (Feature) (LM) Inventory Generator
56

67
## [1.3.1](https://github.com/arangodb/kube-arangodb/tree/1.3.1) (2025-10-07)
78
- (Documentation) Add ArangoPlatformStorage Docs & Examples

docs/cli/arangodb_operator_platform.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ parent: Binaries
44
title: arangodb_operator_platform
55
---
66

7+
# ArangoDB Operator Platform Command
8+
9+
[START_INJECT]: # (arangodb_operator_platform_cmd)
10+
```
11+
Usage:
12+
arangodb_operator_platform [command]
13+
14+
Available Commands:
15+
completion Generate the autocompletion script for the specified shell
16+
help Help about any command
17+
license License Package related operations
18+
package Release Package related operations
19+
20+
Flags:
21+
-h, --help help for arangodb_operator_platform
22+
--kubeconfig string Kubernetes Config File
23+
-n, --namespace string Kubernetes Namespace (default "default")
24+
25+
Use "arangodb_operator_platform [command] --help" for more information about a command.
26+
```
27+
[END_INJECT]: # (arangodb_operator_platform_cmd)
28+
729
# ArangoDB Operator Platform Package Command
830

931
[START_INJECT]: # (arangodb_operator_platform_package_cmd)
@@ -70,3 +92,49 @@ Global Flags:
7092
```
7193
[END_INJECT]: # (arangodb_operator_platform_package_install_cmd)
7294

95+
# ArangoDB Operator Platform License Command
96+
97+
[START_INJECT]: # (arangodb_operator_platform_license_cmd)
98+
```
99+
License Package related operations
100+
101+
Usage:
102+
arangodb_operator_platform license [command]
103+
104+
Available Commands:
105+
inventory Inventory Generator
106+
107+
Flags:
108+
-h, --help help for license
109+
110+
Global Flags:
111+
--kubeconfig string Kubernetes Config File
112+
-n, --namespace string Kubernetes Namespace (default "default")
113+
114+
Use "arangodb_operator_platform license [command] --help" for more information about a command.
115+
```
116+
[END_INJECT]: # (arangodb_operator_platform_license_cmd)
117+
118+
# ArangoDB Operator Platform License Inventory Command
119+
120+
[START_INJECT]: # (arangodb_operator_platform_license_inventory_cmd)
121+
```
122+
Inventory Generator
123+
124+
Usage:
125+
arangodb_operator_platform license inventory [flags] output
126+
127+
Flags:
128+
--arango.authentication string Arango Endpoint Auth Method. One of: Disabled, Basic, Token (default "Disabled")
129+
--arango.basic.password string Arango Password for Basic Authentication
130+
--arango.basic.username string Arango Username for Basic Authentication
131+
--arango.endpoint strings Arango Endpoint
132+
--arango.insecure Arango Endpoint Insecure
133+
--arango.token string Arango JWT Token for Authentication
134+
-h, --help help for inventory
135+
136+
Global Flags:
137+
--kubeconfig string Kubernetes Config File
138+
-n, --namespace string Kubernetes Namespace (default "default")
139+
```
140+
[END_INJECT]: # (arangodb_operator_platform_license_inventory_cmd)

internal/readme_cli.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ func GenerateCLIArangoDBOperatorPlatformReadme(root string) error {
139139
readmeSections["arangodb_operator_platform_package_install_cmd"] = section
140140
}
141141

142+
if section, err := GenerateHelpQuoted(cmd, "license"); err != nil {
143+
return err
144+
} else {
145+
readmeSections["arangodb_operator_platform_license_cmd"] = section
146+
}
147+
148+
if section, err := GenerateHelpQuoted(cmd, "license", "inventory"); err != nil {
149+
return err
150+
} else {
151+
readmeSections["arangodb_operator_platform_license_inventory_cmd"] = section
152+
}
153+
142154
if err := pretty.ReplaceSectionsInFile(path.Join(root, "docs", "cli", "arangodb_operator_platform.md"), readmeSections); err != nil {
143155
return err
144156
}

pkg/apis/shared/validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ func ValidateRequiredNotEmptyPath[T any](path string, in *T) error {
200200
return PrefixResourceError(path, ValidateRequiredNotEmpty(in))
201201
}
202202

203+
// ValidatePath Validates object
204+
func ValidatePath[T any](path string, in T, validator func(T) error) error {
205+
return PrefixResourceErrors(path, validator(in))
206+
}
207+
203208
// ValidateRequiredPath Validates object and required not nil value
204209
func ValidateRequiredPath[T any](path string, in *T, validator func(T) error) error {
205210
return PrefixResourceErrors(path, ValidateRequired(in, validator))

pkg/deployment/client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type Client interface {
5959
Compact(ctx context.Context, request *CompactRequest) error
6060

6161
Inventory(ctx context.Context) (*Inventory, error)
62+
63+
DeploymentID(ctx context.Context) (DeploymentID, error)
6264
}
6365

6466
type client struct {

pkg/deployment/client/id.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 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 client
22+
23+
import (
24+
"context"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
27+
)
28+
29+
type DeploymentID struct {
30+
Id string `json:"id"`
31+
}
32+
33+
func (c *client) DeploymentID(ctx context.Context) (DeploymentID, error) {
34+
return arangod.GetRequest[DeploymentID](ctx, c.c, "_admin", "deployment", "id").AcceptCode(200).Response()
35+
}

pkg/platform/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ var (
100100
},
101101
}
102102

103+
flagDeployment = cli.NewDeployment("arango")
104+
103105
flagValues = cli.Flag[[]string]{
104106
Name: "values",
105107
Short: "f",

pkg/platform/installer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func installer() (*cobra.Command, error) {
4444

4545
if err := withRegisterCommand(&cmd,
4646
pkg,
47+
license,
4748
); err != nil {
4849
return nil, err
4950
}

pkg/platform/inventory/aql.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 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 inventory
22+
23+
import (
24+
"context"
25+
"time"
26+
27+
"github.com/arangodb/go-driver"
28+
"github.com/arangodb/go-driver/util/connection/wrappers/async"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/logging"
31+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
32+
"github.com/arangodb/kube-arangodb/pkg/util/executor"
33+
ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
34+
)
35+
36+
func ExecuteAQL(db string, aql string, bind map[string]any) Executor {
37+
return func(conn driver.Connection, out chan<- *Item) executor.RunFunc {
38+
return func(ctx context.Context, log logging.Logger, t executor.Thread, h executor.Handler) error {
39+
c, err := driver.NewClient(driver.ClientConfig{Connection: async.NewConnectionAsyncWrapper(conn)})
40+
if err != nil {
41+
return err
42+
}
43+
44+
d, err := c.Database(ctx, db)
45+
if err != nil {
46+
return err
47+
}
48+
49+
nctx := driver.WithAsync(ctx)
50+
51+
_, err = d.Query(nctx, aql, bind)
52+
if err == nil {
53+
return errors.Errorf("Async execution of the query should be prepared")
54+
}
55+
56+
jobId, ok := async.IsAsyncJobInProgress(err)
57+
if !ok {
58+
return errors.Wrapf(err, "Async execution of the query should be prepared")
59+
}
60+
61+
var cursor driver.Cursor
62+
63+
for {
64+
zctx := driver.WithAsyncID(ctx, jobId)
65+
66+
query, err := d.Query(zctx, aql, bind)
67+
if err != nil {
68+
_, ok := async.IsAsyncJobInProgress(err)
69+
if !ok {
70+
return errors.Wrapf(err, "Async execution of the query should be prepared")
71+
}
72+
73+
t.Wait(125 * time.Millisecond)
74+
75+
continue
76+
}
77+
78+
cursor = query
79+
break
80+
}
81+
82+
for {
83+
var ret ugrpc.Object[*Item]
84+
85+
if _, err := cursor.ReadDocument(ctx, &ret); err != nil {
86+
if driver.IsNoMoreDocuments(err) {
87+
break
88+
}
89+
90+
return err
91+
}
92+
93+
if err := ret.Object.Validate(); err != nil {
94+
return err
95+
}
96+
97+
out <- ret.Object
98+
}
99+
100+
return nil
101+
}
102+
}
103+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 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 inventory
22+
23+
import _ "embed"
24+
25+
//go:embed queries/timestamp.aql
26+
var queryTimestampAQL string
27+
28+
func init() {
29+
global.MustRegister("aql.timestamp", ExecuteAQL("_system", queryTimestampAQL, nil))
30+
}

0 commit comments

Comments
 (0)