Skip to content

Commit b1b8eef

Browse files
committed
update some files
1 parent 76d5a2c commit b1b8eef

File tree

5 files changed

+89
-72
lines changed

5 files changed

+89
-72
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ replace (
7474
)
7575

7676
require (
77+
github.com/Microsoft/hcsshim v0.12.6
7778
github.com/Mirantis/cri-dockerd v0.0.0-00010101000000-000000000000
7879
github.com/blang/semver/v4 v4.0.0
7980
github.com/containerd/aufs v1.0.0
@@ -182,7 +183,6 @@ require (
182183
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab // indirect
183184
github.com/MakeNowJust/heredoc v1.0.0 // indirect
184185
github.com/Microsoft/go-winio v0.6.2 // indirect
185-
github.com/Microsoft/hcsshim v0.12.6 // indirect
186186
github.com/NYTimes/gziphandler v1.1.1 // indirect
187187
github.com/Rican7/retry v0.1.0 // indirect
188188
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e // indirect

pkg/agent/run.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
9090
return fmt.Errorf("dual-stack or IPv6 are not supported on Windows node")
9191
}
9292

93-
conntrackConfig, err := getConntrackConfig(nodeConfig)
94-
if err != nil {
95-
return errors.Wrap(err, "failed to validate kube-proxy conntrack configuration")
96-
}
97-
syssetup.Configure(enableIPv6, conntrackConfig)
9893
nodeConfig.AgentConfig.EnableIPv4 = enableIPv4
9994
nodeConfig.AgentConfig.EnableIPv6 = enableIPv6
10095

pkg/daemons/executor/embed.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"k8s.io/klog/v2"
4141
apiapp "k8s.io/kubernetes/cmd/kube-apiserver/app"
4242
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
43-
proxy "k8s.io/kubernetes/cmd/kube-proxy/app"
4443
sapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
4544
kubelet "k8s.io/kubernetes/cmd/kubelet/app"
4645

@@ -104,27 +103,6 @@ func (e *Embedded) Kubelet(ctx context.Context, args []string) error {
104103
return nil
105104
}
106105

107-
func (e *Embedded) KubeProxy(ctx context.Context, args []string) error {
108-
command := proxy.NewProxyCommand()
109-
command.SetArgs(daemonconfig.GetArgs(platformKubeProxyArgs(e.nodeConfig), args))
110-
111-
go func() {
112-
defer func() {
113-
if err := recover(); err != nil {
114-
logrus.WithField("stack", string(debug.Stack())).Fatalf("kube-proxy panic: %v", err)
115-
}
116-
}()
117-
err := command.ExecuteContext(ctx)
118-
if err != nil && !errors.Is(err, context.Canceled) {
119-
logrus.Errorf("kube-proxy exited: %v", err)
120-
os.Exit(1)
121-
}
122-
os.Exit(0)
123-
}()
124-
125-
return nil
126-
}
127-
128106
func (*Embedded) APIServerHandlers(ctx context.Context) (authenticator.Request, http.Handler, error) {
129107
startupConfig := <-apiapp.StartupConfig
130108
return startupConfig.Authenticator, startupConfig.Handler, nil

pkg/node/controller.go

Lines changed: 88 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package node
22

33
import (
4+
"bytes"
45
"context"
6+
"net"
7+
"sort"
58
"strings"
69

10+
"github.com/xiaods/k8e/pkg/nodepassword"
711
"github.com/pkg/errors"
8-
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
12+
coreclient "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1"
913
"github.com/sirupsen/logrus"
10-
"github.com/xiaods/k8e/pkg/nodepassword"
1114
core "k8s.io/api/core/v1"
15+
v1 "k8s.io/api/core/v1"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1217
)
1318

1419
func Register(ctx context.Context,
@@ -47,14 +52,22 @@ func (h *handler) onRemove(key string, node *core.Node) (*core.Node, error) {
4752

4853
func (h *handler) updateHosts(node *core.Node, removed bool) (*core.Node, error) {
4954
var (
50-
nodeName string
51-
nodeAddress string
55+
nodeName string
56+
hostName string
57+
nodeIPv4 string
58+
nodeIPv6 string
5259
)
5360
nodeName = node.Name
5461
for _, address := range node.Status.Addresses {
55-
if address.Type == "InternalIP" {
56-
nodeAddress = address.Address
57-
break
62+
switch address.Type {
63+
case v1.NodeInternalIP:
64+
if strings.Contains(address.Address, ":") {
65+
nodeIPv6 = address.Address
66+
} else {
67+
nodeIPv4 = address.Address
68+
}
69+
case v1.NodeHostName:
70+
hostName = address.Address
5871
}
5972
}
6073
if removed {
@@ -63,58 +76,101 @@ func (h *handler) updateHosts(node *core.Node, removed bool) (*core.Node, error)
6376
}
6477
}
6578
if h.modCoreDNS {
66-
if err := h.updateCoreDNSConfigMap(nodeName, nodeAddress, removed); err != nil {
79+
if err := h.updateCoreDNSConfigMap(nodeName, hostName, nodeIPv4, nodeIPv6, removed); err != nil {
6780
return nil, err
6881
}
6982
}
7083
return nil, nil
7184
}
7285

73-
func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed bool) error {
74-
if nodeAddress == "" && !removed {
75-
logrus.Errorf("No InternalIP found for node " + nodeName)
86+
func (h *handler) updateCoreDNSConfigMap(nodeName, hostName, nodeIPv4, nodeIPv6 string, removed bool) error {
87+
if removed {
88+
nodeIPv4 = ""
89+
nodeIPv6 = ""
90+
} else if nodeIPv4 == "" && nodeIPv6 == "" {
91+
logrus.Errorf("No InternalIP addresses found for node " + nodeName)
7692
return nil
7793
}
7894

79-
configMapCache, err := h.configMaps.Cache().Get("kube-system", "coredns")
80-
if err != nil || configMapCache == nil {
95+
nodeNames := nodeName
96+
if hostName != nodeName {
97+
nodeNames += " " + hostName
98+
}
99+
100+
configMap, err := h.configMaps.Get("kube-system", "coredns", metav1.GetOptions{})
101+
if err != nil || configMap == nil {
81102
logrus.Warn(errors.Wrap(err, "Unable to fetch coredns config map"))
82103
return nil
83104
}
84105

85-
configMap := configMapCache.DeepCopy()
86-
hosts := configMap.Data["NodeHosts"]
87-
hostsMap := map[string]string{}
106+
addressMap := map[string]string{}
88107

89-
for _, line := range strings.Split(hosts, "\n") {
108+
// extract current entries from hosts file, skipping any entries that are
109+
// empty, unparsable, or hold an incorrect address for the current node.
110+
for _, line := range strings.Split(configMap.Data["NodeHosts"], "\n") {
111+
line, _, _ = strings.Cut(line, "#")
90112
if line == "" {
91113
continue
92114
}
93115
fields := strings.Fields(line)
94-
if len(fields) != 2 {
116+
if len(fields) < 2 {
95117
logrus.Warnf("Unknown format for hosts line [%s]", line)
96118
continue
97119
}
98120
ip := fields[0]
99-
host := fields[1]
100-
if host == nodeName {
101-
if removed {
102-
continue
103-
}
104-
if ip == nodeAddress {
105-
return nil
121+
if fields[1] == nodeName {
122+
if strings.Contains(ip, ":") {
123+
if ip != nodeIPv6 {
124+
continue
125+
}
126+
} else {
127+
if ip != nodeIPv4 {
128+
continue
129+
}
106130
}
107131
}
108-
hostsMap[host] = ip
132+
names := strings.Join(fields[1:], " ")
133+
addressMap[ip] = names
109134
}
110135

111-
if !removed {
112-
hostsMap[nodeName] = nodeAddress
136+
// determine what names we should have for each address family
137+
var namesv6, namesv4 string
138+
if nodeIPv4 != "" {
139+
namesv4 = nodeNames
140+
}
141+
if nodeIPv6 != "" {
142+
namesv6 = nodeNames
113143
}
114144

145+
// don't need to do anything if the addresses are in sync
146+
if !removed && addressMap[nodeIPv4] == namesv4 && addressMap[nodeIPv6] == namesv6 {
147+
return nil
148+
}
149+
150+
// Something's out of sync, set the desired entries
151+
if nodeIPv4 != "" {
152+
addressMap[nodeIPv4] = namesv4
153+
}
154+
if nodeIPv6 != "" {
155+
addressMap[nodeIPv6] = namesv6
156+
}
157+
158+
// sort addresses by IP
159+
addresses := make([]string, 0, len(addressMap))
160+
for ip := range addressMap {
161+
addresses = append(addresses, ip)
162+
}
163+
sort.Slice(addresses, func(i, j int) bool {
164+
return bytes.Compare(net.ParseIP(addresses[i]), net.ParseIP(addresses[j])) < 0
165+
})
166+
115167
var newHosts string
116-
for host, ip := range hostsMap {
117-
newHosts += ip + " " + host + "\n"
168+
for _, ip := range addresses {
169+
newHosts += ip + " " + addressMap[ip] + "\n"
170+
}
171+
172+
if configMap.Data == nil {
173+
configMap.Data = map[string]string{}
118174
}
119175
configMap.Data["NodeHosts"] = newHosts
120176

@@ -128,10 +184,10 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b
128184
} else {
129185
actionType = "Updated"
130186
}
131-
logrus.Infof("%s coredns node hosts entry [%s]", actionType, nodeAddress+" "+nodeName)
187+
logrus.Infof("%s coredns NodeHosts entry for %s", actionType, nodeName)
132188
return nil
133189
}
134190

135191
func (h *handler) removeNodePassword(nodeName string) error {
136192
return nodepassword.Delete(h.secrets, nodeName)
137-
}
193+
}

pkg/util/services/services_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ func Test_UnitFilesForServices(t *testing.T) {
7070
"/var/lib/rancher/k8e/agent/client-k8e-controller.crt",
7171
"/var/lib/rancher/k8e/agent/client-k8e-controller.key",
7272
},
73-
"kube-proxy": []string{
74-
"/var/lib/rancher/k8e/server/tls/client-kube-proxy.crt",
75-
"/var/lib/rancher/k8e/server/tls/client-kube-proxy.key",
76-
"/var/lib/rancher/k8e/agent/client-kube-proxy.crt",
77-
"/var/lib/rancher/k8e/agent/client-kube-proxy.key",
78-
},
7973
"kubelet": []string{
8074
"/var/lib/rancher/k8e/server/tls/client-kubelet.key",
8175
"/var/lib/rancher/k8e/server/tls/serving-kubelet.key",
@@ -168,12 +162,6 @@ func Test_UnitFilesForServices(t *testing.T) {
168162
"/var/lib/rancher/k8e/agent/client-k8e-controller.crt",
169163
"/var/lib/rancher/k8e/agent/client-k8e-controller.key",
170164
},
171-
"kube-proxy": []string{
172-
"/var/lib/rancher/k8e/server/tls/client-kube-proxy.crt",
173-
"/var/lib/rancher/k8e/server/tls/client-kube-proxy.key",
174-
"/var/lib/rancher/k8e/agent/client-kube-proxy.crt",
175-
"/var/lib/rancher/k8e/agent/client-kube-proxy.key",
176-
},
177165
"kubelet": []string{
178166
"/var/lib/rancher/k8e/server/tls/client-kubelet.key",
179167
"/var/lib/rancher/k8e/server/tls/serving-kubelet.key",

0 commit comments

Comments
 (0)