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: enable faster db recovery #1020

Merged
merged 3 commits into from
Mar 15, 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
5 changes: 5 additions & 0 deletions internal/openstack_helm/barbican.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type BarbicanConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/cinder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type CinderConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
7 changes: 7 additions & 0 deletions internal/openstack_helm/database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package openstack_helm

type DatabaseConf struct {
ConnectionRecycleTime int `yaml:"connection_recycle_time,omitempty"`
MaxPoolSize int `yaml:"max_pool_size,omitempty"`
MaxRetries int `yaml:"max_retries,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/designate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type DesignateConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/glance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type GlanceConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/heat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type HeatConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/keystone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type KeystoneConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/magnum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type MagnumConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/manila.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type ManilaConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/neutron.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type NeutronConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/nova.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type NovaConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/octavia.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type OctaviaConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
79 changes: 79 additions & 0 deletions internal/openstack_helm/openstack_helm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package openstack_helm

import (
"gopkg.in/yaml.v2"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/chartutil"
)

type HelmValues struct {
Conf `yaml:"conf"`
}

type Conf struct {
Barbican *BarbicanConf `yaml:"barbican,omitempty"`
Cinder *CinderConf `yaml:"cinder,omitempty"`
Designate *DesignateConf `yaml:"designate,omitempty"`
Glance *GlanceConf `yaml:"glance,omitempty"`
Heat *HeatConf `yaml:"heat,omitempty"`
Keystone *KeystoneConf `yaml:"keystone,omitempty"`
Magnum *MagnumConf `yaml:"magnum,omitempty"`
Manila *ManilaConf `yaml:"manila,omitempty"`
Neutron *NeutronConf `yaml:"neutron,omitempty"`
Nova *NovaConf `yaml:"nova,omitempty"`
Octavia *OctaviaConf `yaml:"octavia,omitempty"`
Placement *PlacementConf `yaml:"placement,omitempty"`
Senlin *SenlinConf `yaml:"senlin,omitempty"`
Staffeln *StaffelnConf `yaml:"staffeln,omitempty"`
}

func (h *HelmValues) YAML() ([]byte, error) {
return yaml.Marshal(h)
}

func (h *HelmValues) NativeHelmValues() (chartutil.Values, error) {
yamlData, err := h.YAML()
if err != nil {
return nil, err
}

return chartutil.ReadValues(yamlData)
}

func FromYAML(yamlData []byte) (*HelmValues, error) {
var helmValues HelmValues
err := yaml.Unmarshal(yamlData, &helmValues)
if err != nil {
return nil, err
}

return &helmValues, nil
}

func FromYAMLString(yamlString string) (*HelmValues, error) {
return FromYAML([]byte(yamlString))
}

func CoalescedHelmValues(name string, values *HelmValues) (*HelmValues, error) {
chart, err := loader.Load(name)
if err != nil {
return nil, err
}

releaseValues, err := values.NativeHelmValues()
if err != nil {
return nil, err
}

mergedValues, err := chartutil.CoalesceValues(chart, releaseValues)
if err != nil {
return nil, err
}

yamlData, err := mergedValues.YAML()
if err != nil {
return nil, err
}

return FromYAMLString(yamlData)
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/placement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type PlacementConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
10 changes: 10 additions & 0 deletions internal/openstack_helm/senlin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package openstack_helm

type SenlinConf struct {
API SenlinAPIConf `yaml:"senlin_api"`
Database *DatabaseConf `yaml:"database,omitempty"`
}

type SenlinAPIConf struct {
Workers int32 `yaml:"workers"`
}
5 changes: 5 additions & 0 deletions internal/openstack_helm/staffeln.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package openstack_helm

type StaffelnConf struct {
Database *DatabaseConf `yaml:"database,omitempty"`
}
15 changes: 15 additions & 0 deletions internal/testutils/oslo_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testutils

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/vexxhost/atmosphere/internal/openstack_helm"
)

func TestDatabaseConf(t *testing.T, config *openstack_helm.DatabaseConf) {
assert.Equal(t, 10, config.ConnectionRecycleTime)
assert.Equal(t, 1, config.MaxPoolSize)
assert.Equal(t, -1, config.MaxRetries)
}
3 changes: 3 additions & 0 deletions roles/barbican/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ _barbican_helm_values:
barbican:
DEFAULT:
log_config_append: null
database:
connection_recycle_time: 10
max_pool_size: 1
oslo_messaging_notifications:
driver: noop
simple_crypto_plugin:
Expand Down
39 changes: 39 additions & 0 deletions roles/barbican/vars_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package barbican

import (
_ "embed"
"os"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"

"github.com/vexxhost/atmosphere/internal/openstack_helm"
"github.com/vexxhost/atmosphere/internal/testutils"
)

var (
//go:embed vars/main.yml
varsFile []byte
vars Vars
)

type Vars struct {
openstack_helm.HelmValues `yaml:"_barbican_helm_values"`
}

func TestMain(m *testing.M) {
t := &testing.T{}
err := yaml.UnmarshalWithOptions(varsFile, &vars)
require.NoError(t, err)

code := m.Run()
os.Exit(code)
}

func TestHelmValues(t *testing.T) {
vals, err := openstack_helm.CoalescedHelmValues("../../charts/barbican", &vars.HelmValues)
require.NoError(t, err)

testutils.TestDatabaseConf(t, vals.Conf.Barbican.Database)
}
3 changes: 3 additions & 0 deletions roles/cinder/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ __cinder_helm_values:
barbican_endpoint_type: internal
cors:
allowed_origins: "*"
database:
connection_recycle_time: 10
max_pool_size: 1
oslo_messaging_notifications:
driver: noop
manifests:
Expand Down
39 changes: 39 additions & 0 deletions roles/cinder/vars_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cinder

import (
_ "embed"
"os"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"

"github.com/vexxhost/atmosphere/internal/openstack_helm"
"github.com/vexxhost/atmosphere/internal/testutils"
)

var (
//go:embed vars/main.yml
varsFile []byte
vars Vars
)

type Vars struct {
openstack_helm.HelmValues `yaml:"__cinder_helm_values"`
}

func TestMain(m *testing.M) {
t := &testing.T{}
err := yaml.UnmarshalWithOptions(varsFile, &vars)
require.NoError(t, err)

code := m.Run()
os.Exit(code)
}

func TestHelmValues(t *testing.T) {
vals, err := openstack_helm.CoalescedHelmValues("../../charts/cinder", &vars.HelmValues)
require.NoError(t, err)

testutils.TestDatabaseConf(t, vals.Conf.Cinder.Database)
}
3 changes: 3 additions & 0 deletions roles/designate/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ _designate_helm_values:
tags: "{{ atmosphere_images | vexxhost.atmosphere.openstack_helm_image_tags('designate') }}"
conf:
designate:
database:
connection_recycle_time: 10
max_pool_size: 1
service:central:
managed_resource_tenant_id: "{{ _designate_project_info.openstack_projects[0].id }}"
pools: "{{ designate_pools | to_yaml }}"
Expand Down
39 changes: 39 additions & 0 deletions roles/designate/vars_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package designate

import (
_ "embed"
"os"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"

"github.com/vexxhost/atmosphere/internal/openstack_helm"
"github.com/vexxhost/atmosphere/internal/testutils"
)

var (
//go:embed vars/main.yml
varsFile []byte
vars Vars
)

type Vars struct {
openstack_helm.HelmValues `yaml:"_designate_helm_values"`
}

func TestMain(m *testing.M) {
t := &testing.T{}
err := yaml.UnmarshalWithOptions(varsFile, &vars)
require.NoError(t, err)

code := m.Run()
os.Exit(code)
}

func TestHelmValues(t *testing.T) {
vals, err := openstack_helm.CoalescedHelmValues("../../charts/designate", &vars.HelmValues)
require.NoError(t, err)

testutils.TestDatabaseConf(t, vals.Conf.Designate.Database)
}
3 changes: 3 additions & 0 deletions roles/glance/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ _glance_helm_values:
workers: 8
cors:
allowed_origins: "*"
database:
connection_recycle_time: 10
max_pool_size: 1
image_format:
disk_formats: "qcow2,raw"
oslo_messaging_notifications:
Expand Down
39 changes: 39 additions & 0 deletions roles/glance/vars_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package glance

import (
_ "embed"
"os"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/require"

"github.com/vexxhost/atmosphere/internal/openstack_helm"
"github.com/vexxhost/atmosphere/internal/testutils"
)

var (
//go:embed vars/main.yml
varsFile []byte
vars Vars
)

type Vars struct {
openstack_helm.HelmValues `yaml:"_glance_helm_values"`
}

func TestMain(m *testing.M) {
t := &testing.T{}
err := yaml.UnmarshalWithOptions(varsFile, &vars)
require.NoError(t, err)

code := m.Run()
os.Exit(code)
}

func TestHelmValues(t *testing.T) {
vals, err := openstack_helm.CoalescedHelmValues("../../charts/glance", &vars.HelmValues)
require.NoError(t, err)

testutils.TestDatabaseConf(t, vals.Conf.Glance.Database)
}
Loading
Loading