mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3"
|
|
v1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
)
|
|
|
|
func GetResourcesWithDefault(
|
|
resourceProperties *stackv1beta3.ResourceProperties,
|
|
defaultResources v1.ResourceRequirements,
|
|
) v1.ResourceRequirements {
|
|
if resourceProperties == nil {
|
|
return defaultResources
|
|
}
|
|
|
|
resources := defaultResources
|
|
if resourceProperties.Request != nil {
|
|
if resources.Requests == nil {
|
|
resources.Requests = make(v1.ResourceList)
|
|
}
|
|
|
|
if resourceProperties.Request.Cpu != "" {
|
|
resources.Requests[v1.ResourceCPU] = resource.MustParse(resourceProperties.Request.Cpu)
|
|
}
|
|
|
|
if resourceProperties.Request.Memory != "" {
|
|
resources.Requests[v1.ResourceMemory] = resource.MustParse(resourceProperties.Request.Memory)
|
|
}
|
|
}
|
|
|
|
if resourceProperties.Limits != nil {
|
|
if resources.Limits == nil {
|
|
resources.Limits = make(v1.ResourceList)
|
|
}
|
|
|
|
if resourceProperties.Limits.Cpu != "" {
|
|
resources.Limits[v1.ResourceCPU] = resource.MustParse(resourceProperties.Limits.Cpu)
|
|
}
|
|
|
|
if resourceProperties.Limits.Memory != "" {
|
|
resources.Limits[v1.ResourceMemory] = resource.MustParse(resourceProperties.Limits.Memory)
|
|
}
|
|
}
|
|
|
|
return resources
|
|
}
|
|
|
|
func ModulesToScopes(modules ...Module) []string {
|
|
str := []string{}
|
|
for _, module := range modules {
|
|
str = append(str, fmt.Sprintf("%s:%s", module.Name(), "read"))
|
|
str = append(str, fmt.Sprintf("%s:%s", module.Name(), "write"))
|
|
}
|
|
return str
|
|
}
|