@@ -11,174 +11,70 @@ import (
1111 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212)
1313
14- var Config = config.AutoDiscoveryConfig {
15- Cluster : config.ClusterConfig {
16- Name : "test-cluster" ,
17- },
18- ServiceAutoDiscovery : config.ServiceAutoDiscoveryConfig {
19- PassiveReconcileInterval : metav1.Duration {Duration : 1 * time .Second },
20- ScanConfigs : []config.ScanConfig {
21- {
22- Name : "test-scan-0" ,
23- RepeatInterval : metav1.Duration {Duration : time .Hour },
24- Annotations : map [string ]string {},
25- Labels : map [string ]string {},
26- Parameters : []string {"-p" , "{{ .Host.Port }}" , "{{ .Service.Name }}.{{ .Service.Namespace }}.svc" },
27- ScanType : "nmap" ,
28- HookSelector : metav1.LabelSelector {
29- MatchLabels : map [string ]string {
30- "foo" : "bar" ,
31- },
32- },
33- },
34- {
35- Name : "test-scan-1" ,
36- RepeatInterval : metav1.Duration {Duration : time .Hour },
37- Annotations : map [string ]string {},
38- Labels : map [string ]string {},
39- Parameters : []string {"-p" , "{{ .Host.Port }}" , "{{ .Service.Name }}.{{ .Service.Namespace }}.svc" },
40- ScanType : "nmap" ,
41- HookSelector : metav1.LabelSelector {
42- MatchLabels : map [string ]string {
43- "foo" : "bar" ,
44- },
45- },
14+ // newServiceScanConfigMock creates a mock scan configuration specifically for service auto-discovery
15+ func newServiceScanConfigMock (name string ) config.ScanConfig {
16+ return config.ScanConfig {
17+ Name : name ,
18+ RepeatInterval : metav1.Duration {Duration : time .Hour },
19+ Annotations : map [string ]string {},
20+ Labels : map [string ]string {},
21+ Parameters : []string {"-p" , "{{ .Host.Port }}" , "{{ .Service.Name }}.{{ .Service.Namespace }}.svc" },
22+ ScanType : "nmap" ,
23+ HookSelector : metav1.LabelSelector {
24+ MatchLabels : map [string ]string {
25+ "foo" : "bar" ,
4626 },
4727 },
48- },
49- ContainerAutoDiscovery : config.ContainerAutoDiscoveryConfig {
50- PassiveReconcileInterval : metav1.Duration {Duration : 1 * time .Second },
51- ScanConfigs : []config.ScanConfig {
52- {
53- Name : "test-scan" ,
54- RepeatInterval : metav1.Duration {Duration : time .Hour },
55- Annotations : map [string ]string {"testAnnotation" : "{{ .Namespace.Name }}" },
56- Labels : map [string ]string {"testLabel" : "{{ .Namespace.Name }}" },
57- Parameters : []string {"-p" , "{{ .Namespace.Name }}" },
58- ScanType : "nmap" ,
59- HookSelector : metav1.LabelSelector {
60- MatchExpressions : []metav1.LabelSelectorRequirement {
61- {
62- Operator : metav1 .LabelSelectorOpIn ,
63- Key : "foo" ,
64- Values : []string {"bar" , "baz" },
65- },
66- {
67- Operator : metav1 .LabelSelectorOpDoesNotExist ,
68- Key : "foo" ,
69- },
70- },
28+ }
29+ }
30+
31+ // newContainerScanConfigMock creates a mock scan configuration specifically for container auto-discovery
32+ func newContainerScanConfigMock (name string ) config.ScanConfig {
33+ return config.ScanConfig {
34+ Name : name ,
35+ RepeatInterval : metav1.Duration {Duration : time .Hour },
36+ Annotations : map [string ]string {"testAnnotation" : "{{ .Namespace.Name }}" },
37+ Labels : map [string ]string {"testLabel" : "{{ .Namespace.Name }}" },
38+ Parameters : []string {"-p" , "{{ .Namespace.Name }}" },
39+ ScanType : "nmap" ,
40+ HookSelector : metav1.LabelSelector {
41+ MatchExpressions : []metav1.LabelSelectorRequirement {
42+ {
43+ Operator : metav1 .LabelSelectorOpIn ,
44+ Key : "foo" ,
45+ Values : []string {"bar" , "baz" },
7146 },
72- },
73- {
74- Name : "test-scan-two" ,
75- RepeatInterval : metav1.Duration {Duration : time .Hour },
76- Annotations : map [string ]string {"testAnnotation" : "{{ .Namespace.Name }}" },
77- Labels : map [string ]string {"testLabel" : "{{ .Namespace.Name }}" },
78- Parameters : []string {"-p" , "{{ .Namespace.Name }}" },
79- ScanType : "nmap" ,
80- HookSelector : metav1.LabelSelector {
81- MatchExpressions : []metav1.LabelSelectorRequirement {
82- {
83- Operator : metav1 .LabelSelectorOpIn ,
84- Key : "foo" ,
85- Values : []string {"bar" , "baz" },
86- },
87- {
88- Operator : metav1 .LabelSelectorOpDoesNotExist ,
89- Key : "foo" ,
90- },
91- },
47+ {
48+ Operator : metav1 .LabelSelectorOpDoesNotExist ,
49+ Key : "foo" ,
9250 },
9351 },
9452 },
95- },
96- ResourceInclusion : config.ResourceInclusionConfig {
97- Mode : config .EnabledPerResource ,
98- },
53+ }
9954}
10055
101- // broken config has two scans (per autodiscovery) defined with the same name which will trigger an error during controller setup
102- var BrokenConfig = config.AutoDiscoveryConfig {
56+ // AutoDiscoveryConfigMock holds the complete mock configuration
57+ var AutoDiscoveryConfigMock = config.AutoDiscoveryConfig {
10358 Cluster : config.ClusterConfig {
10459 Name : "test-cluster" ,
10560 },
10661 ServiceAutoDiscovery : config.ServiceAutoDiscoveryConfig {
10762 PassiveReconcileInterval : metav1.Duration {Duration : 1 * time .Second },
10863 ScanConfigs : []config.ScanConfig {
109- {
110- Name : "test-scan" ,
111- RepeatInterval : metav1.Duration {Duration : time .Hour },
112- Annotations : map [string ]string {},
113- Labels : map [string ]string {},
114- Parameters : []string {"-p" , "{{ .Host.Port }}" , "{{ .Service.Name }}.{{ .Service.Namespace }}.svc" },
115- ScanType : "nmap" ,
116- HookSelector : metav1.LabelSelector {
117- MatchLabels : map [string ]string {
118- "foo" : "bar" ,
119- },
120- },
121- },
122- {
123- Name : "test-scan" ,
124- RepeatInterval : metav1.Duration {Duration : time .Hour },
125- Annotations : map [string ]string {},
126- Labels : map [string ]string {},
127- Parameters : []string {"-p" , "{{ .Host.Port }}" , "{{ .Service.Name }}.{{ .Service.Namespace }}.svc" },
128- ScanType : "nmap" ,
129- HookSelector : metav1.LabelSelector {
130- MatchLabels : map [string ]string {
131- "foo" : "bar" ,
132- },
133- },
134- },
64+ newServiceScanConfigMock ("test-scan-0" ),
65+ newServiceScanConfigMock ("test-scan-1" ),
13566 },
13667 },
13768 ContainerAutoDiscovery : config.ContainerAutoDiscoveryConfig {
13869 PassiveReconcileInterval : metav1.Duration {Duration : 1 * time .Second },
70+ ImagePullSecretConfig : config.ImagePullSecretConfig {
71+ MapImagePullSecretsToEnvironmentVariables : true ,
72+ UsernameEnvironmentVariableName : "username" ,
73+ PasswordNameEnvironmentVariableName : "password" ,
74+ },
13975 ScanConfigs : []config.ScanConfig {
140- {
141- Name : "test-scan" ,
142- RepeatInterval : metav1.Duration {Duration : time .Hour },
143- Annotations : map [string ]string {"testAnnotation" : "{{ .Namespace.Name }}" },
144- Labels : map [string ]string {"testLabel" : "{{ .Namespace.Name }}" },
145- Parameters : []string {"-p" , "{{ .Namespace.Name }}" },
146- ScanType : "nmap" ,
147- HookSelector : metav1.LabelSelector {
148- MatchExpressions : []metav1.LabelSelectorRequirement {
149- {
150- Operator : metav1 .LabelSelectorOpIn ,
151- Key : "foo" ,
152- Values : []string {"bar" , "baz" },
153- },
154- {
155- Operator : metav1 .LabelSelectorOpDoesNotExist ,
156- Key : "foo" ,
157- },
158- },
159- },
160- },
161- {
162- Name : "test-scan" ,
163- RepeatInterval : metav1.Duration {Duration : time .Hour },
164- Annotations : map [string ]string {"testAnnotation" : "{{ .Namespace.Name }}" },
165- Labels : map [string ]string {"testLabel" : "{{ .Namespace.Name }}" },
166- Parameters : []string {"-p" , "{{ .Namespace.Name }}" },
167- ScanType : "nmap" ,
168- HookSelector : metav1.LabelSelector {
169- MatchExpressions : []metav1.LabelSelectorRequirement {
170- {
171- Operator : metav1 .LabelSelectorOpIn ,
172- Key : "foo" ,
173- Values : []string {"bar" , "baz" },
174- },
175- {
176- Operator : metav1 .LabelSelectorOpDoesNotExist ,
177- Key : "foo" ,
178- },
179- },
180- },
181- },
76+ newContainerScanConfigMock ("test-scan" ),
77+ newContainerScanConfigMock ("test-scan-two" ),
18278 },
18379 },
18480 ResourceInclusion : config.ResourceInclusionConfig {
0 commit comments