Skip to content

Commit 170361a

Browse files
authored
fix dynconfig with nodeSets panic error (#252)
1 parent a6b1501 commit 170361a

File tree

4 files changed

+53
-137
lines changed

4 files changed

+53
-137
lines changed

api/v1alpha1/storage_webhook.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ func (r *Storage) GetGRPCServiceEndpoint() string {
6363
}
6464

6565
func (r *Storage) GetHostFromConfigEndpoint() string {
66-
var configuration schema.Configuration
67-
66+
var rawYamlConfiguration string
6867
// skip handle error because we already checked in webhook
69-
configuration, _ = ParseConfiguration(r.Spec.Configuration)
68+
success, dynConfig, _ := ParseDynConfig(r.Spec.Configuration)
69+
if success {
70+
config, _ := yaml.Marshal(dynConfig.Config)
71+
rawYamlConfiguration = string(config)
72+
} else {
73+
rawYamlConfiguration = r.Spec.Configuration
74+
}
75+
76+
configuration, _ := ParseConfiguration(rawYamlConfiguration)
7077
randNum := rand.Intn(len(configuration.Hosts)) // #nosec G404
7178
return fmt.Sprintf("%s:%d", configuration.Hosts[randNum].Host, GRPCPort)
7279
}

deploy/ydb-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.5.26
18+
version: 0.5.27
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.5.26"
24+
appVersion: "0.5.27"

e2e/tests/data/storage-mirror-3-dc-config-nodeSets.yaml

Lines changed: 0 additions & 118 deletions
This file was deleted.

e2e/tests/smoke_test.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ func portForward(ctx context.Context, svcName string, svcNamespace string, port
252252
}, Timeout, test.Interval).Should(BeNil())
253253
}
254254

255+
func emptyStorageDefaultFields(storage *v1alpha1.Storage) {
256+
storage.Spec.Image = nil
257+
storage.Spec.Resources = nil
258+
storage.Spec.Service = nil
259+
storage.Spec.Monitoring = nil
260+
}
261+
262+
func emptyDatabaseDefaultFields(database *v1alpha1.Database) {
263+
database.Spec.StorageClusterRef.Namespace = ""
264+
database.Spec.Image = nil
265+
database.Spec.Service = nil
266+
database.Spec.Domain = ""
267+
database.Spec.Path = ""
268+
database.Spec.Encryption = nil
269+
database.Spec.Datastreams = nil
270+
database.Spec.Monitoring = nil
271+
database.Spec.StorageEndpoint = ""
272+
}
273+
255274
var _ = Describe("Operator smoke test", func() {
256275
var ctx context.Context
257276
var namespace corev1.Namespace
@@ -284,30 +303,38 @@ var _ = Describe("Operator smoke test", func() {
284303
})
285304

286305
It("Check webhook defaulter", func() {
287-
storageSample.Spec.Image = nil
288-
storageSample.Spec.Resources = nil
289-
storageSample.Spec.Service = nil
290-
storageSample.Spec.Monitoring = nil
306+
emptyStorageDefaultFields(storageSample)
291307
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
292308
defer func() {
293309
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
294310
}()
295311

296-
databaseSample.Spec.StorageClusterRef.Namespace = ""
297-
databaseSample.Spec.Image = nil
298-
databaseSample.Spec.Service = nil
299-
databaseSample.Spec.Domain = ""
300-
databaseSample.Spec.Path = ""
301-
databaseSample.Spec.Encryption = nil
302-
databaseSample.Spec.Datastreams = nil
303-
databaseSample.Spec.Monitoring = nil
304-
databaseSample.Spec.StorageEndpoint = ""
312+
emptyDatabaseDefaultFields(databaseSample)
305313
Expect(k8sClient.Create(ctx, databaseSample)).Should(Succeed())
306314
defer func() {
307315
Expect(k8sClient.Delete(ctx, databaseSample)).Should(Succeed())
308316
}()
309317
})
310318

319+
It("Check webhook defaulter with dynconfig and nodeSets", func() {
320+
storageSample = testobjects.DefaultStorage(filepath.Join(".", "data", "storage-mirror-3-dc-dynconfig.yaml"))
321+
emptyStorageDefaultFields(storageSample)
322+
storageSample.Spec.NodeSets = []v1alpha1.StorageNodeSetSpecInline{
323+
{
324+
Name: "storage-nodeset-1",
325+
StorageNodeSpec: v1alpha1.StorageNodeSpec{Nodes: 1},
326+
},
327+
{
328+
Name: "storage-nodeset-2",
329+
StorageNodeSpec: v1alpha1.StorageNodeSpec{Nodes: 2},
330+
},
331+
}
332+
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
333+
defer func() {
334+
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
335+
}()
336+
})
337+
311338
It("general smoke pipeline, create storage + database", func() {
312339
By("issuing create commands...")
313340
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
@@ -494,7 +521,7 @@ var _ = Describe("Operator smoke test", func() {
494521

495522
It("create storage and database with nodeSets", func() {
496523
By("issuing create commands...")
497-
storageSample = testobjects.DefaultStorage(filepath.Join(".", "data", "storage-mirror-3-dc-config-nodeSets.yaml"))
524+
storageSample = testobjects.DefaultStorage(filepath.Join(".", "data", "storage-mirror-3-dc-config.yaml"))
498525
testNodeSetName := "nodeset"
499526
for idx := 1; idx <= 3; idx++ {
500527
storageSample.Spec.NodeSets = append(storageSample.Spec.NodeSets, v1alpha1.StorageNodeSetSpecInline{

0 commit comments

Comments
 (0)