@@ -36,7 +36,10 @@ import (
3636)
3737
3838const (
39- collectorVPAName = "collector"
39+ alertmanagerVPAName = "alertmanager"
40+ collectorVPAName = "collector"
41+ operatorVPAName = "gmp-operator"
42+ ruleEvaluatorVPAName = "rule-evaluator"
4043)
4144
4245type scalingReconciler struct {
@@ -96,14 +99,53 @@ func (r *scalingReconciler) Reconcile(ctx context.Context, req reconcile.Request
9699}
97100
98101func applyVPA (ctx context.Context , c client.Client , namespace string ) error {
99- vpa := autoscalingv1.VerticalPodAutoscaler {
102+ alertmanagerVPA := autoscalingv1.VerticalPodAutoscaler {
103+ ObjectMeta : metav1.ObjectMeta {
104+ Namespace : namespace ,
105+ Name : alertmanagerVPAName ,
106+ },
107+ }
108+ if _ , err := controllerutil .CreateOrUpdate (ctx , c , & alertmanagerVPA , func () error {
109+ alertmanagerVPA .Spec = autoscalingv1.VerticalPodAutoscalerSpec {
110+ TargetRef : & autoscaling.CrossVersionObjectReference {
111+ APIVersion : "apps/v1" ,
112+ Kind : "StatefulSet" ,
113+ Name : alertmanagerVPAName ,
114+ },
115+ UpdatePolicy : & autoscalingv1.PodUpdatePolicy {
116+ MinReplicas : ptr .To (int32 (1 )),
117+ UpdateMode : ptr .To (autoscalingv1 .UpdateModeAuto ),
118+ },
119+ ResourcePolicy : & autoscalingv1.PodResourcePolicy {
120+ ContainerPolicies : []autoscalingv1.ContainerResourcePolicy {
121+ {
122+ ContainerName : "alertmanager" ,
123+ Mode : ptr .To (autoscalingv1 .ContainerScalingModeAuto ),
124+ MinAllowed : corev1.ResourceList {
125+ corev1 .ResourceCPU : resource .MustParse ("1m" ),
126+ corev1 .ResourceMemory : resource .MustParse ("16Mi" ),
127+ },
128+ },
129+ {
130+ ContainerName : "config-reloader" ,
131+ Mode : ptr .To (autoscalingv1 .ContainerScalingModeOff ),
132+ },
133+ },
134+ },
135+ }
136+ return nil
137+ }); err != nil {
138+ return err
139+ }
140+
141+ collectorVPA := autoscalingv1.VerticalPodAutoscaler {
100142 ObjectMeta : metav1.ObjectMeta {
101143 Namespace : namespace ,
102144 Name : collectorVPAName ,
103145 },
104146 }
105- if _ , err := controllerutil .CreateOrUpdate (ctx , c , & vpa , func () error {
106- vpa .Spec = autoscalingv1.VerticalPodAutoscalerSpec {
147+ if _ , err := controllerutil .CreateOrUpdate (ctx , c , & collectorVPA , func () error {
148+ collectorVPA .Spec = autoscalingv1.VerticalPodAutoscalerSpec {
107149 TargetRef : & autoscaling.CrossVersionObjectReference {
108150 APIVersion : "apps/v1" ,
109151 Kind : "DaemonSet" ,
@@ -118,6 +160,7 @@ func applyVPA(ctx context.Context, c client.Client, namespace string) error {
118160 ContainerName : "prometheus" ,
119161 Mode : ptr .To (autoscalingv1 .ContainerScalingModeAuto ),
120162 MinAllowed : corev1.ResourceList {
163+ corev1 .ResourceCPU : resource .MustParse ("4m" ),
121164 corev1 .ResourceMemory : resource .MustParse ("32Mi" ),
122165 },
123166 },
@@ -132,18 +175,124 @@ func applyVPA(ctx context.Context, c client.Client, namespace string) error {
132175 }); err != nil {
133176 return err
134177 }
178+
179+ operatorVPA := autoscalingv1.VerticalPodAutoscaler {
180+ ObjectMeta : metav1.ObjectMeta {
181+ Namespace : namespace ,
182+ Name : operatorVPAName ,
183+ },
184+ }
185+ if _ , err := controllerutil .CreateOrUpdate (ctx , c , & operatorVPA , func () error {
186+ collectorVPA .Spec = autoscalingv1.VerticalPodAutoscalerSpec {
187+ TargetRef : & autoscaling.CrossVersionObjectReference {
188+ APIVersion : "apps/v1" ,
189+ Kind : "Deployment" ,
190+ Name : operatorVPAName ,
191+ },
192+ UpdatePolicy : & autoscalingv1.PodUpdatePolicy {
193+ MinReplicas : ptr .To (int32 (1 )),
194+ UpdateMode : ptr .To (autoscalingv1 .UpdateModeAuto ),
195+ },
196+ ResourcePolicy : & autoscalingv1.PodResourcePolicy {
197+ ContainerPolicies : []autoscalingv1.ContainerResourcePolicy {
198+ {
199+ ContainerName : "operator" ,
200+ Mode : ptr .To (autoscalingv1 .ContainerScalingModeAuto ),
201+ MinAllowed : corev1.ResourceList {
202+ corev1 .ResourceCPU : resource .MustParse ("1m" ),
203+ corev1 .ResourceMemory : resource .MustParse ("16Mi" ),
204+ },
205+ },
206+ },
207+ },
208+ }
209+ return nil
210+ }); err != nil {
211+ return err
212+ }
213+
214+ ruleEvaluatorVPA := autoscalingv1.VerticalPodAutoscaler {
215+ ObjectMeta : metav1.ObjectMeta {
216+ Namespace : namespace ,
217+ Name : ruleEvaluatorVPAName ,
218+ },
219+ }
220+ if _ , err := controllerutil .CreateOrUpdate (ctx , c , & ruleEvaluatorVPA , func () error {
221+ collectorVPA .Spec = autoscalingv1.VerticalPodAutoscalerSpec {
222+ TargetRef : & autoscaling.CrossVersionObjectReference {
223+ APIVersion : "apps/v1" ,
224+ Kind : "Deployment" ,
225+ Name : ruleEvaluatorVPAName ,
226+ },
227+ UpdatePolicy : & autoscalingv1.PodUpdatePolicy {
228+ MinReplicas : ptr .To (int32 (1 )),
229+ UpdateMode : ptr .To (autoscalingv1 .UpdateModeAuto ),
230+ },
231+ ResourcePolicy : & autoscalingv1.PodResourcePolicy {
232+ ContainerPolicies : []autoscalingv1.ContainerResourcePolicy {
233+ {
234+ ContainerName : "evaluator" ,
235+ Mode : ptr .To (autoscalingv1 .ContainerScalingModeAuto ),
236+ MinAllowed : corev1.ResourceList {
237+ corev1 .ResourceCPU : resource .MustParse ("1m" ),
238+ corev1 .ResourceMemory : resource .MustParse ("16Mi" ),
239+ },
240+ },
241+ {
242+ ContainerName : "config-reloader" ,
243+ Mode : ptr .To (autoscalingv1 .ContainerScalingModeOff ),
244+ },
245+ },
246+ },
247+ }
248+ return nil
249+ }); err != nil {
250+ return err
251+ }
252+
135253 return nil
136254}
137255
138256func deleteVPA (ctx context.Context , c client.Writer , namespace string ) error {
139- vpa := autoscalingv1.VerticalPodAutoscaler {
257+ alertmanagerVPA := autoscalingv1.VerticalPodAutoscaler {
258+ ObjectMeta : metav1.ObjectMeta {
259+ Name : alertmanagerVPAName ,
260+ Namespace : namespace ,
261+ },
262+ }
263+ if err := c .Delete (ctx , & alertmanagerVPA ); client .IgnoreNotFound (err ) != nil {
264+ return err
265+ }
266+
267+ collectorVPA := autoscalingv1.VerticalPodAutoscaler {
140268 ObjectMeta : metav1.ObjectMeta {
141269 Name : collectorVPAName ,
142270 Namespace : namespace ,
143271 },
144272 }
145- if err := c .Delete (ctx , & vpa ); client .IgnoreNotFound (err ) != nil {
273+ if err := c .Delete (ctx , & collectorVPA ); client .IgnoreNotFound (err ) != nil {
146274 return err
147275 }
276+
277+ operatorVPA := autoscalingv1.VerticalPodAutoscaler {
278+ ObjectMeta : metav1.ObjectMeta {
279+ Name : operatorVPAName ,
280+ Namespace : namespace ,
281+ },
282+ }
283+ if err := c .Delete (ctx , & operatorVPA ); client .IgnoreNotFound (err ) != nil {
284+ return err
285+ }
286+
287+ ruleEvaluatorVPA := autoscalingv1.VerticalPodAutoscaler {
288+ ObjectMeta : metav1.ObjectMeta {
289+ Name : ruleEvaluatorVPAName ,
290+ Namespace : namespace ,
291+ },
292+ }
293+ if err := c .Delete (ctx , & ruleEvaluatorVPA ); client .IgnoreNotFound (err ) != nil {
294+ return err
295+ }
296+
148297 return nil
149298}
0 commit comments