mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Extract CalculateMemoryReservation function into ArangoDeployment Group Spec (#1472)
This commit is contained in:
parent
638425b684
commit
11ffb30e42
7 changed files with 114 additions and 31 deletions
|
@ -16,6 +16,7 @@
|
|||
- (Documentation) Use OpenAPI-compatible type names in docs
|
||||
- (Improvement) Use agency cache lock in metrics exporter
|
||||
- (Maintenance) Remove `scale_down_candidate` annotation
|
||||
- (Maintenance) Extract CalculateMemoryReservation function into ArangoDeployment Group Spec
|
||||
|
||||
## [1.2.34](https://github.com/arangodb/kube-arangodb/tree/1.2.34) (2023-10-16)
|
||||
- (Bugfix) Fix make manifests-crd-file command
|
||||
|
|
|
@ -180,9 +180,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.agents.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
@ -1024,9 +1024,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.coordinators.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
@ -1756,9 +1756,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.dbservers.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
@ -2972,9 +2972,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.single.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
@ -3869,9 +3869,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.syncmasters.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
@ -4595,9 +4595,9 @@ MaxCount specifies a maximum for the count of servers. If set, a specification i
|
|||
|
||||
### .spec.syncworkers.memoryReservation: integer
|
||||
|
||||
MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
|
||||
Links:
|
||||
* [Docs of the ArangoDB Envs](https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/)
|
||||
|
|
|
@ -99,9 +99,9 @@ type ServerGroupSpec struct {
|
|||
// +doc/default: true
|
||||
// +doc/link: Docs of the ArangoDB Envs|https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/
|
||||
OverrideDetectedTotalMemory *bool `json:"overrideDetectedTotalMemory,omitempty"`
|
||||
// MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
// If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
// Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
// MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
// If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
// Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
// +doc/default: 0
|
||||
// +doc/link: Docs of the ArangoDB Envs|https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/
|
||||
MemoryReservation *int64 `json:"memoryReservation,omitempty"`
|
||||
|
@ -796,7 +796,11 @@ func (s *ServerGroupSpec) GetExporterPort() uint16 {
|
|||
func (s *ServerGroupSpec) GetMemoryReservation() int64 {
|
||||
if s != nil {
|
||||
if v := s.MemoryReservation; v != nil {
|
||||
if q := *v; q >= 0 && q <= 50 {
|
||||
if q := *v; q < 0 {
|
||||
return 0
|
||||
} else if q > 50 {
|
||||
return 50
|
||||
} else {
|
||||
return q
|
||||
}
|
||||
}
|
||||
|
@ -804,3 +808,11 @@ func (s *ServerGroupSpec) GetMemoryReservation() int64 {
|
|||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *ServerGroupSpec) CalculateMemoryReservation(memory int64) int64 {
|
||||
if r := s.GetMemoryReservation(); r > 0 {
|
||||
return int64((float64(memory)) * (float64(100-r) / 100))
|
||||
}
|
||||
|
||||
return memory
|
||||
}
|
||||
|
|
|
@ -130,3 +130,34 @@ func TestServerGroupSpecValidateArgs(t *testing.T) {
|
|||
assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment))
|
||||
assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment))
|
||||
}
|
||||
|
||||
func TestServerGroupSpecMemoryReservation(t *testing.T) {
|
||||
// If group is nil
|
||||
assert.EqualValues(t, 1024, (*ServerGroupSpec)(nil).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is nil
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 0
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](0)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is -1
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](-1)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 10
|
||||
assert.EqualValues(t, 921, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](10)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 25
|
||||
assert.EqualValues(t, 768, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](25)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 50
|
||||
assert.EqualValues(t, 512, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](50)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 51
|
||||
assert.EqualValues(t, 512, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](51)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is int max
|
||||
assert.EqualValues(t, 576460752303423488, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](50)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
assert.EqualValues(t, 864691128455135232, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](25)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
assert.EqualValues(t, 1037629354146162304, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](10)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
}
|
||||
|
|
|
@ -99,9 +99,9 @@ type ServerGroupSpec struct {
|
|||
// +doc/default: true
|
||||
// +doc/link: Docs of the ArangoDB Envs|https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/
|
||||
OverrideDetectedTotalMemory *bool `json:"overrideDetectedTotalMemory,omitempty"`
|
||||
// MemoryReservation determines system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
// If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by specified value in percents.
|
||||
// Accepted Range <0, 50>. If value is outside accepted range, it is adjusted to the closest value.
|
||||
// MemoryReservation determines the system reservation of memory while calculating `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` value.
|
||||
// If this field is set, `ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY` is reduced by a specified value in percent.
|
||||
// Accepted Range <0, 50>. If the value is outside the accepted range, it is adjusted to the closest value.
|
||||
// +doc/default: 0
|
||||
// +doc/link: Docs of the ArangoDB Envs|https://docs.arangodb.com/devel/components/arangodb-server/environment-variables/
|
||||
MemoryReservation *int64 `json:"memoryReservation,omitempty"`
|
||||
|
@ -796,7 +796,11 @@ func (s *ServerGroupSpec) GetExporterPort() uint16 {
|
|||
func (s *ServerGroupSpec) GetMemoryReservation() int64 {
|
||||
if s != nil {
|
||||
if v := s.MemoryReservation; v != nil {
|
||||
if q := *v; q >= 0 && q <= 50 {
|
||||
if q := *v; q < 0 {
|
||||
return 0
|
||||
} else if q > 50 {
|
||||
return 50
|
||||
} else {
|
||||
return q
|
||||
}
|
||||
}
|
||||
|
@ -804,3 +808,11 @@ func (s *ServerGroupSpec) GetMemoryReservation() int64 {
|
|||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *ServerGroupSpec) CalculateMemoryReservation(memory int64) int64 {
|
||||
if r := s.GetMemoryReservation(); r > 0 {
|
||||
return int64((float64(memory)) * (float64(100-r) / 100))
|
||||
}
|
||||
|
||||
return memory
|
||||
}
|
||||
|
|
|
@ -130,3 +130,34 @@ func TestServerGroupSpecValidateArgs(t *testing.T) {
|
|||
assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment))
|
||||
assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment))
|
||||
}
|
||||
|
||||
func TestServerGroupSpecMemoryReservation(t *testing.T) {
|
||||
// If group is nil
|
||||
assert.EqualValues(t, 1024, (*ServerGroupSpec)(nil).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is nil
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 0
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](0)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is -1
|
||||
assert.EqualValues(t, 1024, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](-1)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 10
|
||||
assert.EqualValues(t, 921, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](10)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 25
|
||||
assert.EqualValues(t, 768, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](25)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 50
|
||||
assert.EqualValues(t, 512, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](50)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is 51
|
||||
assert.EqualValues(t, 512, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](51)}).CalculateMemoryReservation(1024))
|
||||
|
||||
// If reservation is int max
|
||||
assert.EqualValues(t, 576460752303423488, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](50)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
assert.EqualValues(t, 864691128455135232, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](25)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
assert.EqualValues(t, 1037629354146162304, (&ServerGroupSpec{MemoryReservation: util.NewType[int64](10)}).CalculateMemoryReservation(0xFFFFFFFFFFFFFFF))
|
||||
}
|
||||
|
|
|
@ -213,11 +213,7 @@ func (a *ArangoDContainer) GetEnvs() ([]core.EnvVar, []core.EnvFromSource) {
|
|||
if resources.Limits != nil {
|
||||
if a.groupSpec.GetOverrideDetectedTotalMemory() {
|
||||
if limits, ok := resources.Limits[core.ResourceMemory]; ok {
|
||||
value := limits.Value()
|
||||
|
||||
if memoryReservation := a.groupSpec.GetMemoryReservation(); memoryReservation > 0 {
|
||||
value = (value / 100) * (100 - memoryReservation)
|
||||
}
|
||||
value := a.groupSpec.CalculateMemoryReservation(limits.Value())
|
||||
|
||||
envs.Add(true, core.EnvVar{
|
||||
Name: ArangoDBOverrideDetectedTotalMemoryEnv,
|
||||
|
|
Loading…
Reference in a new issue