Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var up = &cobra.Command{
return fmt.Errorf("failed while rendering files from ignition config, err: %w", err)
}

signals := make(chan os.Signal)
signals := make(chan os.Signal, 1)
signal.Notify(signals,
syscall.SIGTERM,
syscall.SIGINT,
Expand Down
3 changes: 2 additions & 1 deletion pkg/proc/basejob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
func startTestJob(t *testing.T) (*baseJob, chan error) {
t.Helper()

job, err := newBaseJob(&config.BaseJobConfig{
job := &baseJob{}
err := job.init(&config.BaseJobConfig{
Name: "test-job",
Command: "sleep",
Args: []string{"30"},
Expand Down
42 changes: 18 additions & 24 deletions pkg/proc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,18 @@ type Job interface {
GetName() string
}

func newBaseJob(jobConfig *config.BaseJobConfig) (*baseJob, error) {
job := &baseJob{
Config: jobConfig,
cmd: nil,
restart: false,
stop: false,
stdout: os.Stdout,
stderr: os.Stderr,
}
// init initializes the baseJob in place; baseJob must not be copied once
// initialized, since it contains sync.WaitGroup and atomic.Bool fields.
func (job *baseJob) init(jobConfig *config.BaseJobConfig) error {
job.Config = jobConfig
job.stdout = os.Stdout
job.stderr = os.Stderr
job.phase.Set(JobPhaseReasonAwaitingReadiness)
if len(jobConfig.Stdout) == 0 {
return job, nil
return nil
}

return job, job.CreateAndOpenStdFile(jobConfig)
return job.CreateAndOpenStdFile(jobConfig)
Comment thread
leontappe marked this conversation as resolved.
Outdated
}

func (job *baseJob) CreateAndOpenStdFile(jobConfig *config.BaseJobConfig) error {
Expand Down Expand Up @@ -174,29 +171,26 @@ func (job *baseJob) CreateAndOpenStdFile(jobConfig *config.BaseJobConfig) error
}

func NewCommonJob(c *config.JobConfig) (*CommonJob, error) {
job, err := newBaseJob(&c.BaseJobConfig)
if err != nil {
return nil, err
j := CommonJob{
Config: c,
}

j := CommonJob{
baseJob: *job,
Config: c,
if err := j.baseJob.init(&c.BaseJobConfig); err != nil {
return nil, err
}

return &j, nil
}

func NewLazyJob(c *config.JobConfig) (*LazyJob, error) {
commonJob, err := NewCommonJob(c)
if err != nil {
return nil, err
j := LazyJob{
CommonJob: CommonJob{
Config: c,
},
}

commonJob.phase.Set(JobPhaseReasonAwaitingReadiness)

j := LazyJob{
CommonJob: *commonJob,
if err := j.baseJob.init(&c.BaseJobConfig); err != nil {
return nil, err
}

if c.Laziness.SpinUpTimeout != "" {
Expand Down
Loading