forked from waterme7on/openGauss-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhpaObject.go
37 lines (34 loc) · 1.12 KB
/
hpaObject.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
This files implements helpful utils to manage components of openGauss.
*/
package main
import (
v1 "github.com/waterme7on/openGauss-operator/pkg/apis/opengausscontroller/v1"
"github.com/waterme7on/openGauss-operator/util"
autoscaling "k8s.io/api/autoscaling/v2beta2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
scalerv1 "github.com/waterme7on/openGauss-operator/pkg/apis/autoscaler/v1"
)
func NewHorizontalPodAutoscaler(og *v1.OpenGauss, autoscaler *scalerv1.AutoScaler, id Identity) *autoscaling.HorizontalPodAutoscaler {
hpa := &autoscaling.HorizontalPodAutoscaler{
TypeMeta: metav1.TypeMeta{
Kind: "HorizontalPodAutoscaler",
APIVersion: "autoscaling/v2beta2",
},
ObjectMeta: metav1.ObjectMeta{
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(og, v1.SchemeGroupVersion.WithKind("OpenGauss")),
},
},
}
var formatter util.StatefulsetFormatterInterface
if id == Master {
formatter = util.Master(og)
hpa.Spec = *autoscaler.Spec.Master.Spec
} else {
formatter = util.Replica(og)
hpa.Spec = *autoscaler.Spec.Worker.Spec
}
hpa.Name = formatter.StatefulSetName()
return hpa
}