@@ -36,7 +36,7 @@ import (
3636// by one or more network policy chains, till there is a match which will accept the packet, or gets
3737// dropped by the rule in the pod chain, if there is no match.
3838
39- // strcut to hold information required by NetworkPolicyController
39+ // NetworkPolicyController strcut to hold information required by NetworkPolicyController
4040type NetworkPolicyController struct {
4141 nodeIP net.IP
4242 nodeHostName string
@@ -81,7 +81,7 @@ type protocolAndPort struct {
8181 port string
8282}
8383
84- // Run: runs forver till we recive notification on stopCh
84+ // Run runs forver till we recive notification on stopCh
8585func (npc * NetworkPolicyController ) Run (stopCh <- chan struct {}, wg * sync.WaitGroup ) {
8686 t := time .NewTicker (npc .syncPeriod )
8787 defer t .Stop ()
@@ -117,7 +117,7 @@ func (npc *NetworkPolicyController) Run(stopCh <-chan struct{}, wg *sync.WaitGro
117117 }
118118}
119119
120- // OnPodUpdate: handles updates to pods from the Kubernetes api server
120+ // OnPodUpdate handles updates to pods from the Kubernetes api server
121121func (npc * NetworkPolicyController ) OnPodUpdate (podUpdate * watchers.PodUpdate ) {
122122 glog .Infof ("Received pod update namspace:%s pod name:%s" , podUpdate .Pod .Namespace , podUpdate .Pod .Name )
123123 if watchers .PodWatcher .HasSynced () && watchers .NetworkPolicyWatcher .HasSynced () {
@@ -130,7 +130,7 @@ func (npc *NetworkPolicyController) OnPodUpdate(podUpdate *watchers.PodUpdate) {
130130 }
131131}
132132
133- // OnNetworkPolicyUpdate: handles updates to network policy from the kubernetes api server
133+ // OnNetworkPolicyUpdate handles updates to network policy from the kubernetes api server
134134func (npc * NetworkPolicyController ) OnNetworkPolicyUpdate (networkPolicyUpdate * watchers.NetworkPolicyUpdate ) {
135135 if watchers .PodWatcher .HasSynced () && watchers .NetworkPolicyWatcher .HasSynced () {
136136 err := npc .Sync ()
@@ -142,7 +142,7 @@ func (npc *NetworkPolicyController) OnNetworkPolicyUpdate(networkPolicyUpdate *w
142142 }
143143}
144144
145- // OnNamespaceUpdate: handles updates to namespace from kubernetes api server
145+ // OnNamespaceUpdate handles updates to namespace from kubernetes api server
146146func (npc * NetworkPolicyController ) OnNamespaceUpdate (namespaceUpdate * watchers.NamespaceUpdate ) {
147147
148148 // namespace (and annotations on it) has no significance in GA ver of network policy
@@ -598,7 +598,7 @@ func (npc *NetworkPolicyController) getFirewallEnabledPods(nodeIp string) (*map[
598598 }
599599 if npc .v1NetworkPolicy {
600600 podNeedsFirewall := false
601- for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
601+ for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
602602 policy , _ := policyObj .(* networking.NetworkPolicy )
603603
604604 // we are only interested in the network policies in same namespace that of pod
@@ -652,7 +652,7 @@ func buildNetworkPoliciesInfo() (*[]networkPolicyInfo, error) {
652652
653653 NetworkPolicies := make ([]networkPolicyInfo , 0 )
654654
655- for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
655+ for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
656656
657657 policy , ok := policyObj .(* networking.NetworkPolicy )
658658 if ! ok {
@@ -747,7 +747,7 @@ func buildBetaNetworkPoliciesInfo() (*[]networkPolicyInfo, error) {
747747
748748 NetworkPolicies := make ([]networkPolicyInfo , 0 )
749749
750- for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
750+ for _ , policyObj := range watchers .NetworkPolicyWatcher .List () {
751751
752752 policy , _ := policyObj .(* apiextensions.NetworkPolicy )
753753 newPolicy := networkPolicyInfo {
@@ -806,13 +806,11 @@ func getNameSpaceDefaultPolicy(namespace string) (string, error) {
806806 err := json .Unmarshal ([]byte (networkPolicyAnnotation ), & annot )
807807 if err == nil {
808808 return annot ["ingress" ]["isolation" ], nil
809- } else {
810- glog .Errorf ("Skipping invalid network-policy for namespace \" %s\" : %s" , namespace , err )
811- return "DefaultAllow" , errors .New ("Invalid NetworkPolicy." )
812809 }
813- } else {
814- return "DefaultAllow" , nil
810+ glog . Errorf ( "Skipping invalid network-policy for namespace \" %s \" : %s" , namespace , err )
811+ return "DefaultAllow" , errors . New ( "Invalid NetworkPolicy." )
815812 }
813+ return "DefaultAllow" , nil
816814 }
817815 }
818816 return "" , errors .New ("Failed to get the default ingress policy for the namespace: " + namespace )
@@ -857,7 +855,7 @@ func getNodeIP(node *apiv1.Node) (net.IP, error) {
857855 return nil , errors .New ("host IP unknown" )
858856}
859857
860- // Cleanup: cleanup configurations done
858+ // Cleanup cleanup configurations done
861859func (npc * NetworkPolicyController ) Cleanup () {
862860
863861 glog .Infof ("Cleaning up iptables configuration permanently done by kube-router" )
@@ -941,6 +939,7 @@ func (npc *NetworkPolicyController) Cleanup() {
941939 glog .Infof ("Successfully cleaned the iptables configuration done by kube-router" )
942940}
943941
942+ // NewNetworkPolicyController returns new NetworkPolicyController object
944943func NewNetworkPolicyController (clientset * kubernetes.Clientset , config * options.KubeRouterConfig ) (* NetworkPolicyController , error ) {
945944
946945 npc := NetworkPolicyController {}
0 commit comments