-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_test.go
114 lines (97 loc) · 3.6 KB
/
controller_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// package main
// import (
// "context"
// "testing"
// "time"
// securityv1 "github.com/kubearmor/KubeArmor/pkg/KubeArmorPolicy/api/security.kubearmor.com/v1"
// karmorfake "github.com/kubearmor/KubeArmor/pkg/KubeArmorPolicy/client/clientset/versioned/fake"
// v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/runtime"
// "k8s.io/client-go/informers"
// kubeinformers "k8s.io/client-go/informers"
// k8sfake "k8s.io/client-go/kubernetes/fake"
// core "k8s.io/client-go/testing"
// "k8s.io/client-go/tools/record"
// "k8s.io/kubernetes/pkg/apis/apps"
// )
// var (
// alwaysReady = func() bool { return true }
// noResyncPeriodFunc = func() time.Duration { return 0 }
// )
// type fixture struct {
// t *testing.T
// karmorclient *karmorfake.Clientset
// kubeclient *k8sfake.Clientset
// // Objects to put in the store.
// karmorLister []*securityv1.KubeArmorPolicy
// deploymentLister []*apps.Deployment
// // Actions expected to happen on the client.
// kubeactions []core.Action
// actions []core.Action
// // Objects from here preloaded into NewSimpleFake.
// kubeobjects []runtime.Object
// objects []runtime.Object
// }
// func newFixture(t *testing.T) *fixture {
// f := &fixture{}
// f.t = t
// f.objects = []runtime.Object{}
// f.kubeobjects = []runtime.Object{}
// return f
// }
// func newKarmorPolicy(matchLabels map[string]string, secretPaths []string, secretDirPaths []string, namespace string, policyName string) *securityv1.KubeArmorPolicy {
// matchDirectories := []securityv1.FileDirectoryType{}
// matchPaths := []securityv1.FilePathType{}
// for _, secretDirPath := range secretDirPaths {
// matchDirectories = append(matchDirectories, securityv1.FileDirectoryType{
// Directory: securityv1.MatchDirectoryType(secretDirPath),
// Recursive: true,
// })
// }
// for _, secretPath := range secretPaths {
// matchPaths = append(matchPaths, securityv1.FilePathType{
// Path: securityv1.MatchPathType(secretPath),
// })
// }
// return &securityv1.KubeArmorPolicy{
// ObjectMeta: v1.ObjectMeta{
// Name: policyName,
// Namespace: namespace,
// },
// Spec: securityv1.KubeArmorPolicySpec{
// Selector: securityv1.SelectorType{
// MatchLabels: matchLabels,
// },
// File: securityv1.FileType{
// MatchPaths: matchPaths,
// MatchDirectories: matchDirectories,
// },
// Action: securityv1.ActionType("Block"),
// Capabilities: securityv1.CapabilitiesType{
// MatchCapabilities: []securityv1.MatchCapabilitiesType{},
// },
// Network: securityv1.NetworkType{
// MatchProtocols: []securityv1.MatchNetworkProtocolType{},
// },
// },
// }
// }
// func (f *fixture) newController(ctx context.Context) (*Controller, informers.SharedInformerFactory, kubeinformers.SharedInformerFactory) {
// f.karmorclient = karmorfake.NewSimpleClientset(f.objects...)
// f.kubeclient = k8sfake.NewSimpleClientset(f.kubeobjects...)
// i := informers.NewSharedInformerFactory(f.karmorclient, noResyncPeriodFunc())
// k8sI := kubeinformers.NewSharedInformerFactory(f.kubeclient, noResyncPeriodFunc())
// c := NewController(ctx, f.kubeclient, f.client,
// k8sI.Apps().V1().Deployments(), i.Samplecontroller().V1alpha1().Foos())
// c.foosSynced = alwaysReady
// c.deploymentsSynced = alwaysReady
// c.recorder = &record.FakeRecorder{}
// for _, f := range f.fooLister {
// i.Samplecontroller().V1alpha1().Foos().Informer().GetIndexer().Add(f)
// }
// for _, d := range f.deploymentLister {
// k8sI.Apps().V1().Deployments().Informer().GetIndexer().Add(d)
// }
// return c, i, k8sI
// }
package main