forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
90 lines (77 loc) · 3.14 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package helper
import (
"net"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
)
// ClusterAutoscalerRequired returns whether the given worker pool configuration indicates that a cluster-autoscaler
// is needed.
func ClusterAutoscalerRequired(pools []extensionsv1alpha1.WorkerPool) bool {
for _, pool := range pools {
if pool.Maximum > pool.Minimum {
return true
}
}
return false
}
// GetDNSRecordType returns the appropriate DNS record type (A/AAAA or CNAME) for the given address.
func GetDNSRecordType(address string) extensionsv1alpha1.DNSRecordType {
if ip := net.ParseIP(address); ip != nil {
if ip.To4() != nil {
return extensionsv1alpha1.DNSRecordTypeA
}
return extensionsv1alpha1.DNSRecordTypeAAAA
}
return extensionsv1alpha1.DNSRecordTypeCNAME
}
// GetDNSRecordTTL returns the value of the given ttl, or 120 if nil.
func GetDNSRecordTTL(ttl *int64) int64 {
if ttl != nil {
return *ttl
}
return 120
}
// DeterminePrimaryIPFamily determines the primary IP family out of a specified list of IP families.
func DeterminePrimaryIPFamily(ipFamilies []extensionsv1alpha1.IPFamily) extensionsv1alpha1.IPFamily {
if len(ipFamilies) == 0 {
return extensionsv1alpha1.IPFamilyIPv4
}
return ipFamilies[0]
}
// FilePathsFrom returns the paths for all the given files.
func FilePathsFrom(files []extensionsv1alpha1.File) []string {
var out []string
for _, file := range files {
out = append(out, file.Path)
}
return out
}
// GetMachineDeploymentClusterAutoscalerAnnotations returns a map of annotations with values intended to be used as cluster-autoscaler options for the worker group
func GetMachineDeploymentClusterAutoscalerAnnotations(caOptions *extensionsv1alpha1.ClusterAutoscalerOptions) map[string]string {
var annotations map[string]string
if caOptions != nil {
annotations = map[string]string{}
if caOptions.ScaleDownUtilizationThreshold != nil {
annotations[extensionsv1alpha1.ScaleDownUtilizationThresholdAnnotation] = *caOptions.ScaleDownUtilizationThreshold
}
if caOptions.ScaleDownGpuUtilizationThreshold != nil {
annotations[extensionsv1alpha1.ScaleDownGpuUtilizationThresholdAnnotation] = *caOptions.ScaleDownGpuUtilizationThreshold
}
if caOptions.ScaleDownUnneededTime != nil {
annotations[extensionsv1alpha1.ScaleDownUnneededTimeAnnotation] = caOptions.ScaleDownUnneededTime.Duration.String()
}
if caOptions.ScaleDownUnreadyTime != nil {
annotations[extensionsv1alpha1.ScaleDownUnreadyTimeAnnotation] = caOptions.ScaleDownUnreadyTime.Duration.String()
}
if caOptions.MaxNodeProvisionTime != nil {
annotations[extensionsv1alpha1.MaxNodeProvisionTimeAnnotation] = caOptions.MaxNodeProvisionTime.Duration.String()
}
}
return annotations
}
// HasContainerdConfiguration returns true if containerd is the configured CRI and has a proper configuration.
func HasContainerdConfiguration(criConfig *extensionsv1alpha1.CRIConfig) bool {
return criConfig != nil && criConfig.Name == extensionsv1alpha1.CRINameContainerD && criConfig.Containerd != nil
}