Skip to content

Commit c98a4d9

Browse files
committed
refactoring mongodb specific code into store-client-sdk
Signed-off-by: Davanum Srinivas <[email protected]> cleanup Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 19d00f2 commit c98a4d9

File tree

134 files changed

+15277
-3875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+15277
-3875
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ linters:
5353
- noctx
5454
- whitespace
5555
- wsl_v5
56+
- gosec
5657
exclusions:
5758
generated: lax
5859
presets:

commons/go.mod

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,58 @@ require (
1717
require (
1818
github.com/beorn7/perks v1.0.1 // indirect
1919
github.com/cespare/xxhash/v2 v2.3.0 // indirect
20-
github.com/davecgh/go-spew v1.1.1 // indirect
21-
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
20+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
21+
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
2222
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
23-
github.com/go-logr/logr v1.4.2 // indirect
24-
github.com/go-openapi/jsonpointer v0.21.0 // indirect
25-
github.com/go-openapi/jsonreference v0.20.2 // indirect
26-
github.com/go-openapi/swag v0.23.0 // indirect
23+
github.com/go-logr/logr v1.4.3 // indirect
24+
github.com/go-openapi/jsonpointer v0.22.1 // indirect
25+
github.com/go-openapi/jsonreference v0.21.2 // indirect
26+
github.com/go-openapi/swag v0.25.1 // indirect
27+
github.com/go-openapi/swag/cmdutils v0.25.1 // indirect
28+
github.com/go-openapi/swag/conv v0.25.1 // indirect
29+
github.com/go-openapi/swag/fileutils v0.25.1 // indirect
30+
github.com/go-openapi/swag/jsonname v0.25.1 // indirect
31+
github.com/go-openapi/swag/jsonutils v0.25.1 // indirect
32+
github.com/go-openapi/swag/loading v0.25.1 // indirect
33+
github.com/go-openapi/swag/mangling v0.25.1 // indirect
34+
github.com/go-openapi/swag/netutils v0.25.1 // indirect
35+
github.com/go-openapi/swag/stringutils v0.25.1 // indirect
36+
github.com/go-openapi/swag/typeutils v0.25.1 // indirect
37+
github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
2738
github.com/gogo/protobuf v1.3.2 // indirect
2839
github.com/google/gnostic-models v0.7.0 // indirect
40+
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d // indirect
2941
github.com/google/uuid v1.6.0 // indirect
30-
github.com/josharian/intern v1.0.0 // indirect
3142
github.com/json-iterator/go v1.1.12 // indirect
32-
github.com/mailru/easyjson v0.7.7 // indirect
3343
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3444
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
3545
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
36-
github.com/pkg/errors v0.9.1 // indirect
37-
github.com/pmezard/go-difflib v1.0.0 // indirect
46+
github.com/onsi/ginkgo/v2 v2.26.0 // indirect
47+
github.com/onsi/gomega v1.38.2 // indirect
48+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3849
github.com/prometheus/client_model v0.6.2 // indirect
39-
github.com/prometheus/common v0.66.1 // indirect
40-
github.com/prometheus/procfs v0.16.1 // indirect
50+
github.com/prometheus/common v0.67.2 // indirect
51+
github.com/prometheus/procfs v0.17.0 // indirect
52+
github.com/rogpeppe/go-internal v1.14.1 // indirect
53+
github.com/spf13/pflag v1.0.10 // indirect
4154
github.com/x448/float16 v0.8.4 // indirect
42-
go.yaml.in/yaml/v2 v2.4.2 // indirect
55+
go.yaml.in/yaml/v2 v2.4.3 // indirect
4356
go.yaml.in/yaml/v3 v3.0.4 // indirect
44-
golang.org/x/net v0.43.0 // indirect
45-
golang.org/x/oauth2 v0.30.0 // indirect
46-
golang.org/x/sys v0.35.0 // indirect
47-
golang.org/x/term v0.34.0 // indirect
48-
golang.org/x/text v0.28.0 // indirect
49-
golang.org/x/time v0.9.0 // indirect
50-
google.golang.org/protobuf v1.36.8 // indirect
51-
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
57+
golang.org/x/net v0.46.0 // indirect
58+
golang.org/x/oauth2 v0.32.0 // indirect
59+
golang.org/x/sys v0.37.0 // indirect
60+
golang.org/x/term v0.36.0 // indirect
61+
golang.org/x/text v0.30.0 // indirect
62+
golang.org/x/time v0.14.0 // indirect
63+
golang.org/x/tools v0.38.0 // indirect
64+
google.golang.org/protobuf v1.36.10 // indirect
65+
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
5266
gopkg.in/inf.v0 v0.9.1 // indirect
5367
gopkg.in/yaml.v3 v3.0.1 // indirect
5468
k8s.io/klog/v2 v2.130.1 // indirect
55-
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
56-
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
57-
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
69+
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
70+
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
71+
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
5872
sigs.k8s.io/randfill v1.0.0 // indirect
5973
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
6074
sigs.k8s.io/yaml v1.6.0 // indirect

commons/go.sum

Lines changed: 84 additions & 70 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package flags
16+
17+
import (
18+
"flag"
19+
"log/slog"
20+
"os"
21+
)
22+
23+
// DatabaseCertConfig holds the configuration for database client certificate paths
24+
type DatabaseCertConfig struct {
25+
DatabaseClientCertMountPath string
26+
LegacyMongoCertPath string
27+
ResolvedCertPath string
28+
}
29+
30+
// RegisterDatabaseCertFlags registers both the new and legacy database certificate flags
31+
// for backward compatibility. This centralizes the flag parsing logic that was duplicated
32+
// across multiple modules.
33+
func RegisterDatabaseCertFlags() *DatabaseCertConfig {
34+
config := &DatabaseCertConfig{}
35+
36+
flag.StringVar(&config.DatabaseClientCertMountPath, "database-client-cert-mount-path", "/etc/ssl/database-client",
37+
"path where the database client cert is mounted")
38+
39+
// Support legacy flag name for backward compatibility
40+
flag.StringVar(&config.LegacyMongoCertPath, "mongo-client-cert-mount-path", "/etc/ssl/mongo-client",
41+
"path where the mongo client cert is mounted (legacy flag, use database-client-cert-mount-path)")
42+
43+
return config
44+
}
45+
46+
// ResolveCertPath resolves the actual certificate path to use based on flag values and file existence.
47+
// This implements the backward compatibility logic that was duplicated across multiple modules.
48+
func (c *DatabaseCertConfig) ResolveCertPath() string {
49+
// If new flag is still default and legacy flag is provided, use legacy flag value
50+
if c.DatabaseClientCertMountPath == "/etc/ssl/database-client" {
51+
c.ResolvedCertPath = c.LegacyMongoCertPath
52+
slog.Info("Using legacy certificate path for backward compatibility",
53+
"resolved_path", c.ResolvedCertPath,
54+
"database_flag", c.DatabaseClientCertMountPath,
55+
"legacy_flag", c.LegacyMongoCertPath)
56+
} else {
57+
c.ResolvedCertPath = c.DatabaseClientCertMountPath
58+
slog.Info("Using new certificate path",
59+
"resolved_path", c.ResolvedCertPath)
60+
}
61+
62+
return c.ResolvedCertPath
63+
}
64+
65+
// GetCertPath checks if the certificate exists at the resolved path, with fallback logic
66+
func (c *DatabaseCertConfig) GetCertPath() string {
67+
if c.ResolvedCertPath == "" {
68+
c.ResolveCertPath()
69+
}
70+
71+
// Check if ca.crt exists at the resolved path
72+
if _, err := os.Stat(c.ResolvedCertPath + "/ca.crt"); err == nil {
73+
return c.ResolvedCertPath
74+
}
75+
76+
// Fall back to legacy mongo-client path
77+
legacyPath := "/etc/ssl/mongo-client"
78+
if _, err := os.Stat(legacyPath + "/ca.crt"); err == nil {
79+
slog.Info("Fallback to legacy certificate path", "path", legacyPath)
80+
return legacyPath
81+
}
82+
83+
// Fall back to new database-client path
84+
newPath := "/etc/ssl/database-client"
85+
if _, err := os.Stat(newPath + "/ca.crt"); err == nil {
86+
slog.Info("Fallback to new certificate path", "path", newPath)
87+
return newPath
88+
}
89+
90+
// If neither exists, return the resolved path (original behavior)
91+
slog.Warn("Certificate file not found at any expected location, using resolved path",
92+
"resolved_path", c.ResolvedCertPath)
93+
94+
return c.ResolvedCertPath
95+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package flags
16+
17+
import (
18+
"os"
19+
"path/filepath"
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestDatabaseCertConfig_ResolveCertPath(t *testing.T) {
27+
tests := []struct {
28+
name string
29+
databaseClientCertMountPath string
30+
legacyMongoCertPath string
31+
expectedResolvedPath string
32+
description string
33+
}{
34+
{
35+
name: "new flag with default value uses legacy",
36+
databaseClientCertMountPath: "/etc/ssl/database-client",
37+
legacyMongoCertPath: "/etc/ssl/mongo-client",
38+
expectedResolvedPath: "/etc/ssl/mongo-client",
39+
description: "When new flag is default, legacy flag value should be used",
40+
},
41+
{
42+
name: "new flag with custom value uses new",
43+
databaseClientCertMountPath: "/custom/database-client",
44+
legacyMongoCertPath: "/etc/ssl/mongo-client",
45+
expectedResolvedPath: "/custom/database-client",
46+
description: "When new flag is explicitly set, it should be used",
47+
},
48+
{
49+
name: "new flag with default and legacy custom uses legacy",
50+
databaseClientCertMountPath: "/etc/ssl/database-client",
51+
legacyMongoCertPath: "/custom/mongo-client",
52+
expectedResolvedPath: "/custom/mongo-client",
53+
description: "When new flag is default and legacy is custom, legacy should be used",
54+
},
55+
}
56+
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
config := &DatabaseCertConfig{
60+
DatabaseClientCertMountPath: tt.databaseClientCertMountPath,
61+
LegacyMongoCertPath: tt.legacyMongoCertPath,
62+
}
63+
64+
resolvedPath := config.ResolveCertPath()
65+
66+
assert.Equal(t, tt.expectedResolvedPath, resolvedPath, tt.description)
67+
assert.Equal(t, tt.expectedResolvedPath, config.ResolvedCertPath, "ResolvedCertPath should be set")
68+
})
69+
}
70+
}
71+
72+
func TestDatabaseCertConfig_GetCertPath(t *testing.T) {
73+
// Create a temporary directory structure for testing
74+
tempDir, err := os.MkdirTemp("", "cert_test")
75+
require.NoError(t, err)
76+
defer os.RemoveAll(tempDir)
77+
78+
// Create test certificate directories
79+
legacyPath := filepath.Join(tempDir, "mongo-client")
80+
newPath := filepath.Join(tempDir, "database-client")
81+
customPath := filepath.Join(tempDir, "custom")
82+
83+
require.NoError(t, os.MkdirAll(legacyPath, 0755))
84+
require.NoError(t, os.MkdirAll(newPath, 0755))
85+
require.NoError(t, os.MkdirAll(customPath, 0755))
86+
87+
// Create ca.crt files in test directories
88+
require.NoError(t, os.WriteFile(filepath.Join(legacyPath, "ca.crt"), []byte("legacy cert"), 0644))
89+
require.NoError(t, os.WriteFile(filepath.Join(newPath, "ca.crt"), []byte("new cert"), 0644))
90+
require.NoError(t, os.WriteFile(filepath.Join(customPath, "ca.crt"), []byte("custom cert"), 0644))
91+
92+
tests := []struct {
93+
name string
94+
resolvedPath string
95+
expectedPath string
96+
description string
97+
}{
98+
{
99+
name: "resolved path exists",
100+
resolvedPath: customPath,
101+
expectedPath: customPath,
102+
description: "When resolved path has ca.crt, it should be used",
103+
},
104+
{
105+
name: "resolved path missing fallback to legacy",
106+
resolvedPath: filepath.Join(tempDir, "nonexistent"),
107+
expectedPath: "/etc/ssl/mongo-client", // Falls back to hardcoded legacy path
108+
description: "When resolved path missing, should fallback to legacy path",
109+
},
110+
}
111+
112+
for _, tt := range tests {
113+
t.Run(tt.name, func(t *testing.T) {
114+
config := &DatabaseCertConfig{
115+
ResolvedCertPath: tt.resolvedPath,
116+
}
117+
118+
certPath := config.GetCertPath()
119+
120+
if tt.expectedPath == "/etc/ssl/mongo-client" {
121+
// For fallback cases, just check it's using the fallback logic
122+
assert.True(t, certPath == "/etc/ssl/mongo-client" || certPath == "/etc/ssl/database-client" || certPath == tt.resolvedPath,
123+
"Should use fallback logic when resolved path doesn't exist")
124+
} else {
125+
assert.Equal(t, tt.expectedPath, certPath, tt.description)
126+
}
127+
})
128+
}
129+
}
130+
131+
func TestDatabaseCertConfig_GetCertPath_WithRealPaths(t *testing.T) {
132+
tests := []struct {
133+
name string
134+
resolvedPath string
135+
description string
136+
}{
137+
{
138+
name: "legacy path preference",
139+
resolvedPath: "/etc/ssl/mongo-client",
140+
description: "Should handle legacy path correctly",
141+
},
142+
{
143+
name: "new path preference",
144+
resolvedPath: "/etc/ssl/database-client",
145+
description: "Should handle new path correctly",
146+
},
147+
}
148+
149+
for _, tt := range tests {
150+
t.Run(tt.name, func(t *testing.T) {
151+
config := &DatabaseCertConfig{
152+
ResolvedCertPath: tt.resolvedPath,
153+
}
154+
155+
certPath := config.GetCertPath()
156+
157+
// Since we can't guarantee these paths exist in test environment,
158+
// just verify the function returns a reasonable path
159+
assert.NotEmpty(t, certPath, "GetCertPath should return a non-empty path")
160+
assert.Contains(t, []string{"/etc/ssl/mongo-client", "/etc/ssl/database-client", tt.resolvedPath},
161+
certPath, "Should return one of the expected paths")
162+
})
163+
}
164+
}

data-models/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ DOCKER_EXTRA_ARGS :=
3535
# =============================================================================
3636

3737
include ../make/common.mk
38+
include ../make/go.mk
3839

3940
# =============================================================================
4041
# MODULE-SPECIFIC TARGETS

data-models/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
golang.org/x/net v0.46.0 // indirect
1616
golang.org/x/sys v0.37.0 // indirect
1717
golang.org/x/text v0.30.0 // indirect
18-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f // indirect
18+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
1919
)
2020

