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

fix(cni): pass buffer to kuma net iptables engine to get logs out #4826

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions app/cni/pkg/cni/injector_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cni

import (
"io/ioutil"
"bufio"
"bytes"
"strconv"
"strings"

Expand Down Expand Up @@ -39,7 +40,9 @@ func convertCommaSeparatedString(list string) ([]uint16, error) {
}

func Inject(netns string, logger logr.Logger, intermediateConfig *IntermediateConfig) error {
cfg, err := mapToConfig(intermediateConfig)
var logBuffer bytes.Buffer
logWriter := bufio.NewWriter(&logBuffer)
cfg, err := mapToConfig(intermediateConfig, logWriter)
if err != nil {
return err
}
Expand All @@ -50,20 +53,23 @@ func Inject(netns string, logger logr.Logger, intermediateConfig *IntermediateCo
}
defer namespace.Close()

err = namespace.Do(func(_ ns.NetNS) error {
rules, err := kumanet_tproxy.Setup(*cfg)
if err != nil {
return namespace.Do(func(_ ns.NetNS) error {
if _, err := kumanet_tproxy.Setup(*cfg); err != nil {
return err
}

if err := logWriter.Flush(); err != nil {
return err
}
logger.V(1).Info("generated iptables rules", "rules", rules)

logger.Info("iptables rules applied")
logger.V(1).Info("generated iptables rules", "iptablesStdout", logBuffer.String())

return nil
})

return err
}

func mapToConfig(intermediateConfig *IntermediateConfig) (*kumanet_config.Config, error) {
func mapToConfig(intermediateConfig *IntermediateConfig, logWriter *bufio.Writer) (*kumanet_config.Config, error) {
port, err := convertToUint16("inbound port", intermediateConfig.targetPort)
if err != nil {
return nil, err
Expand All @@ -73,7 +79,7 @@ func mapToConfig(intermediateConfig *IntermediateConfig) (*kumanet_config.Config
return nil, err
}
cfg := kumanet_config.Config{
RuntimeStdout: ioutil.Discard,
RuntimeStdout: logWriter,
Owner: kumanet_config.Owner{
UID: intermediateConfig.noRedirectUID,
},
Expand Down