github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/util/memory/podmem.go (about)

     1  // Copyright (C) 2021, 2022, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package memory
     5  
     6  import (
     7  	"k8s.io/apimachinery/pkg/api/resource"
     8  )
     9  
    10  // PodMemToJvmHeapArgs converts a pod resource memory to the JVM heap setting
    11  // with same min/max, e.g: "-Xms512m -Xmx512m"
    12  func PodMemToJvmHeapArgs(size, defaultValue string) (string, error) {
    13  	if size == "" {
    14  		return defaultValue, nil
    15  	}
    16  
    17  	s, err := PodMemToJvmHeap(size)
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  	return FormatJvmHeapMinMax(s), nil
    22  }
    23  
    24  // PodMemToJvmHeap converts a pod resource memory (.5Gi) to the JVM heap setting
    25  // in the format java expects (e.g. 512m)
    26  func PodMemToJvmHeap(size string) (string, error) {
    27  	q, err := resource.ParseQuantity(size)
    28  	if err != nil {
    29  		// This will never happen when VO creates the VMI since it formats the values correctly.
    30  		// If someone happened to manually create a VMI this could happen if they format it wrong
    31  		return "", err
    32  	}
    33  	// JVM setting should be around 75% of pod request size
    34  	heap := (q.Value() * 75) / 100
    35  	return FormatJvmHeapSize(heap), nil
    36  }