Skip to content

Commit d816931

Browse files
authored
[NPM] support network policy controller and its unit tests (#849)
* first version of network policy controller and its unit tests * update reconcile and deleteNetworkPolicy function to correctly install and uninstall default Azure NPM chain. * To explicitly manage default Azure NPM chain in deleteNetworkPolicy function * correct comments and delete unused variable * fix missed returing errors in codes * Correct to check DeletionTimestamp and DeletionGracePeriodSeconds variables * removed placeholder functions in network policy controoler and added more test cases (e.g., update and adding multiple network policies) * - applied comments (use explict names, locating lock in a better place) * add two methods to save and restore iptables in unit test * comment out unused function * early filter in updateNetworkPolicy function if they are the same network policies. Update unit tests to test more network policies events * - start using klog package instead of log package * remove unneeded defer for lock * Locate of adding and deleting network policy object from our network policy cache in a right place. Correct prometheus metric code. * use cached network policy key instead of network policy object as method parameter in cleanUpNetworkPolicy * remove redundant check * Remove ns- prefix as key in RawNpMap. Update UT to check prometheus metrics. Applied better naming and removed redundancy codes. * minor update for varialbe names * remove dependency between UT by re-initializing metrics. Correct message.
1 parent d929d1a commit d816931

File tree

8 files changed

+894
-733
lines changed

8 files changed

+894
-733
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ require (
3939
k8s.io/api v0.18.2
4040
k8s.io/apimachinery v0.18.2
4141
k8s.io/client-go v0.18.2
42+
k8s.io/klog v1.0.0
4243
sigs.k8s.io/controller-runtime v0.6.0
4344
software.sslmate.com/src/go-pkcs12 v0.0.0-20201102150903-66718f75db0e // indirect
4445
)

npm/metrics/prometheus_metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ var nodeLevelRegistry = prometheus.NewRegistry()
6161
var clusterLevelRegistry = prometheus.NewRegistry()
6262
var haveInitialized = false
6363

64+
func ReInitializeAllMetrics() {
65+
haveInitialized = false
66+
InitializeAll()
67+
}
68+
6469
// InitializeAll creates all the Prometheus Metrics. The metrics will be nil before this method is called.
6570
func InitializeAll() {
6671
if !haveInitialized {

0 commit comments

Comments
 (0)