2022-01-20 03:41:55 +03:00
|
|
|
// Copyright 2018 Microsoft. All rights reserved.
|
|
|
|
// MIT License
|
2021-09-18 02:19:51 +03:00
|
|
|
package npm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
|
2021-10-20 23:03:12 +03:00
|
|
|
npmconfig "github.com/Azure/azure-container-networking/npm/config"
|
|
|
|
dpmocks "github.com/Azure/azure-container-networking/npm/pkg/dataplane/mocks"
|
2021-09-18 02:19:51 +03:00
|
|
|
k8sversion "k8s.io/apimachinery/pkg/version"
|
|
|
|
kubeinformers "k8s.io/client-go/informers"
|
|
|
|
k8sfake "k8s.io/client-go/kubernetes/fake"
|
|
|
|
fakeexec "k8s.io/utils/exec/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CacheEncoder is used only for unit tests to test encoding and decoding Cache.
|
|
|
|
func CacheEncoder(nodeName string) json.Marshaler {
|
|
|
|
noResyncPeriodFunc := func() time.Duration { return 0 }
|
|
|
|
kubeclient := k8sfake.NewSimpleClientset()
|
|
|
|
kubeInformer := kubeinformers.NewSharedInformerFactory(kubeclient, noResyncPeriodFunc())
|
|
|
|
fakeK8sVersion := &k8sversion.Info{
|
|
|
|
GitVersion: "v1.20.2",
|
|
|
|
}
|
|
|
|
exec := &fakeexec.FakeExec{}
|
|
|
|
npmVersion := "npm-ut-test"
|
|
|
|
|
2022-02-17 02:37:40 +03:00
|
|
|
cfg := npmconfig.DefaultConfig
|
|
|
|
cfg.Toggles.EnableHTTPDebugAPI = true
|
|
|
|
cfg.Toggles.EnableV2NPM = false
|
|
|
|
// TODO test v2 NPM debug API when it's implemented
|
|
|
|
npMgr := NewNetworkPolicyManager(cfg, kubeInformer, &dpmocks.MockGenericDataplane{}, exec, npmVersion, fakeK8sVersion)
|
2021-09-18 02:19:51 +03:00
|
|
|
npMgr.NodeName = nodeName
|
|
|
|
return npMgr
|
|
|
|
}
|