@@ -88,6 +88,12 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
8888 // In case of cluster provisioned on AWS disable source-destination check
8989 nrc .disableSourceDestinationCheck ()
9090
91+ // enable IP forwarding for the packets coming in/out from ther pods
92+ err = nrc .enableForwarding ()
93+ if err != nil {
94+ glog .Errorf ("Failed to enable IP forwarding of traffic from pods: %s" , err .Error ())
95+ }
96+
9197 t := time .NewTicker (nrc .syncPeriod )
9298 defer t .Stop ()
9399 defer wg .Done ()
@@ -672,6 +678,55 @@ func (nrc *NetworkRoutingController) syncPeers() {
672678 }
673679}
674680
681+ // ensure there is rule in filter table and FORWARD chain to permit in/out traffic from pods
682+ // this rules will be appended so that any iptable rules for network policies will take
683+ // precedence
684+ func (nrc * NetworkRoutingController ) enableForwarding () error {
685+
686+ iptablesCmdHandler , err := iptables .New ()
687+
688+ comment := "allow outbound traffic from pods"
689+ args := []string {"-m" , "comment" , "--comment" , comment , "-i" , "kube-bridge" , "-j" , "ACCEPT" }
690+ exists , err := iptablesCmdHandler .Exists ("filter" , "FORWARD" , args ... )
691+ if err != nil {
692+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
693+ }
694+ if ! exists {
695+ err := iptablesCmdHandler .AppendUnique ("filter" , "FORWARD" , args ... )
696+ if err != nil {
697+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
698+ }
699+ }
700+
701+ comment = "allow inbound traffic to pods"
702+ args = []string {"-m" , "comment" , "--comment" , comment , "-o" , "kube-bridge" , "-j" , "ACCEPT" }
703+ exists , err = iptablesCmdHandler .Exists ("filter" , "FORWARD" , args ... )
704+ if err != nil {
705+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
706+ }
707+ if ! exists {
708+ err = iptablesCmdHandler .AppendUnique ("filter" , "FORWARD" , args ... )
709+ if err != nil {
710+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
711+ }
712+ }
713+
714+ comment = "allow outbound node port traffic on node interface with which node ip is associated"
715+ args = []string {"-m" , "comment" , "--comment" , comment , "-o" , nrc .nodeInterface , "-j" , "ACCEPT" }
716+ exists , err = iptablesCmdHandler .Exists ("filter" , "FORWARD" , args ... )
717+ if err != nil {
718+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
719+ }
720+ if ! exists {
721+ err = iptablesCmdHandler .AppendUnique ("filter" , "FORWARD" , args ... )
722+ if err != nil {
723+ return fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
724+ }
725+ }
726+
727+ return nil
728+ }
729+
675730// Handle updates from Node watcher. Node watcher calls this method whenever there is
676731// new node is added or old node is deleted. So peer up with new node and drop peering
677732// from old node
@@ -722,7 +777,8 @@ func (nrc *NetworkRoutingController) startBgpServer() error {
722777 } else {
723778 nodeasn , ok := node .ObjectMeta .Annotations ["net.kuberouter.nodeasn" ]
724779 if ! ok {
725- return errors .New ("Could not find ASN number for the node. Node need to be annotated with ASN number details to start BGP server." )
780+ return errors .New ("Could not find ASN number for the node. Node need to be annotated with ASN number " +
781+ "details to start BGP server." )
726782 } else {
727783 glog .Infof ("Found ASN for the node to be %s from the node annotations" , nodeasn )
728784 asnNo , err := strconv .ParseUint (nodeasn , 0 , 32 )
@@ -838,7 +894,8 @@ func getNodeSubnet(nodeIp net.IP) (net.IPNet, string, error) {
838894 return net.IPNet {}, "" , errors .New ("Failed to find interface with specified node ip" )
839895}
840896
841- func NewNetworkRoutingController (clientset * kubernetes.Clientset , kubeRouterConfig * options.KubeRouterConfig ) (* NetworkRoutingController , error ) {
897+ func NewNetworkRoutingController (clientset * kubernetes.Clientset ,
898+ kubeRouterConfig * options.KubeRouterConfig ) (* NetworkRoutingController , error ) {
842899 // TODO: Remove lookup, ipset.New already does this.
843900 _ , err := exec .LookPath ("ipset" )
844901 if err != nil {
0 commit comments