-
Notifications
You must be signed in to change notification settings - Fork 414
/
azuremanagedcontrolplane_default.go
146 lines (130 loc) · 5.43 KB
/
azuremanagedcontrolplane_default.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright 2021 The Kubernetes Authors.
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 v1beta1
import (
"encoding/base64"
"fmt"
"github.com/Azure/go-autorest/autorest/to"
"golang.org/x/crypto/ssh"
utilSSH "sigs.k8s.io/cluster-api-provider-azure/util/ssh"
)
const (
// defaultAKSVnetCIDR is the default Vnet CIDR.
defaultAKSVnetCIDR = "10.0.0.0/8"
// defaultAKSNodeSubnetCIDR is the default Node Subnet CIDR.
defaultAKSNodeSubnetCIDR = "10.240.0.0/16"
)
// setDefaultSSHPublicKey sets the default SSHPublicKey for an AzureManagedControlPlane.
func (m *AzureManagedControlPlane) setDefaultSSHPublicKey() error {
if sshKeyData := m.Spec.SSHPublicKey; sshKeyData == "" {
_, publicRsaKey, err := utilSSH.GenerateSSHKey()
if err != nil {
return err
}
m.Spec.SSHPublicKey = base64.StdEncoding.EncodeToString(ssh.MarshalAuthorizedKey(publicRsaKey))
}
return nil
}
// setDefaultNodeResourceGroupName sets the default NodeResourceGroup for an AzureManagedControlPlane.
func (m *AzureManagedControlPlane) setDefaultNodeResourceGroupName() {
if m.Spec.NodeResourceGroupName == "" {
m.Spec.NodeResourceGroupName = fmt.Sprintf("MC_%s_%s_%s", m.Spec.ResourceGroupName, m.Name, m.Spec.Location)
}
}
// setDefaultVirtualNetwork sets the default VirtualNetwork for an AzureManagedControlPlane.
func (m *AzureManagedControlPlane) setDefaultVirtualNetwork() {
if m.Spec.VirtualNetwork.Name == "" {
m.Spec.VirtualNetwork.Name = m.Name
}
if m.Spec.VirtualNetwork.CIDRBlock == "" {
m.Spec.VirtualNetwork.CIDRBlock = defaultAKSVnetCIDR
}
if m.Spec.VirtualNetwork.ResourceGroup == "" {
m.Spec.VirtualNetwork.ResourceGroup = m.Spec.ResourceGroupName
}
}
// setDefaultSubnet sets the default Subnet for an AzureManagedControlPlane.
func (m *AzureManagedControlPlane) setDefaultSubnet() {
if m.Spec.VirtualNetwork.Subnet.Name == "" {
m.Spec.VirtualNetwork.Subnet.Name = m.Name
}
if m.Spec.VirtualNetwork.Subnet.CIDRBlock == "" {
m.Spec.VirtualNetwork.Subnet.CIDRBlock = defaultAKSNodeSubnetCIDR
}
}
func (m *AzureManagedControlPlane) setDefaultSku() {
if m.Spec.SKU == nil {
m.Spec.SKU = &SKU{
Tier: FreeManagedControlPlaneTier,
}
}
}
func (m *AzureManagedControlPlane) setDefaultAutoScalerProfile() {
if m.Spec.AutoScalerProfile == nil {
return
}
// Default values are from https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler#using-the-autoscaler-profile
// If any values are set, they all need to be set.
if m.Spec.AutoScalerProfile.BalanceSimilarNodeGroups == nil {
m.Spec.AutoScalerProfile.BalanceSimilarNodeGroups = (*BalanceSimilarNodeGroups)(to.StringPtr(string(BalanceSimilarNodeGroupsFalse)))
}
if m.Spec.AutoScalerProfile.Expander == nil {
m.Spec.AutoScalerProfile.Expander = (*Expander)(to.StringPtr(string(ExpanderRandom)))
}
if m.Spec.AutoScalerProfile.MaxEmptyBulkDelete == nil {
m.Spec.AutoScalerProfile.MaxEmptyBulkDelete = to.StringPtr("10")
}
if m.Spec.AutoScalerProfile.MaxGracefulTerminationSec == nil {
m.Spec.AutoScalerProfile.MaxGracefulTerminationSec = to.StringPtr("600")
}
if m.Spec.AutoScalerProfile.MaxNodeProvisionTime == nil {
m.Spec.AutoScalerProfile.MaxNodeProvisionTime = to.StringPtr("15m")
}
if m.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage == nil {
m.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage = to.StringPtr("45")
}
if m.Spec.AutoScalerProfile.NewPodScaleUpDelay == nil {
m.Spec.AutoScalerProfile.NewPodScaleUpDelay = to.StringPtr("0s")
}
if m.Spec.AutoScalerProfile.OkTotalUnreadyCount == nil {
m.Spec.AutoScalerProfile.OkTotalUnreadyCount = to.StringPtr("3")
}
if m.Spec.AutoScalerProfile.ScanInterval == nil {
m.Spec.AutoScalerProfile.ScanInterval = to.StringPtr("10s")
}
if m.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd == nil {
m.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd = to.StringPtr("10m")
}
if m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete == nil {
// Default is the same as the ScanInterval so default to that same value if it isn't set
m.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete = m.Spec.AutoScalerProfile.ScanInterval
}
if m.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure == nil {
m.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure = to.StringPtr("3m")
}
if m.Spec.AutoScalerProfile.ScaleDownUnneededTime == nil {
m.Spec.AutoScalerProfile.ScaleDownUnneededTime = to.StringPtr("10m")
}
if m.Spec.AutoScalerProfile.ScaleDownUnreadyTime == nil {
m.Spec.AutoScalerProfile.ScaleDownUnreadyTime = to.StringPtr("20m")
}
if m.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold == nil {
m.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold = to.StringPtr("0.5")
}
if m.Spec.AutoScalerProfile.SkipNodesWithLocalStorage == nil {
m.Spec.AutoScalerProfile.SkipNodesWithLocalStorage = (*SkipNodesWithLocalStorage)(to.StringPtr(string(SkipNodesWithLocalStorageFalse)))
}
if m.Spec.AutoScalerProfile.SkipNodesWithSystemPods == nil {
m.Spec.AutoScalerProfile.SkipNodesWithSystemPods = (*SkipNodesWithSystemPods)(to.StringPtr(string(SkipNodesWithSystemPodsTrue)))
}
}