Skip to content

Commit a172d77

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

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

internal/mode/static/manager.go

Lines changed: 6 additions & 2 deletions
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,9 +135,12 @@ 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
}
141+
//if err := ngxruntime.EnsureNginxRunning(ctx, &ngxruntime.ProcessHandlerImpl{}); err != nil {
142+
// return fmt.Errorf("NGINX is not running: %w", err)
143+
//}
140144

141145
var (
142146
ngxruntimeCollector ngxruntime.MetricsCollector = collectors.NewManagerNoopCollector()
@@ -211,7 +215,7 @@ func StartManager(cfg config.Config) error {
211215
ngxPlusClient,
212216
ngxruntimeCollector,
213217
cfg.Logger.WithName("nginxRuntimeManager"),
214-
&ngxruntime.ProcessHandlerImpl{},
218+
proccesHandler,
215219
ngxruntime.NewVerifyClient(ngxruntime.NginxReloadTimeout),
216220
),
217221
statusUpdater: groupStatusUpdater,

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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)