mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
kube-proxy: make iptables buffer-writing cleaner
This commit is contained in:
@@ -468,23 +468,35 @@ func GetClusterIPByFamily(ipFamily v1.IPFamily, service *v1.Service) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// WriteLine join all words with spaces, terminate with newline and write to buff.
|
||||
func WriteLine(buf *bytes.Buffer, words ...string) {
|
||||
type LineBuffer struct {
|
||||
b bytes.Buffer
|
||||
}
|
||||
|
||||
// Write joins all words with spaces, terminates with newline and writes to buf.
|
||||
func (buf *LineBuffer) Write(words ...string) {
|
||||
// We avoid strings.Join for performance reasons.
|
||||
for i := range words {
|
||||
buf.WriteString(words[i])
|
||||
buf.b.WriteString(words[i])
|
||||
if i < len(words)-1 {
|
||||
buf.WriteByte(' ')
|
||||
buf.b.WriteByte(' ')
|
||||
} else {
|
||||
buf.WriteByte('\n')
|
||||
buf.b.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WriteBytesLine write bytes to buffer, terminate with newline
|
||||
func WriteBytesLine(buf *bytes.Buffer, bytes []byte) {
|
||||
buf.Write(bytes)
|
||||
buf.WriteByte('\n')
|
||||
// WriteBytes writes bytes to buffer, and terminates with newline.
|
||||
func (buf *LineBuffer) WriteBytes(bytes []byte) {
|
||||
buf.b.Write(bytes)
|
||||
buf.b.WriteByte('\n')
|
||||
}
|
||||
|
||||
func (buf *LineBuffer) Reset() {
|
||||
buf.b.Reset()
|
||||
}
|
||||
|
||||
func (buf *LineBuffer) Bytes() []byte {
|
||||
return buf.b.Bytes()
|
||||
}
|
||||
|
||||
// RevertPorts is closing ports in replacementPortsMap but not in originalPortsMap. In other words, it only
|
||||
|
||||
Reference in New Issue
Block a user