11// Copyright 2018 Microsoft. All rights reserved.
22// MIT License
3- package npm
3+ package controllers
44
55import (
66 "fmt"
@@ -31,7 +31,7 @@ const (
3131 unSafeToCleanUpAzureNpmChain IsSafeCleanUpAzureNpmChain = false
3232)
3333
34- type networkPolicyController struct {
34+ type NetworkPolicyController struct {
3535 netPolLister netpollister.NetworkPolicyLister
3636 workqueue workqueue.RateLimitingInterface
3737 rawNpMap map [string ]* networkingv1.NetworkPolicy // Key is <nsname>/<policyname>
@@ -43,8 +43,8 @@ type networkPolicyController struct {
4343 iptMgr * iptm.IptablesManager
4444}
4545
46- func NewNetworkPolicyController (npInformer networkinginformers.NetworkPolicyInformer , ipsMgr * ipsm.IpsetManager ) * networkPolicyController {
47- netPolController := & networkPolicyController {
46+ func NewNetworkPolicyController (npInformer networkinginformers.NetworkPolicyInformer , ipsMgr * ipsm.IpsetManager ) * NetworkPolicyController {
47+ netPolController := & NetworkPolicyController {
4848 netPolLister : npInformer .Lister (),
4949 workqueue : workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), "NetworkPolicy" ),
5050 rawNpMap : make (map [string ]* networkingv1.NetworkPolicy ),
@@ -66,7 +66,7 @@ func NewNetworkPolicyController(npInformer networkinginformers.NetworkPolicyInfo
6666
6767// initializeDataPlane do all initialization tasks for data plane
6868// TODO(jungukcho) Need to refactor UninitNpmChains since it assumes it has already AZURE-NPM chains
69- func (c * networkPolicyController ) resetDataPlane () error {
69+ func (c * NetworkPolicyController ) ResetDataPlane () error {
7070 klog .Infof ("Initiailize data plane. Clean up Azure-NPM chains and start reconcile iptables" )
7171
7272 // TODO(jungukcho): will clean-up error handling codes to initialize iptables and ipset in a separate PR
@@ -85,18 +85,18 @@ func (c *networkPolicyController) resetDataPlane() error {
8585 return nil
8686}
8787
88- func (c * networkPolicyController ) runPeriodicTasks (stopCh <- chan struct {}) {
88+ func (c * NetworkPolicyController ) RunPeriodicTasks (stopCh <- chan struct {}) {
8989 // (TODO): Check any side effects
9090 c .iptMgr .ReconcileIPTables (stopCh )
9191}
9292
93- func (c * networkPolicyController ) lengthOfRawNpMap () int {
93+ func (c * NetworkPolicyController ) LengthOfRawNpMap () int {
9494 return len (c .rawNpMap )
9595}
9696
9797// getNetworkPolicyKey returns namespace/name of network policy object if it is valid network policy object and has valid namespace/name.
9898// If not, it returns error.
99- func (c * networkPolicyController ) getNetworkPolicyKey (obj interface {}) (string , error ) {
99+ func (c * NetworkPolicyController ) getNetworkPolicyKey (obj interface {}) (string , error ) {
100100 var key string
101101 _ , ok := obj .(* networkingv1.NetworkPolicy )
102102 if ! ok {
@@ -111,7 +111,7 @@ func (c *networkPolicyController) getNetworkPolicyKey(obj interface{}) (string,
111111 return key , nil
112112}
113113
114- func (c * networkPolicyController ) addNetworkPolicy (obj interface {}) {
114+ func (c * NetworkPolicyController ) addNetworkPolicy (obj interface {}) {
115115 netPolkey , err := c .getNetworkPolicyKey (obj )
116116 if err != nil {
117117 utilruntime .HandleError (err )
@@ -121,15 +121,15 @@ func (c *networkPolicyController) addNetworkPolicy(obj interface{}) {
121121 c .workqueue .Add (netPolkey )
122122}
123123
124- func (c * networkPolicyController ) updateNetworkPolicy (old , new interface {}) {
125- netPolkey , err := c .getNetworkPolicyKey (new )
124+ func (c * NetworkPolicyController ) updateNetworkPolicy (old , newnetpol interface {}) {
125+ netPolkey , err := c .getNetworkPolicyKey (newnetpol )
126126 if err != nil {
127127 utilruntime .HandleError (err )
128128 return
129129 }
130130
131131 // new network policy object is already checked validation by calling getNetworkPolicyKey function.
132- newNetPol , _ := new .(* networkingv1.NetworkPolicy )
132+ newNetPol , _ := newnetpol .(* networkingv1.NetworkPolicy )
133133 oldNetPol , ok := old .(* networkingv1.NetworkPolicy )
134134 if ok {
135135 if oldNetPol .ResourceVersion == newNetPol .ResourceVersion {
@@ -142,7 +142,7 @@ func (c *networkPolicyController) updateNetworkPolicy(old, new interface{}) {
142142 c .workqueue .Add (netPolkey )
143143}
144144
145- func (c * networkPolicyController ) deleteNetworkPolicy (obj interface {}) {
145+ func (c * NetworkPolicyController ) deleteNetworkPolicy (obj interface {}) {
146146 netPolObj , ok := obj .(* networkingv1.NetworkPolicy )
147147 // DeleteFunc gets the final state of the resource (if it is known).
148148 // Otherwise, it gets an object of type DeletedFinalStateUnknown.
@@ -173,7 +173,7 @@ func (c *networkPolicyController) deleteNetworkPolicy(obj interface{}) {
173173 c .workqueue .Add (netPolkey )
174174}
175175
176- func (c * networkPolicyController ) Run (stopCh <- chan struct {}) {
176+ func (c * NetworkPolicyController ) Run (stopCh <- chan struct {}) {
177177 defer utilruntime .HandleCrash ()
178178 defer c .workqueue .ShutDown ()
179179
@@ -185,12 +185,12 @@ func (c *networkPolicyController) Run(stopCh <-chan struct{}) {
185185 klog .Info ("Shutting down Network Policy workers" )
186186}
187187
188- func (c * networkPolicyController ) runWorker () {
188+ func (c * NetworkPolicyController ) runWorker () {
189189 for c .processNextWorkItem () {
190190 }
191191}
192192
193- func (c * networkPolicyController ) processNextWorkItem () bool {
193+ func (c * NetworkPolicyController ) processNextWorkItem () bool {
194194 obj , shutdown := c .workqueue .Get ()
195195
196196 if shutdown {
@@ -232,7 +232,7 @@ func (c *networkPolicyController) processNextWorkItem() bool {
232232}
233233
234234// syncNetPol compares the actual state with the desired, and attempts to converge the two.
235- func (c * networkPolicyController ) syncNetPol (key string ) error {
235+ func (c * NetworkPolicyController ) syncNetPol (key string ) error {
236236 // Convert the namespace/name string into a distinct namespace and name
237237 namespace , name , err := cache .SplitMetaNamespaceKey (key )
238238 if err != nil {
@@ -286,7 +286,7 @@ func (c *networkPolicyController) syncNetPol(key string) error {
286286}
287287
288288// initializeDefaultAzureNpmChain install default rules for kube-system and iptables
289- func (c * networkPolicyController ) initializeDefaultAzureNpmChain () error {
289+ func (c * NetworkPolicyController ) initializeDefaultAzureNpmChain () error {
290290 if c .isAzureNpmChainCreated {
291291 return nil
292292 }
@@ -303,7 +303,7 @@ func (c *networkPolicyController) initializeDefaultAzureNpmChain() error {
303303}
304304
305305// syncAddAndUpdateNetPol handles a new network policy or an updated network policy object triggered by add and update events
306- func (c * networkPolicyController ) syncAddAndUpdateNetPol (netPolObj * networkingv1.NetworkPolicy ) error {
306+ func (c * NetworkPolicyController ) syncAddAndUpdateNetPol (netPolObj * networkingv1.NetworkPolicy ) error {
307307 prometheusTimer := metrics .StartNewTimer ()
308308 defer metrics .RecordPolicyExecTime (prometheusTimer ) // record execution time regardless of failure
309309
@@ -395,7 +395,7 @@ func (c *networkPolicyController) syncAddAndUpdateNetPol(netPolObj *networkingv1
395395}
396396
397397// DeleteNetworkPolicy handles deleting network policy based on netPolKey.
398- func (c * networkPolicyController ) cleanUpNetworkPolicy (netPolKey string , isSafeCleanUpAzureNpmChain IsSafeCleanUpAzureNpmChain ) error {
398+ func (c * NetworkPolicyController ) cleanUpNetworkPolicy (netPolKey string , isSafeCleanUpAzureNpmChain IsSafeCleanUpAzureNpmChain ) error {
399399 cachedNetPolObj , cachedNetPolObjExists := c .rawNpMap [netPolKey ]
400400 // if there is no applied network policy with the netPolKey, do not need to clean up process.
401401 if ! cachedNetPolObjExists {
@@ -455,7 +455,7 @@ func (c *networkPolicyController) cleanUpNetworkPolicy(netPolKey string, isSafeC
455455}
456456
457457// (TODO) do not need to ipsMgr parameter
458- func (c * networkPolicyController ) createCidrsRule (direction , policyName , ns string , ipsets [][]string ) error {
458+ func (c * NetworkPolicyController ) createCidrsRule (direction , policyName , ns string , ipsets [][]string ) error {
459459 spec := []string {util .IpsetNetHashFlag , util .IpsetMaxelemName , util .IpsetMaxelemNum }
460460
461461 for i , ipCidrSet := range ipsets {
@@ -488,7 +488,7 @@ func (c *networkPolicyController) createCidrsRule(direction, policyName, ns stri
488488 return nil
489489}
490490
491- func (c * networkPolicyController ) removeCidrsRule (direction , policyName , ns string , ipsets [][]string ) error {
491+ func (c * NetworkPolicyController ) removeCidrsRule (direction , policyName , ns string , ipsets [][]string ) error {
492492 for i , ipCidrSet := range ipsets {
493493 if len (ipCidrSet ) == 0 {
494494 continue
0 commit comments