Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dynconfig with nodeSets panic error #252

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions api/v1alpha1/storage_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ func (r *Storage) GetGRPCServiceEndpoint() string {
}

func (r *Storage) GetHostFromConfigEndpoint() string {
var configuration schema.Configuration

var rawYamlConfiguration string
// skip handle error because we already checked in webhook
configuration, _ = ParseConfiguration(r.Spec.Configuration)
success, dynConfig, _ := ParseDynConfig(r.Spec.Configuration)
if success {
config, _ := yaml.Marshal(dynConfig.Config)
rawYamlConfiguration = string(config)
} else {
rawYamlConfiguration = r.Spec.Configuration
}

configuration, _ := ParseConfiguration(rawYamlConfiguration)
randNum := rand.Intn(len(configuration.Hosts)) // #nosec G404
return fmt.Sprintf("%s:%d", configuration.Hosts[randNum].Host, GRPCPort)
}
Expand Down
4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.26
version: 0.5.27

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.26"
appVersion: "0.5.27"
118 changes: 0 additions & 118 deletions e2e/tests/data/storage-mirror-3-dc-config-nodeSets.yaml

This file was deleted.

55 changes: 41 additions & 14 deletions e2e/tests/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ func portForward(ctx context.Context, svcName string, svcNamespace string, port
}, Timeout, test.Interval).Should(BeNil())
}

func emptyStorageDefaultFields(storage *v1alpha1.Storage) {
storage.Spec.Image = nil
storage.Spec.Resources = nil
storage.Spec.Service = nil
storage.Spec.Monitoring = nil
}

func emptyDatabaseDefaultFields(database *v1alpha1.Database) {
database.Spec.StorageClusterRef.Namespace = ""
database.Spec.Image = nil
database.Spec.Service = nil
database.Spec.Domain = ""
database.Spec.Path = ""
database.Spec.Encryption = nil
database.Spec.Datastreams = nil
database.Spec.Monitoring = nil
database.Spec.StorageEndpoint = ""
}

var _ = Describe("Operator smoke test", func() {
var ctx context.Context
var namespace corev1.Namespace
Expand Down Expand Up @@ -284,30 +303,38 @@ var _ = Describe("Operator smoke test", func() {
})

It("Check webhook defaulter", func() {
storageSample.Spec.Image = nil
storageSample.Spec.Resources = nil
storageSample.Spec.Service = nil
storageSample.Spec.Monitoring = nil
emptyStorageDefaultFields(storageSample)
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
defer func() {
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
}()

databaseSample.Spec.StorageClusterRef.Namespace = ""
databaseSample.Spec.Image = nil
databaseSample.Spec.Service = nil
databaseSample.Spec.Domain = ""
databaseSample.Spec.Path = ""
databaseSample.Spec.Encryption = nil
databaseSample.Spec.Datastreams = nil
databaseSample.Spec.Monitoring = nil
databaseSample.Spec.StorageEndpoint = ""
emptyDatabaseDefaultFields(databaseSample)
Expect(k8sClient.Create(ctx, databaseSample)).Should(Succeed())
defer func() {
Expect(k8sClient.Delete(ctx, databaseSample)).Should(Succeed())
}()
})

It("Check webhook defaulter with dynconfig and nodeSets", func() {
storageSample = testobjects.DefaultStorage(filepath.Join(".", "data", "storage-mirror-3-dc-dynconfig.yaml"))
emptyStorageDefaultFields(storageSample)
storageSample.Spec.NodeSets = []v1alpha1.StorageNodeSetSpecInline{
{
Name: "storage-nodeset-1",
StorageNodeSpec: v1alpha1.StorageNodeSpec{Nodes: 1},
},
{
Name: "storage-nodeset-2",
StorageNodeSpec: v1alpha1.StorageNodeSpec{Nodes: 2},
},
}
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
defer func() {
Expect(k8sClient.Delete(ctx, storageSample)).Should(Succeed())
}()
})

It("general smoke pipeline, create storage + database", func() {
By("issuing create commands...")
Expect(k8sClient.Create(ctx, storageSample)).Should(Succeed())
Expand Down Expand Up @@ -494,7 +521,7 @@ var _ = Describe("Operator smoke test", func() {

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