Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory allocations in kube proxy #46033

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 12 additions & 21 deletions pkg/kubelet/network/hostport/fake_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,36 +228,27 @@ func saveChain(chain *fakeChain, data *bytes.Buffer) {
}

func (f *fakeIPTables) Save(tableName utiliptables.Table) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need plain Save() any more?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still using it in few places in kubelet. Though I'm happy to send a PR migrating it to SaveInto (should be pretty simple). But I would prefer to do it in a separate one. Will send one on Monday.

data := bytes.NewBuffer(nil)
err := f.SaveInto(tableName, data)
return data.Bytes(), err
}

func (f *fakeIPTables) SaveInto(tableName utiliptables.Table, buffer *bytes.Buffer) error {
table, err := f.getTable(tableName)
if err != nil {
return nil, err
return err
}

data := bytes.NewBuffer(nil)
data.WriteString(fmt.Sprintf("*%s\n", table.name))
buffer.WriteString(fmt.Sprintf("*%s\n", table.name))

rules := bytes.NewBuffer(nil)
for _, chain := range table.chains {
data.WriteString(fmt.Sprintf(":%s - [0:0]\n", string(chain.name)))
buffer.WriteString(fmt.Sprintf(":%s - [0:0]\n", string(chain.name)))
saveChain(chain, rules)
}
data.Write(rules.Bytes())
data.WriteString("COMMIT\n")
return data.Bytes(), nil
}

func (f *fakeIPTables) SaveAll() ([]byte, error) {
data := bytes.NewBuffer(nil)
for _, table := range f.tables {
tableData, err := f.Save(table.name)
if err != nil {
return nil, err
}
if _, err = data.Write(tableData); err != nil {
return nil, err
}
}
return data.Bytes(), nil
buffer.Write(rules.Bytes())
buffer.WriteString("COMMIT\n")
return nil
}

func (f *fakeIPTables) restore(restoreTableName utiliptables.Table, data []byte, flush utiliptables.FlushFlag) error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubelet/prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func (pb *prober) newExecInContainer(container v1.Container, containerID kubecon
}}
}

func (eic execInContainer) Run() error {
return fmt.Errorf("unimplemented")
}

func (eic execInContainer) CombinedOutput() ([]byte, error) {
return eic.run()
}
Expand All @@ -257,6 +261,10 @@ func (eic execInContainer) SetStdout(out io.Writer) {
//unimplemented
}

func (eic execInContainer) SetStderr(out io.Writer) {
//unimplemented
}

func (eic execInContainer) Stop() {
//unimplemented
}
6 changes: 6 additions & 0 deletions pkg/probe/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type FakeCmd struct {
err error
}

func (f *FakeCmd) Run() error {
return nil
}

func (f *FakeCmd) CombinedOutput() ([]byte, error) {
return f.out, f.err
}
Expand All @@ -44,6 +48,8 @@ func (f *FakeCmd) SetStdin(in io.Reader) {}

func (f *FakeCmd) SetStdout(out io.Writer) {}

func (f *FakeCmd) SetStderr(out io.Writer) {}

func (f *FakeCmd) Stop() {}

type fakeExitError struct {
Expand Down