-
Notifications
You must be signed in to change notification settings - Fork 479
/
helper.go
95 lines (83 loc) · 3.43 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
91
92
93
94
95
// Copyright 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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
}