1
1
package nginx
2
2
3
3
import (
4
+ "log/slog"
4
5
"net/http"
5
6
"os"
6
7
"path"
7
8
8
- "github.com/golang/glog"
9
+ nl "github.com/nginxinc/kubernetes-ingress/internal/logger"
10
+ nic_glog "github.com/nginxinc/kubernetes-ingress/internal/logger/glog"
11
+ "github.com/nginxinc/kubernetes-ingress/internal/logger/levels"
9
12
"github.com/nginxinc/nginx-plus-go-client/client"
10
13
)
11
14
@@ -14,6 +17,7 @@ type FakeManager struct {
14
17
confdPath string
15
18
secretsPath string
16
19
dhparamFilename string
20
+ logger * slog.Logger
17
21
}
18
22
19
23
// NewFakeManager creates a FakeManager.
@@ -22,71 +26,72 @@ func NewFakeManager(confPath string) *FakeManager {
22
26
confdPath : path .Join (confPath , "conf.d" ),
23
27
secretsPath : path .Join (confPath , "secrets" ),
24
28
dhparamFilename : path .Join (confPath , "secrets" , "dhparam.pem" ),
29
+ logger : slog .New (nic_glog .New (os .Stdout , & nic_glog.Options {Level : levels .LevelInfo })),
25
30
}
26
31
}
27
32
28
33
// CreateMainConfig provides a fake implementation of CreateMainConfig.
29
- func (* FakeManager ) CreateMainConfig (content []byte ) bool {
30
- glog . V ( 3 ). Info ( "Writing main config" )
31
- glog . V ( 3 ). Info ( string (content ))
34
+ func (fm * FakeManager ) CreateMainConfig (content []byte ) bool {
35
+ nl . Debug ( fm . logger , "Writing main config" )
36
+ nl . Debug ( fm . logger , string (content ))
32
37
return true
33
38
}
34
39
35
40
// CreateConfig provides a fake implementation of CreateConfig.
36
- func (* FakeManager ) CreateConfig (name string , content []byte ) bool {
37
- glog . V ( 3 ). Infof ( "Writing config %v" , name )
38
- glog . V ( 3 ). Info ( string (content ))
41
+ func (fm * FakeManager ) CreateConfig (name string , content []byte ) bool {
42
+ nl . Debugf ( fm . logger , "Writing config %v" , name )
43
+ nl . Debug ( fm . logger , string (content ))
39
44
return true
40
45
}
41
46
42
47
// CreateAppProtectResourceFile provides a fake implementation of CreateAppProtectResourceFile
43
- func (* FakeManager ) CreateAppProtectResourceFile (name string , content []byte ) {
44
- glog . V ( 3 ). Infof ( "Writing Ap Resource File %v" , name )
45
- glog . V ( 3 ). Info ( string (content ))
48
+ func (fm * FakeManager ) CreateAppProtectResourceFile (name string , content []byte ) {
49
+ nl . Debugf ( fm . logger , "Writing Ap Resource File %v" , name )
50
+ nl . Debug ( fm . logger , string (content ))
46
51
}
47
52
48
53
// DeleteAppProtectResourceFile provides a fake implementation of DeleteAppProtectResourceFile
49
- func (* FakeManager ) DeleteAppProtectResourceFile (name string ) {
50
- glog . V ( 3 ). Infof ( "Deleting Ap Resource File %v" , name )
54
+ func (fm * FakeManager ) DeleteAppProtectResourceFile (name string ) {
55
+ nl . Debugf ( fm . logger , "Deleting Ap Resource File %v" , name )
51
56
}
52
57
53
58
// ClearAppProtectFolder provides a fake implementation of ClearAppProtectFolder
54
- func (* FakeManager ) ClearAppProtectFolder (name string ) {
55
- glog . V ( 3 ). Infof ( "Deleting Ap Resource folder %v" , name )
59
+ func (fm * FakeManager ) ClearAppProtectFolder (name string ) {
60
+ nl . Debugf ( fm . logger , "Deleting Ap Resource folder %v" , name )
56
61
}
57
62
58
63
// DeleteConfig provides a fake implementation of DeleteConfig.
59
- func (* FakeManager ) DeleteConfig (name string ) {
60
- glog . V ( 3 ). Infof ( "Deleting config %v" , name )
64
+ func (fm * FakeManager ) DeleteConfig (name string ) {
65
+ nl . Debugf ( fm . logger , "Deleting config %v" , name )
61
66
}
62
67
63
68
// CreateStreamConfig provides a fake implementation of CreateStreamConfig.
64
- func (* FakeManager ) CreateStreamConfig (name string , content []byte ) bool {
65
- glog . V ( 3 ). Infof ( "Writing stream config %v" , name )
66
- glog . V ( 3 ). Info ( string (content ))
69
+ func (fm * FakeManager ) CreateStreamConfig (name string , content []byte ) bool {
70
+ nl . Debugf ( fm . logger , "Writing stream config %v" , name )
71
+ nl . Debug ( fm . logger , string (content ))
67
72
return true
68
73
}
69
74
70
75
// DeleteStreamConfig provides a fake implementation of DeleteStreamConfig.
71
- func (* FakeManager ) DeleteStreamConfig (name string ) {
72
- glog . V ( 3 ). Infof ( "Deleting stream config %v" , name )
76
+ func (fm * FakeManager ) DeleteStreamConfig (name string ) {
77
+ nl . Debugf ( fm . logger , "Deleting stream config %v" , name )
73
78
}
74
79
75
80
// CreateTLSPassthroughHostsConfig provides a fake implementation of CreateTLSPassthroughHostsConfig.
76
- func (* FakeManager ) CreateTLSPassthroughHostsConfig (_ []byte ) bool {
77
- glog . V ( 3 ). Infof ( "Writing TLS Passthrough Hosts config file" )
81
+ func (fm * FakeManager ) CreateTLSPassthroughHostsConfig (_ []byte ) bool {
82
+ nl . Debugf ( fm . logger , "Writing TLS Passthrough Hosts config file" )
78
83
return false
79
84
}
80
85
81
86
// CreateSecret provides a fake implementation of CreateSecret.
82
87
func (fm * FakeManager ) CreateSecret (name string , _ []byte , _ os.FileMode ) string {
83
- glog . V ( 3 ). Infof ( "Writing secret %v" , name )
88
+ nl . Debugf ( fm . logger , "Writing secret %v" , name )
84
89
return fm .GetFilenameForSecret (name )
85
90
}
86
91
87
92
// DeleteSecret provides a fake implementation of DeleteSecret.
88
- func (* FakeManager ) DeleteSecret (name string ) {
89
- glog . V ( 3 ). Infof ( "Deleting secret %v" , name )
93
+ func (fm * FakeManager ) DeleteSecret (name string ) {
94
+ nl . Debugf ( fm . logger , "Deleting secret %v" , name )
90
95
}
91
96
92
97
// GetFilenameForSecret provides a fake implementation of GetFilenameForSecret.
@@ -96,56 +101,56 @@ func (fm *FakeManager) GetFilenameForSecret(name string) string {
96
101
97
102
// CreateDHParam provides a fake implementation of CreateDHParam.
98
103
func (fm * FakeManager ) CreateDHParam (_ string ) (string , error ) {
99
- glog . V ( 3 ). Infof ( "Writing dhparam file" )
104
+ nl . Debugf ( fm . logger , "Writing dhparam file" )
100
105
return fm .dhparamFilename , nil
101
106
}
102
107
103
108
// Version provides a fake implementation of Version.
104
- func (* FakeManager ) Version () Version {
105
- glog . V ( 3 ). Info ( "Printing nginx version" )
109
+ func (fm * FakeManager ) Version () Version {
110
+ nl . Debug ( fm . logger , "Printing nginx version" )
106
111
return NewVersion ("nginx version: nginx/1.25.3 (nginx-plus-r31)" )
107
112
}
108
113
109
114
// Start provides a fake implementation of Start.
110
- func (* FakeManager ) Start (_ chan error ) {
111
- glog . V ( 3 ). Info ( "Starting nginx" )
115
+ func (fm * FakeManager ) Start (_ chan error ) {
116
+ nl . Debug ( fm . logger , "Starting nginx" )
112
117
}
113
118
114
119
// Reload provides a fake implementation of Reload.
115
- func (* FakeManager ) Reload (_ bool ) error {
116
- glog . V ( 3 ). Infof ( "Reloading nginx" )
120
+ func (fm * FakeManager ) Reload (_ bool ) error {
121
+ nl . Debugf ( fm . logger , "Reloading nginx" )
117
122
return nil
118
123
}
119
124
120
125
// Quit provides a fake implementation of Quit.
121
- func (* FakeManager ) Quit () {
122
- glog . V ( 3 ). Info ( "Quitting nginx" )
126
+ func (fm * FakeManager ) Quit () {
127
+ nl . Debug ( fm . logger , "Quitting nginx" )
123
128
}
124
129
125
130
// UpdateConfigVersionFile provides a fake implementation of UpdateConfigVersionFile.
126
- func (* FakeManager ) UpdateConfigVersionFile (_ bool ) {
127
- glog . V ( 3 ). Infof ( "Writing config version" )
131
+ func (fm * FakeManager ) UpdateConfigVersionFile (_ bool ) {
132
+ nl . Debugf ( fm . logger , "Writing config version" )
128
133
}
129
134
130
135
// SetPlusClients provides a fake implementation of SetPlusClients.
131
136
func (* FakeManager ) SetPlusClients (_ * client.NginxClient , _ * http.Client ) {
132
137
}
133
138
134
139
// UpdateServersInPlus provides a fake implementation of UpdateServersInPlus.
135
- func (* FakeManager ) UpdateServersInPlus (upstream string , servers []string , _ ServerConfig ) error {
136
- glog . V ( 3 ). Infof ( "Updating servers of %v: %v" , upstream , servers )
140
+ func (fm * FakeManager ) UpdateServersInPlus (upstream string , servers []string , _ ServerConfig ) error {
141
+ nl . Debugf ( fm . logger , "Updating servers of %v: %v" , upstream , servers )
137
142
return nil
138
143
}
139
144
140
145
// UpdateStreamServersInPlus provides a fake implementation of UpdateStreamServersInPlus.
141
- func (* FakeManager ) UpdateStreamServersInPlus (upstream string , servers []string ) error {
142
- glog . V ( 3 ). Infof ( "Updating stream servers of %v: %v" , upstream , servers )
146
+ func (fm * FakeManager ) UpdateStreamServersInPlus (upstream string , servers []string ) error {
147
+ nl . Debugf ( fm . logger , "Updating stream servers of %v: %v" , upstream , servers )
143
148
return nil
144
149
}
145
150
146
151
// CreateOpenTracingTracerConfig creates a fake implementation of CreateOpenTracingTracerConfig.
147
- func (* FakeManager ) CreateOpenTracingTracerConfig (_ string ) error {
148
- glog . V ( 3 ). Infof ( "Writing OpenTracing tracer config file" )
152
+ func (fm * FakeManager ) CreateOpenTracingTracerConfig (_ string ) error {
153
+ nl . Debugf ( fm . logger , "Writing OpenTracing tracer config file" )
149
154
150
155
return nil
151
156
}
@@ -155,37 +160,37 @@ func (*FakeManager) SetOpenTracing(_ bool) {
155
160
}
156
161
157
162
// AppProtectPluginStart is a fake implementation AppProtectPluginStart
158
- func (* FakeManager ) AppProtectPluginStart (_ chan error , _ string ) {
159
- glog . V ( 3 ). Infof ( "Starting FakeAppProtectPlugin" )
163
+ func (fm * FakeManager ) AppProtectPluginStart (_ chan error , _ string ) {
164
+ nl . Debugf ( fm . logger , "Starting FakeAppProtectPlugin" )
160
165
}
161
166
162
167
// AppProtectPluginQuit is a fake implementation AppProtectPluginQuit
163
- func (* FakeManager ) AppProtectPluginQuit () {
164
- glog . V ( 3 ). Infof ( "Quitting FakeAppProtectPlugin" )
168
+ func (fm * FakeManager ) AppProtectPluginQuit () {
169
+ nl . Debugf ( fm . logger , "Quitting FakeAppProtectPlugin" )
165
170
}
166
171
167
172
// AppProtectDosAgentQuit is a fake implementation AppProtectAgentQuit
168
- func (* FakeManager ) AppProtectDosAgentQuit () {
169
- glog . V ( 3 ). Infof ( "Quitting FakeAppProtectDosAgent" )
173
+ func (fm * FakeManager ) AppProtectDosAgentQuit () {
174
+ nl . Debugf ( fm . logger , "Quitting FakeAppProtectDosAgent" )
170
175
}
171
176
172
177
// AppProtectDosAgentStart is a fake implementation of AppProtectAgentStart
173
- func (* FakeManager ) AppProtectDosAgentStart (_ chan error , _ bool , _ int , _ int , _ int ) {
174
- glog . V ( 3 ). Infof ( "Starting FakeAppProtectDosAgent" )
178
+ func (fm * FakeManager ) AppProtectDosAgentStart (_ chan error , _ bool , _ int , _ int , _ int ) {
179
+ nl . Debugf ( fm . logger , "Starting FakeAppProtectDosAgent" )
175
180
}
176
181
177
182
// AgentQuit is a fake implementation AppProtectAgentQuit
178
- func (* FakeManager ) AgentQuit () {
179
- glog . V ( 3 ). Infof ( "Quitting FakeAgent" )
183
+ func (fm * FakeManager ) AgentQuit () {
184
+ nl . Debugf ( fm . logger , "Quitting FakeAgent" )
180
185
}
181
186
182
187
// AgentStart is a fake implementation of AppProtectAgentStart
183
- func (* FakeManager ) AgentStart (_ chan error , _ string ) {
184
- glog . V ( 3 ). Infof ( "Starting FakeAgent" )
188
+ func (fm * FakeManager ) AgentStart (_ chan error , _ string ) {
189
+ nl . Debugf ( fm . logger , "Starting FakeAgent" )
185
190
}
186
191
187
192
// AgentVersion is a fake implementation of AppProtectAgentStart
188
- func (* FakeManager ) AgentVersion () string {
193
+ func (fm * FakeManager ) AgentVersion () string {
189
194
return "v0.00.0-00000000"
190
195
}
191
196
@@ -196,10 +201,10 @@ func (fm *FakeManager) GetSecretsDir() string {
196
201
197
202
// UpsertSplitClientsKeyVal is a fake implementation of UpsertSplitClientsKeyVal
198
203
func (fm * FakeManager ) UpsertSplitClientsKeyVal (_ string , _ string , _ string ) {
199
- glog . V ( 3 ). Infof ( "Creating split clients key" )
204
+ nl . Debugf ( fm . logger , "Creating split clients key" )
200
205
}
201
206
202
207
// DeleteKeyValStateFiles is a fake implementation of DeleteKeyValStateFiles
203
208
func (fm * FakeManager ) DeleteKeyValStateFiles (_ string ) {
204
- glog . V ( 3 ). Infof ( "Deleting keyval state files" )
209
+ nl . Debugf ( fm . logger , "Deleting keyval state files" )
205
210
}
0 commit comments