2121
// Local replacements for internal modules

data-models/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
2828
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
2929
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
3030
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
31-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f h1:1FTH6cpXFsENbPR5Bu8NQddPSaUUE6NA2XdZdDSAJK4=
32-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
31+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 h1:M1rk8KBnUsBDg1oPGHNCxG4vc1f49epmTO7xscSajMk=
32+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
3333
google.golang.org/grpc v1.76.0 h1:UnVkv1+uMLYXoIz6o7chp59WfQUYA2ex/BXQ9rHZu7A=
3434
google.golang.org/grpc v1.76.0/go.mod h1:Ju12QI8M6iQJtbcsV+awF5a4hfJMLi4X0JLo94ULZ6c=
3535
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=

distros/kubernetes/nvsentinel/charts/health-events-analyzer/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ config: |
6767
6868
[[rules]]
6969
name = "RepeatedXidError"
70-
description = "Detect occurrence of fatal XIDs 5 times within 24 hours"
70+
description = "Detect occurrence of fatal XIDs 5 times within 24 hours (production: 86400s for real workloads)"
7171
recommended_action = "CONTACT_SUPPORT"
7272
stage = [
7373
'''
@@ -96,7 +96,7 @@ config: |
9696
"$map": {
9797
"input": {
9898
"$filter": {
99-
"input": "$healthevent.entitiesimpacted",
99+
"input": {"$ifNull": ["$healthevent.entitiesimpacted", []]},
100100
"cond": {"$eq": ["$$this.entitytype", "GPU"]}
101101
}
102102
},

0 commit comments

Comments
 (0)