Skip to content

Commit

Permalink
adding processHandler struct update
Browse files Browse the repository at this point in the history
  • Loading branch information
miledxz committed May 20, 2024
1 parent 2d30681 commit 8d57c25
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
5 changes: 3 additions & 2 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
)

var scheme = runtime.NewScheme()
var proccesHandler = &ngxruntime.ProcessHandlerImpl{}

func init() {
utilruntime.Must(gatewayv1beta1.Install(scheme))
Expand Down Expand Up @@ -134,7 +135,7 @@ func StartManager(cfg config.Config) error {
}

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

Expand Down Expand Up @@ -211,7 +212,7 @@ func StartManager(cfg config.Config) error {
ngxPlusClient,
ngxruntimeCollector,
cfg.Logger.WithName("nginxRuntimeManager"),
&ngxruntime.ProcessHandlerImpl{},
proccesHandler,
ngxruntime.NewVerifyClient(ngxruntime.NginxReloadTimeout),
),
statusUpdater: groupStatusUpdater,
Expand Down
7 changes: 4 additions & 3 deletions internal/mode/static/nginx/runtime/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ type nginxPlusClient interface {
GetUpstreams() (*ngxclient.Upstreams, error)
}

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . processHandler
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ProcessHandler

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

type ProcessHandlerImpl struct {
Expand Down Expand Up @@ -176,8 +177,8 @@ func (m *ManagerImpl) GetUpstreams() (ngxclient.Upstreams, error) {
}

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d57c25

Please sign in to comment.