Skip to content

Commit 8d57c25

Browse files
committed
adding processHandler struct update
1 parent 2d30681 commit 8d57c25

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

internal/mode/static/manager.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const (
6363
)
6464

6565
var scheme = runtime.NewScheme()
66+
var proccesHandler = &ngxruntime.ProcessHandlerImpl{}
6667

6768
func init() {
6869
utilruntime.Must(gatewayv1beta1.Install(scheme))
@@ -134,7 +135,7 @@ func StartManager(cfg config.Config) error {
134135
}
135136

136137
// Ensure NGINX is running before registering metrics & starting the manager.
137-
if err := ngxruntime.EnsureNginxRunning(ctx, &ngxruntime.ProcessHandlerImpl{}); err != nil {
138+
if err := proccesHandler.EnsureNginxRunning(ctx); err != nil {
138139
return fmt.Errorf("NGINX is not running: %w", err)
139140
}
140141

@@ -211,7 +212,7 @@ func StartManager(cfg config.Config) error {
211212
ngxPlusClient,
212213
ngxruntimeCollector,
213214
cfg.Logger.WithName("nginxRuntimeManager"),
214-
&ngxruntime.ProcessHandlerImpl{},
215+
proccesHandler,
215216
ngxruntime.NewVerifyClient(ngxruntime.NginxReloadTimeout),
216217
),
217218
statusUpdater: groupStatusUpdater,

internal/mode/static/nginx/runtime/manager.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ type nginxPlusClient interface {
3636
GetUpstreams() (*ngxclient.Upstreams, error)
3737
}
3838

39-
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . processHandler
39+
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ProcessHandler
4040

4141
type ProcessHandler interface {
4242
FindMainProcess(ctx context.Context, checkFile CheckFileFunc, readFile ReadFileFunc, timeout time.Duration) (int, error)
4343
ReadFile(file string) ([]byte, error)
4444
Kill(pid int, signum syscall.Signal) error
45+
EnsureNginxRunning(ctx context.Context) error
4546
}
4647

4748
type ProcessHandlerImpl struct {
@@ -176,8 +177,8 @@ func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error) {
176177
}
177178

178179
// EnsureNginxRunning ensures NGINX is running by locating the main process.
179-
func EnsureNginxRunning(ctx context.Context, processHandler ProcessHandler) error {
180-
if _, err := processHandler.FindMainProcess(ctx, os.Stat, os.ReadFile, pidFileTimeout); err != nil {
180+
func (p *ProcessHandlerImpl) EnsureNginxRunning(ctx context.Context) error {
181+
if _, err := p.FindMainProcess(ctx, os.Stat, os.ReadFile, pidFileTimeout); err != nil {
181182
return fmt.Errorf("failed to find NGINX main process: %w", err)
182183
}
183184
return nil

internal/mode/static/nginx/runtime/runtimefakes/fake_process_handler.go

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)