Skip to content

Commit

Permalink
memory requests and limits padding fix when requests = limits (#692)
Browse files Browse the repository at this point in the history
* add helm-docs to bump script

* fix memory padding when requests and limits are equal

* Update common.go
  • Loading branch information
freeznet authored Oct 23, 2023
1 parent 606dc73 commit da5a0c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,15 @@ func getPythonSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef) []str
return ret
}

func calcInstanceMemoryResources(resources corev1.ResourceRequirements) *resource.Quantity {
if resources.Requests.Memory() == resources.Limits.Memory() {
// if request and limit are the same, use the value * 0.9 as the instance (JVM) memory size, to prevent OOM
return resource.NewQuantity(int64(float64(resources.Requests.Memory().Value())*0.9), resource.DecimalSI)
}
// if request and limit are different, use the request value as the instance (JVM) memory size
return resources.Requests.Memory()
}

func getGenericSecretProviderArgs(secretMaps map[string]v1alpha1.SecretRef, language string) []string {
var ret []string
if len(secretMaps) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
generateFunctionDetailsInJSON(function),
spec.Java.ExtraDependenciesDir,
string(function.UID),
spec.Resources.Requests.Memory(),
calcInstanceMemoryResources(spec.Resources),
spec.Java.JavaOpts, hasPulsarctl, hasWget,
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig,
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func MakeSinkCommand(sink *v1alpha1.Sink) []string {
parseJavaLogLevel(spec.Java),
generateSinkDetailsInJSON(sink),
spec.Java.ExtraDependenciesDir, string(sink.UID),
spec.Resources.Requests.Memory(),
calcInstanceMemoryResources(spec.Resources),
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
generateJavaLogConfigFileName(spec.Java))
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func makeSourceCommand(source *v1alpha1.Source) []string {
parseJavaLogLevel(spec.Java),
generateSourceDetailsInJSON(source),
spec.Java.ExtraDependenciesDir, string(source.UID),
spec.Resources.Requests.Memory(),
calcInstanceMemoryResources(spec.Resources),
spec.Java.JavaOpts, hasPulsarctl, hasWget, spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "",
spec.SecretsMap, spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig, nil,
generateJavaLogConfigFileName(spec.Java))
Expand Down

0 comments on commit da5a0c2

Please sign in to comment.