Skip to content

Commit 2bef219

Browse files
authored
[Feature] Extend DebugPackage with Debug files (#1929)
1 parent 598b6f5 commit 2bef219

File tree

11 files changed

+256
-15
lines changed

11 files changed

+256
-15
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
- (Feature) (Platform) Storage Debug
5+
- (Feature) Extend DebugPackage with Debug files
56

67
## [1.2.50](https://github.com/arangodb/kube-arangodb/tree/1.2.50) (2025-07-04)
78
- (Feature) (Platform) MetaV1 Integration Service

docs/cli/arangodb_operator_ops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Usage:
101101
arangodb_operator_ops debug-package [flags]
102102
103103
Flags:
104+
--debug-package-files Collect Debug files from Storage
104105
--generator.arango-analytics-gae Define if generator arango-analytics-gae is enabled (default true)
105106
--generator.arango-backup-backup Define if generator arango-backup-backup is enabled (default true)
106107
--generator.arango-backup-backuppolicy Define if generator arango-backup-backuppolicy is enabled (default true)

integrations/shutdown/v1/impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func (i *impl) Close() error {
103103
k := goStrings.TrimPrefix(p, i.cfg.Debug.Path)
104104

105105
prefix := []string{
106+
"debug",
106107
"pod",
107108
}
108109

integrations/storage/v2/object.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 v2
22+
23+
import (
24+
"context"
25+
"net/url"
26+
27+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
29+
pbImplStorageV2Shared "github.com/arangodb/kube-arangodb/integrations/storage/v2/shared"
30+
pbImplStorageV2SharedS3 "github.com/arangodb/kube-arangodb/integrations/storage/v2/shared/s3"
31+
platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1"
32+
awsHelper "github.com/arangodb/kube-arangodb/pkg/util/aws"
33+
"github.com/arangodb/kube-arangodb/pkg/util/constants"
34+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
35+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
36+
)
37+
38+
func NewIOFromObject(ctx context.Context, client kclient.Client, in *platformApi.ArangoPlatformStorage) (pbImplStorageV2Shared.IO, error) {
39+
if err := in.Spec.Validate(); err != nil {
40+
return nil, err
41+
}
42+
43+
if backend := in.Spec.Backend; backend != nil {
44+
if s3Spec := backend.S3; s3Spec != nil {
45+
var config awsHelper.Config
46+
47+
if v := s3Spec.CASecret; v != nil {
48+
secret, err := client.Kubernetes().CoreV1().Secrets(v.GetNamespace(in)).Get(ctx, v.GetName(), meta.GetOptions{})
49+
if err != nil {
50+
return nil, errors.WithMessage(err, "Failed to get S3 secret")
51+
}
52+
53+
q, ok := secret.Data[constants.SecretCACertificate]
54+
if !ok {
55+
return nil, errors.WithMessagef(err, "Failed to get S3 secret %s data: Key %s not found", secret.GetName(), constants.SecretCACertificate)
56+
}
57+
58+
config.TLS.CABytes = [][]byte{q}
59+
}
60+
61+
if v := s3Spec.CredentialsSecret; v != nil {
62+
secret, err := client.Kubernetes().CoreV1().Secrets(v.GetNamespace(in)).Get(ctx, v.GetName(), meta.GetOptions{})
63+
if err != nil {
64+
return nil, errors.WithMessage(err, "Failed to get S3 secret")
65+
}
66+
67+
sk, ok := secret.Data[constants.SecretCredentialsSecretKey]
68+
if !ok {
69+
return nil, errors.Errorf("Failed to get S3 secret %s data: Key %s not found", secret.GetName(), constants.SecretCredentialsSecretKey)
70+
}
71+
72+
ak, ok := secret.Data[constants.SecretCredentialsAccessKey]
73+
if !ok {
74+
return nil, errors.Errorf("Failed to get S3 secret %s data: Key %s not found", secret.GetName(), constants.SecretCredentialsAccessKey)
75+
}
76+
77+
config.Provider.Static.AccessKeyID = string(ak)
78+
config.Provider.Static.SecretAccessKey = string(sk)
79+
config.Provider.Type = awsHelper.ProviderTypeStatic
80+
}
81+
82+
if v := s3Spec.AllowInsecure; v != nil {
83+
config.TLS.Insecure = *v
84+
}
85+
86+
{
87+
if e := s3Spec.GetEndpoint(); e != "" {
88+
endpointURL, err := url.Parse(s3Spec.GetEndpoint())
89+
90+
if err != nil {
91+
return nil, errors.WithMessagef(err, "Failed to parse url: %s", s3Spec.GetEndpoint())
92+
}
93+
disableSSL := endpointURL.Scheme == "http"
94+
95+
config.DisableSSL = disableSSL
96+
}
97+
}
98+
99+
config.Endpoint = s3Spec.GetEndpoint()
100+
config.Region = s3Spec.GetRegion()
101+
102+
var cfg pbImplStorageV2SharedS3.Configuration
103+
104+
cfg.BucketName = s3Spec.GetBucketName()
105+
cfg.BucketPrefix = s3Spec.GetBucketPrefix()
106+
cfg.Client = config
107+
108+
return cfg.New()
109+
}
110+
}
111+
112+
return nil, errors.Errorf("Unable to init the storage")
113+
}

integrations/storage/v2/shared/io.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -62,3 +62,25 @@ type IO interface {
6262
Delete(ctx context.Context, key string) (bool, error)
6363
List(ctx context.Context, key string) (util.NextIterator[[]File], error)
6464
}
65+
66+
func ToIOReader(ctx context.Context, in Reader) io.ReadCloser {
67+
return ioReader{
68+
ctx: ctx,
69+
reader: in,
70+
}
71+
}
72+
73+
type ioReader struct {
74+
ctx context.Context
75+
76+
reader Reader
77+
}
78+
79+
func (i ioReader) Read(p []byte) (n int, err error) {
80+
return i.reader.Read(p)
81+
}
82+
83+
func (i ioReader) Close() error {
84+
_, _, err := i.reader.Close(i.ctx)
85+
return err
86+
}

integrations/storage/v2/shared/s3/io_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func getClient(t *testing.T) pbImplStorageV2Shared.IO {
4848
}
4949

5050
func Test(t *testing.T) {
51+
t.Skipf("DATA")
52+
5153
w := getClient(t)
5254

5355
data := make([]byte, 1024*1024*64)

pkg/debug_package/cli/cli.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ func Register(cmd *cobra.Command) {
3131
f.StringVarP(&input.Namespace, "namespace", "n", constants.NamespaceWithDefault("default"), "Kubernetes namespace")
3232
f.BoolVar(&input.HideSensitiveData, "hide-sensitive-data", true, "Hide sensitive data")
3333
f.BoolVar(&input.PodLogs, "pod-logs", true, "Collect pod logs")
34+
f.BoolVar(&input.DebugPackageFiles, "debug-package-files", false, "Collect Debug files from Storage")
3435
}
3536

3637
var input Input
@@ -43,4 +44,5 @@ type Input struct {
4344
Namespace string
4445
HideSensitiveData bool
4546
PodLogs bool
47+
DebugPackageFiles bool
4648
}

pkg/debug_package/generators/arango/arango_platform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
func Platform(f shared.FactoryGen) {
3333
f.AddSection("platform").
34-
Register("storage", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformStorage](arangoPlatformV1Alpha1ArangoPlatformStorageList, shared.WithDefinitions[*platformApi.ArangoPlatformStorage])).
34+
Register("storage", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformStorage](arangoPlatformV1Alpha1ArangoPlatformStorageList, shared.WithDefinitions[*platformApi.ArangoPlatformStorage], arangoPlatformV1Alpha1ArangoPlatformStorageDebug)).
3535
Register("chart", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformChart](arangoPlatformV1Alpha1ArangoPlatformChartList, shared.WithDefinitions[*platformApi.ArangoPlatformChart], arangoPlatformV1Alpha1ArangoPlatformChartExtract)).
3636
Register("service", true, shared.WithKubernetesItems[*platformApi.ArangoPlatformService](arangoPlatformV1Alpha1ArangoPlatformServiceList, shared.WithDefinitions[*platformApi.ArangoPlatformService]))
3737
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 arango
22+
23+
import (
24+
"context"
25+
"io"
26+
27+
"github.com/rs/zerolog"
28+
29+
pbImplStorageV2 "github.com/arangodb/kube-arangodb/integrations/storage/v2"
30+
platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
32+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
33+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
34+
)
35+
36+
func arangoPlatformV1Alpha1ArangoPlatformStorageDebug(ctx context.Context, logger zerolog.Logger, client kclient.Client, files chan<- shared.File, item *platformApi.ArangoPlatformStorage) error {
37+
if !cli.GetInput().DebugPackageFiles {
38+
return nil
39+
}
40+
41+
c, err := pbImplStorageV2.NewIOFromObject(ctx, client, item)
42+
if err != nil {
43+
return err
44+
}
45+
46+
allFiles, err := c.List(ctx, "debug/")
47+
if err != nil {
48+
return err
49+
}
50+
51+
for {
52+
t, err := allFiles.Next(ctx)
53+
if err != nil {
54+
if err == io.EOF {
55+
break
56+
}
57+
return err
58+
}
59+
60+
for _, f := range t {
61+
f := f
62+
files <- shared.NewFile(f.Key, func() ([]byte, error) {
63+
reader, err := c.Read(ctx, f.Key)
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
data, err := io.ReadAll(reader)
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
return data, nil
74+
})
75+
}
76+
}
77+
78+
return nil
79+
}

pkg/util/aws/tls.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import (
3131
type TLS struct {
3232
Insecure bool
3333
CAFiles []string
34+
CABytes [][]byte
3435
}
3536

3637
func (s TLS) configuration() (*tls.Config, error) {
@@ -40,15 +41,23 @@ func (s TLS) configuration() (*tls.Config, error) {
4041
r.InsecureSkipVerify = true
4142
}
4243

43-
if len(s.CAFiles) > 0 {
44+
if len(s.CAFiles) > 0 || len(s.CABytes) > 0 {
4445
caCertPool := x509.NewCertPool()
4546

4647
for _, file := range s.CAFiles {
4748
caCert, err := os.ReadFile(file)
4849
if err != nil {
4950
return nil, errors.Wrapf(err, "Unable to load CA from %s", file)
5051
}
51-
caCertPool.AppendCertsFromPEM(caCert)
52+
if !caCertPool.AppendCertsFromPEM(caCert) {
53+
return nil, errors.Errorf("Unable to add CA from %s", file)
54+
}
55+
}
56+
57+
for _, data := range s.CABytes {
58+
if !caCertPool.AppendCertsFromPEM(data) {
59+
return nil, errors.Errorf("Unable to add CA bytes")
60+
}
5261
}
5362

5463
r.RootCAs = caCertPool

0 commit comments

Comments
 (0)