@@ -19,6 +19,7 @@ package registry
19
19
import (
20
20
registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
21
21
corev1 "k8s.io/api/core/v1"
22
+ "k8s.io/apimachinery/pkg/api/resource"
22
23
)
23
24
24
25
const (
@@ -32,6 +33,11 @@ const (
32
33
DefaultRegistryViewerImagePullPolicy = corev1 .PullAlways
33
34
DefaultOCIRegistryImagePullPolicy = corev1 .PullAlways
34
35
36
+ // Default memory limits
37
+ DefaultDevfileIndexMemoryLimit = "256Mi"
38
+ DefaultRegistryViewerMemoryLimit = "256Mi"
39
+ DefaultOCIRegistryMemoryLimit = "256Mi"
40
+
35
41
// Defaults/constants for devfile registry storages
36
42
DefaultDevfileRegistryVolumeSize = "1Gi"
37
43
DevfileRegistryVolumeEnabled = false
@@ -73,6 +79,13 @@ func GetRegistryViewerImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) core
73
79
return DefaultRegistryViewerImagePullPolicy
74
80
}
75
81
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
+
76
89
// GetOCIRegistryImage returns the container image for the OCI registry to be deployed on the Devfile Registry.
77
90
// Default: "quay.io/devfile/oci-registry:next"
78
91
func GetOCIRegistryImage (cr * registryv1alpha1.DevfileRegistry ) string {
@@ -93,6 +106,13 @@ func GetOCIRegistryImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) corev1.
93
106
return DefaultOCIRegistryImagePullPolicy
94
107
}
95
108
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
+
96
116
// GetDevfileIndexImage returns the container image for the devfile index server to be deployed on the Devfile Registry.
97
117
// Default: "quay.io/devfile/devfile-index:next"
98
118
func GetDevfileIndexImage (cr * registryv1alpha1.DevfileRegistry ) string {
@@ -113,6 +133,13 @@ func GetDevfileIndexImagePullPolicy(cr *registryv1alpha1.DevfileRegistry) corev1
113
133
return DefaultDevfileIndexImagePullPolicy
114
134
}
115
135
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
+
116
143
func getDevfileRegistryVolumeSize (cr * registryv1alpha1.DevfileRegistry ) string {
117
144
if cr .Spec .Storage .RegistryVolumeSize != "" {
118
145
return cr .Spec .Storage .RegistryVolumeSize
@@ -167,3 +194,13 @@ func IsHeadlessEnabled(cr *registryv1alpha1.DevfileRegistry) bool {
167
194
}
168
195
return DefaultDevfileRegistryHeadlessEnabled
169
196
}
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