-
Notifications
You must be signed in to change notification settings - Fork 31
/
scaling_helper.go
43 lines (38 loc) · 1.19 KB
/
scaling_helper.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
38
39
40
41
42
43
package scaling
import (
"strings"
"github.com/test-network-function/cnf-certification-test/pkg/configuration"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiv1 "k8s.io/apimachinery/pkg/apis/meta/v1"
scalingv1 "k8s.io/api/autoscaling/v1"
)
func GetResourceHPA(hpaList []*scalingv1.HorizontalPodAutoscaler, name, namespace, kind string) *scalingv1.HorizontalPodAutoscaler {
for _, hpa := range hpaList {
if hpa.Spec.ScaleTargetRef.Kind == kind && hpa.Spec.ScaleTargetRef.Name == name && hpa.Namespace == namespace {
return hpa
}
}
return nil
}
func IsManaged(podSetName string, managedPodSet []configuration.ManagedDeploymentsStatefulsets) bool {
for _, ps := range managedPodSet {
if ps.Name == podSetName {
return true
}
}
return false
}
func CheckOwnerReference(ownerReference []apiv1.OwnerReference, crdFilter []configuration.CrdFilter, crds []*apiextv1.CustomResourceDefinition) bool {
for _, owner := range ownerReference {
for _, aCrd := range crds {
if aCrd.Spec.Names.Kind == owner.Kind {
for _, crdF := range crdFilter {
if strings.HasSuffix(aCrd.Name, crdF.NameSuffix) {
return crdF.Scalable
}
}
}
}
}
return false
}