Skip to content

Commit 466123f

Browse files
committed
Update defaults with MemoryLimit field
Signed-off-by: thepetk <thepetk@gmail.com>
1 parent 5036482 commit 466123f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pkg/registry/defaults.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package registry
1919
import (
2020
registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
2121
corev1 "k8s.io/api/core/v1"
22+
"k8s.io/apimachinery/pkg/api/resource"
2223
)
2324

2425
const (
@@ -32,6 +33,11 @@ const (
3233
DefaultRegistryViewerImagePullPolicy = corev1.PullAlways
3334
DefaultOCIRegistryImagePullPolicy = corev1.PullAlways
3435

36+
// Default memory limits
37+
DefaultDevfileIndexMemoryLimit = "256Mi"
38+
DefaultRegistryViewerMemoryLimit = "256Mi"
39+
DefaultOCIRegistryMemoryLimit = "256Mi"
40+
3541
// Defaults/constants for devfile registry storages
3642
DefaultDevfileRegistryVolumeSize = "1Gi"
3743
DevfileRegistryVolumeEnabled = false
@@ -73,6 +79,13 @@ func GetRegistryViewerImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) core
7379
return DefaultRegistryViewerImagePullPolicy
7480
}
7581

82+
// GetRegistryViewerMemoryLimit returns the memory limit for the registry viewer container.
83+
// In case of invalid quantity given, it returns the default value.
84+
// Default: resource.Quantity{s: "256Mi"}
85+
func GetRegistryViewerMemoryLimit(cr *registryv1alpha1.DevfileRegistry) resource.Quantity {
86+
return getDevfileRegistrySpecContainer(cr.Spec.RegistryViewer.MemoryLimit, DefaultRegistryViewerMemoryLimit)
87+
}
88+
7689
// GetOCIRegistryImage returns the container image for the OCI registry to be deployed on the Devfile Registry.
7790
// Default: "quay.io/devfile/oci-registry:next"
7891
func GetOCIRegistryImage(cr *registryv1alpha1.DevfileRegistry) string {
@@ -93,6 +106,13 @@ func GetOCIRegistryImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) corev1.
93106
return DefaultOCIRegistryImagePullPolicy
94107
}
95108

109+
// GetOCIRegistryMemoryLimit returns the memory limit for the OCI registry container.
110+
// In case of invalid quantity given, it returns the default value.
111+
// Default: resource.Quantity{s: "256Mi"}
112+
func GetOCIRegistryMemoryLimit(cr *registryv1alpha1.DevfileRegistry) resource.Quantity {
113+
return getDevfileRegistrySpecContainer(cr.Spec.OciRegistry.MemoryLimit, DefaultOCIRegistryMemoryLimit)
114+
}
115+
96116
// GetDevfileIndexImage returns the container image for the devfile index server to be deployed on the Devfile Registry.
97117
// Default: "quay.io/devfile/devfile-index:next"
98118
func GetDevfileIndexImage(cr *registryv1alpha1.DevfileRegistry) string {
@@ -113,6 +133,13 @@ func GetDevfileIndexImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) corev1
113133
return DefaultDevfileIndexImagePullPolicy
114134
}
115135

136+
// GetDevfileIndexMemoryLimit returns the memory limit for the devfile index container.
137+
// In case of invalid quantity given, it returns the default value.
138+
// Default: resource.Quantity{s: "256Mi"}
139+
func GetDevfileIndexMemoryLimit(cr *registryv1alpha1.DevfileRegistry) resource.Quantity {
140+
return getDevfileRegistrySpecContainer(cr.Spec.DevfileIndex.MemoryLimit, DefaultDevfileIndexMemoryLimit)
141+
}
142+
116143
func getDevfileRegistryVolumeSize(cr *registryv1alpha1.DevfileRegistry) string {
117144
if cr.Spec.Storage.RegistryVolumeSize != "" {
118145
return cr.Spec.Storage.RegistryVolumeSize
@@ -167,3 +194,13 @@ func IsHeadlessEnabled(cr *registryv1alpha1.DevfileRegistry) bool {
167194
}
168195
return DefaultDevfileRegistryHeadlessEnabled
169196
}
197+
198+
func getDevfileRegistrySpecContainer(quantity string, defaultValue string) resource.Quantity {
199+
if quantity != "" {
200+
resourceQuantity, err := resource.ParseQuantity(quantity)
201+
if err == nil {
202+
return resourceQuantity
203+
}
204+
}
205+
return resource.MustParse(defaultValue)
206+
}

0 commit comments

Comments
 (0)