mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: make cache and max-sql-memory configurable for cockroachdb (#2483)
This commit is contained in:
parent
cc0d8b0b7a
commit
1ca2d8adde
@ -134,6 +134,8 @@ func Adapter(
|
||||
desiredKind.Spec.NodeSelector,
|
||||
desiredKind.Spec.Tolerations,
|
||||
desiredKind.Spec.Resources,
|
||||
desiredKind.Spec.Cache,
|
||||
desiredKind.Spec.MaxSQLMemory,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, false, err
|
||||
|
@ -26,6 +26,8 @@ type Spec struct {
|
||||
ClusterDns string `yaml:"clusterDNS,omitempty"`
|
||||
Backups map[string]*tree.Tree `yaml:"backups,omitempty"`
|
||||
Resources *k8s.Resources `yaml:"resources,omitempty"`
|
||||
MaxSQLMemory string `yaml:"maxSqlMemory,omitempty"`
|
||||
Cache string `yaml:"cache,omitempty"`
|
||||
}
|
||||
|
||||
func parseDesiredV0(desiredTree *tree.Tree) (*DesiredV0, error) {
|
||||
|
@ -63,6 +63,8 @@ func AdaptFunc(
|
||||
nodeSelector map[string]string,
|
||||
tolerations []corev1.Toleration,
|
||||
resourcesSFS *k8s.Resources,
|
||||
cache string,
|
||||
maxSqlMemory string,
|
||||
) (
|
||||
resources.QueryFunc,
|
||||
resources.DestroyFunc,
|
||||
@ -149,6 +151,8 @@ func AdaptFunc(
|
||||
name,
|
||||
int(dbPort),
|
||||
replicaCount,
|
||||
getCache(cache),
|
||||
getMaxSqlMemory(maxSqlMemory),
|
||||
),
|
||||
},
|
||||
Resources: getResources(resourcesSFS),
|
||||
@ -286,7 +290,14 @@ func AdaptFunc(
|
||||
return wrapedQuery, wrapedDestroy, ensureInit, checkDBReady, getAllDBs, err
|
||||
}
|
||||
|
||||
func getJoinExec(namespace string, name string, dbPort int, replicaCount int) string {
|
||||
func getJoinExec(
|
||||
namespace string,
|
||||
name string,
|
||||
dbPort int,
|
||||
replicaCount int,
|
||||
cache string,
|
||||
maxSqlMemory string,
|
||||
) string {
|
||||
joinList := make([]string, 0)
|
||||
for i := 0; i < replicaCount; i++ {
|
||||
joinList = append(joinList, fmt.Sprintf("%s-%d.%s.%s:%d", name, i, name, namespace, dbPort))
|
||||
@ -294,7 +305,21 @@ func getJoinExec(namespace string, name string, dbPort int, replicaCount int) st
|
||||
joinListStr := strings.Join(joinList, ",")
|
||||
locality := "zone=" + namespace
|
||||
|
||||
return "exec /cockroach/cockroach start --logtostderr --certs-dir " + certPath + " --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join " + joinListStr + " --locality " + locality + " --cache 25% --max-sql-memory 25%"
|
||||
return "exec /cockroach/cockroach start --logtostderr --certs-dir " + certPath + " --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join " + joinListStr + " --locality " + locality + " --cache " + cache + " --max-sql-memory " + maxSqlMemory
|
||||
}
|
||||
|
||||
func getCache(cache string) string {
|
||||
if cache != "" {
|
||||
return cache
|
||||
}
|
||||
return "10%"
|
||||
}
|
||||
|
||||
func getMaxSqlMemory(maxSqlMemory string) string {
|
||||
if maxSqlMemory != "" {
|
||||
return maxSqlMemory
|
||||
}
|
||||
return "10%"
|
||||
}
|
||||
|
||||
func getResources(resourcesSFS *k8s.Resources) corev1.ResourceRequirements {
|
||||
|
@ -22,9 +22,11 @@ func TestStatefulset_JoinExec0(t *testing.T) {
|
||||
name := "test"
|
||||
dbPort := 26257
|
||||
replicaCount := 0
|
||||
cache := ""
|
||||
maxSqlMemory := ""
|
||||
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join --locality zone=testNs --cache 25% --max-sql-memory 25%"
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount))
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join --locality zone=testNs --cache --max-sql-memory "
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount, cache, maxSqlMemory))
|
||||
}
|
||||
|
||||
func TestStatefulset_JoinExec1(t *testing.T) {
|
||||
@ -32,9 +34,11 @@ func TestStatefulset_JoinExec1(t *testing.T) {
|
||||
name := "test2"
|
||||
dbPort := 26257
|
||||
replicaCount := 1
|
||||
cache := "15%"
|
||||
maxSqlMemory := "15%"
|
||||
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join test2-0.test2.testNs2:26257 --locality zone=testNs2 --cache 25% --max-sql-memory 25%"
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount))
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join test2-0.test2.testNs2:26257 --locality zone=testNs2 --cache 15% --max-sql-memory 15%"
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount, cache, maxSqlMemory))
|
||||
}
|
||||
|
||||
func TestStatefulset_JoinExec2(t *testing.T) {
|
||||
@ -42,9 +46,11 @@ func TestStatefulset_JoinExec2(t *testing.T) {
|
||||
name := "test"
|
||||
dbPort := 23
|
||||
replicaCount := 2
|
||||
cache := "20%"
|
||||
maxSqlMemory := "20%"
|
||||
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join test-0.test.testNs:23,test-1.test.testNs:23 --locality zone=testNs --cache 25% --max-sql-memory 25%"
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount))
|
||||
equals := "exec /cockroach/cockroach start --logtostderr --certs-dir /cockroach/cockroach-certs --advertise-host $(hostname -f) --http-addr 0.0.0.0 --join test-0.test.testNs:23,test-1.test.testNs:23 --locality zone=testNs --cache 20% --max-sql-memory 20%"
|
||||
assert.Equal(t, equals, getJoinExec(namespace, name, dbPort, replicaCount, cache, maxSqlMemory))
|
||||
}
|
||||
|
||||
func TestStatefulset_Resources0(t *testing.T) {
|
||||
@ -150,6 +156,8 @@ func TestStatefulset_Adapt1(t *testing.T) {
|
||||
nodeSelector := map[string]string{}
|
||||
tolerations := []corev1.Toleration{}
|
||||
resourcesSFS := &k8s.Resources{}
|
||||
cache := ""
|
||||
maxSqlMemory := ""
|
||||
|
||||
quantity, err := resource.ParseQuantity(storageCapacity)
|
||||
assert.NoError(t, err)
|
||||
@ -228,6 +236,8 @@ func TestStatefulset_Adapt1(t *testing.T) {
|
||||
name,
|
||||
int(dbPort),
|
||||
replicaCount,
|
||||
getCache(cache),
|
||||
getMaxSqlMemory(maxSqlMemory),
|
||||
),
|
||||
},
|
||||
Resources: getResources(resourcesSFS),
|
||||
@ -299,6 +309,8 @@ func TestStatefulset_Adapt1(t *testing.T) {
|
||||
nodeSelector,
|
||||
tolerations,
|
||||
resourcesSFS,
|
||||
cache,
|
||||
maxSqlMemory,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -346,6 +358,8 @@ func TestStatefulset_Adapt2(t *testing.T) {
|
||||
nodeSelector := map[string]string{}
|
||||
tolerations := []corev1.Toleration{}
|
||||
resourcesSFS := &k8s.Resources{}
|
||||
cache := "20%"
|
||||
maxSqlMemory := "20%"
|
||||
|
||||
quantity, err := resource.ParseQuantity(storageCapacity)
|
||||
assert.NoError(t, err)
|
||||
@ -424,6 +438,8 @@ func TestStatefulset_Adapt2(t *testing.T) {
|
||||
name,
|
||||
int(dbPort),
|
||||
replicaCount,
|
||||
getCache(cache),
|
||||
getMaxSqlMemory(maxSqlMemory),
|
||||
),
|
||||
},
|
||||
Resources: getResources(resourcesSFS),
|
||||
@ -495,6 +511,8 @@ func TestStatefulset_Adapt2(t *testing.T) {
|
||||
nodeSelector,
|
||||
tolerations,
|
||||
resourcesSFS,
|
||||
cache,
|
||||
maxSqlMemory,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user