...
1
16
17 package v1alpha1
18
19 import (
20 "fmt"
21 "time"
22
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 kruntime "k8s.io/apimachinery/pkg/runtime"
25 kubeproxyconfigv1alpha1 "k8s.io/kube-proxy/config/v1alpha1"
26
27 logsapi "k8s.io/component-base/logs/api/v1"
28 "k8s.io/kubernetes/pkg/cluster/ports"
29 "k8s.io/kubernetes/pkg/kubelet/qos"
30 proxyutil "k8s.io/kubernetes/pkg/proxy/util"
31 netutils "k8s.io/utils/net"
32 "k8s.io/utils/ptr"
33 )
34
35 func addDefaultingFuncs(scheme *kruntime.Scheme) error {
36 return RegisterDefaults(scheme)
37 }
38
39 func SetDefaults_KubeProxyConfiguration(obj *kubeproxyconfigv1alpha1.KubeProxyConfiguration) {
40
41 if len(obj.BindAddress) == 0 {
42 obj.BindAddress = "0.0.0.0"
43 }
44
45 defaultHealthzAddress, defaultMetricsAddress := getDefaultAddresses(obj.BindAddress)
46
47 if obj.HealthzBindAddress == "" {
48 obj.HealthzBindAddress = fmt.Sprintf("%s:%v", defaultHealthzAddress, ports.ProxyHealthzPort)
49 } else {
50 obj.HealthzBindAddress = proxyutil.AppendPortIfNeeded(obj.HealthzBindAddress, ports.ProxyHealthzPort)
51 }
52 if obj.MetricsBindAddress == "" {
53 obj.MetricsBindAddress = fmt.Sprintf("%s:%v", defaultMetricsAddress, ports.ProxyStatusPort)
54 } else {
55 obj.MetricsBindAddress = proxyutil.AppendPortIfNeeded(obj.MetricsBindAddress, ports.ProxyStatusPort)
56 }
57
58 if obj.OOMScoreAdj == nil {
59 temp := int32(qos.KubeProxyOOMScoreAdj)
60 obj.OOMScoreAdj = &temp
61 }
62 if obj.IPTables.SyncPeriod.Duration == 0 {
63 obj.IPTables.SyncPeriod = metav1.Duration{Duration: 30 * time.Second}
64 }
65 if obj.IPTables.MinSyncPeriod.Duration == 0 {
66 obj.IPTables.MinSyncPeriod = metav1.Duration{Duration: 1 * time.Second}
67 }
68 if obj.IPTables.LocalhostNodePorts == nil {
69 obj.IPTables.LocalhostNodePorts = ptr.To(true)
70 }
71 if obj.IPVS.SyncPeriod.Duration == 0 {
72 obj.IPVS.SyncPeriod = metav1.Duration{Duration: 30 * time.Second}
73 }
74 if obj.NFTables.SyncPeriod.Duration == 0 {
75 obj.NFTables.SyncPeriod = metav1.Duration{Duration: 30 * time.Second}
76 }
77 if obj.NFTables.MinSyncPeriod.Duration == 0 {
78 obj.NFTables.MinSyncPeriod = metav1.Duration{Duration: 1 * time.Second}
79 }
80
81 if obj.Conntrack.MaxPerCore == nil {
82 obj.Conntrack.MaxPerCore = ptr.To[int32](32 * 1024)
83 }
84 if obj.Conntrack.Min == nil {
85 obj.Conntrack.Min = ptr.To[int32](128 * 1024)
86 }
87
88 if obj.IPTables.MasqueradeBit == nil {
89 temp := int32(14)
90 obj.IPTables.MasqueradeBit = &temp
91 }
92 if obj.NFTables.MasqueradeBit == nil {
93 temp := int32(14)
94 obj.NFTables.MasqueradeBit = &temp
95 }
96 if obj.Conntrack.TCPEstablishedTimeout == nil {
97 obj.Conntrack.TCPEstablishedTimeout = &metav1.Duration{Duration: 24 * time.Hour}
98 }
99 if obj.Conntrack.TCPCloseWaitTimeout == nil {
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 obj.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: 1 * time.Hour}
121 }
122 if obj.ConfigSyncPeriod.Duration == 0 {
123 obj.ConfigSyncPeriod.Duration = 15 * time.Minute
124 }
125
126 if len(obj.ClientConnection.ContentType) == 0 {
127 obj.ClientConnection.ContentType = "application/vnd.kubernetes.protobuf"
128 }
129 if obj.ClientConnection.QPS == 0.0 {
130 obj.ClientConnection.QPS = 5.0
131 }
132 if obj.ClientConnection.Burst == 0 {
133 obj.ClientConnection.Burst = 10
134 }
135 if obj.FeatureGates == nil {
136 obj.FeatureGates = make(map[string]bool)
137 }
138
139 logsapi.SetRecommendedLoggingConfiguration(&obj.Logging)
140 }
141
142
143
144
145 func getDefaultAddresses(bindAddress string) (defaultHealthzAddress, defaultMetricsAddress string) {
146 if netutils.ParseIPSloppy(bindAddress).To4() != nil {
147 return "0.0.0.0", "127.0.0.1"
148 }
149 return "[::]", "[::1]"
150 }
151
View as plain text