-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
kubedns.go
117 lines (94 loc) · 3.45 KB
/
kubedns.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
/*
Copyright 2019 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 components
import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/loader"
)
// KubeDnsOptionsBuilder adds options for kube-dns
type KubeDnsOptionsBuilder struct {
Context *OptionsContext
}
var _ loader.OptionsBuilder = &KubeDnsOptionsBuilder{}
// BuildOptions fills in the kubedns model
func (b *KubeDnsOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
if clusterSpec.KubeDNS == nil {
clusterSpec.KubeDNS = &kops.KubeDNSConfig{}
}
if clusterSpec.KubeDNS.CacheMaxSize == 0 {
clusterSpec.KubeDNS.CacheMaxSize = 1000
}
if clusterSpec.KubeDNS.CacheMaxConcurrent == 0 {
clusterSpec.KubeDNS.CacheMaxConcurrent = 150
}
if clusterSpec.KubeDNS.ServerIP == "" {
ip, err := WellKnownServiceIP(&clusterSpec.Networking, 10)
if err != nil {
return err
}
clusterSpec.KubeDNS.ServerIP = ip.String()
}
if clusterSpec.KubeDNS.Domain == "" {
clusterSpec.KubeDNS.Domain = clusterSpec.ClusterDNSDomain
}
if clusterSpec.KubeDNS.MemoryRequest == nil || clusterSpec.KubeDNS.MemoryRequest.IsZero() {
defaultMemoryRequest := resource.MustParse("70Mi")
clusterSpec.KubeDNS.MemoryRequest = &defaultMemoryRequest
}
if clusterSpec.KubeDNS.CPURequest == nil || clusterSpec.KubeDNS.CPURequest.IsZero() {
defaultCPURequest := resource.MustParse("100m")
clusterSpec.KubeDNS.CPURequest = &defaultCPURequest
}
if clusterSpec.KubeDNS.MemoryLimit == nil || clusterSpec.KubeDNS.MemoryLimit.IsZero() {
defaultMemoryLimit := resource.MustParse("170Mi")
clusterSpec.KubeDNS.MemoryLimit = &defaultMemoryLimit
}
if clusterSpec.IsIPv6Only() && clusterSpec.GetCloudProvider() == kops.CloudProviderAWS {
if len(clusterSpec.KubeDNS.UpstreamNameservers) == 0 {
clusterSpec.KubeDNS.UpstreamNameservers = []string{"fd00:ec2::253"}
}
}
nodeLocalDNS := clusterSpec.KubeDNS.NodeLocalDNS
if nodeLocalDNS == nil {
nodeLocalDNS = &kops.NodeLocalDNSConfig{}
clusterSpec.KubeDNS.NodeLocalDNS = nodeLocalDNS
}
if nodeLocalDNS.Enabled == nil {
nodeLocalDNS.Enabled = fi.PtrTo(false)
}
if fi.ValueOf(nodeLocalDNS.Enabled) && nodeLocalDNS.LocalIP == "" {
if clusterSpec.IsIPv6Only() {
nodeLocalDNS.LocalIP = "fd00:90de:d95::1"
} else {
nodeLocalDNS.LocalIP = "169.254.20.10"
}
}
if fi.ValueOf(nodeLocalDNS.Enabled) && nodeLocalDNS.ForwardToKubeDNS == nil {
nodeLocalDNS.ForwardToKubeDNS = fi.PtrTo(false)
}
if nodeLocalDNS.MemoryRequest == nil || nodeLocalDNS.MemoryRequest.IsZero() {
defaultMemoryRequest := resource.MustParse("5Mi")
nodeLocalDNS.MemoryRequest = &defaultMemoryRequest
}
if nodeLocalDNS.CPURequest == nil || nodeLocalDNS.CPURequest.IsZero() {
defaultCPURequest := resource.MustParse("25m")
nodeLocalDNS.CPURequest = &defaultCPURequest
}
if nodeLocalDNS.Image == nil {
nodeLocalDNS.Image = fi.PtrTo("registry.k8s.io/dns/k8s-dns-node-cache:1.22.20")
}
return nil
}