Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Dec 29, 2022
1 parent 4367e1e commit e5b3912
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/alexec/kit/internal/types"
)

func probeLoop(ctx context.Context, stop func(), name string, probe types.Probe, callback func(name string, ok bool, err error)) {
func probeLoop(ctx context.Context, stop func(), probe types.Probe, callback func(ok bool, err error)) {
defer handleCrash(stop)
initialDelay := probe.GetInitialDelay()
period := probe.GetPeriod()
Expand Down Expand Up @@ -48,9 +48,9 @@ func probeLoop(ctx context.Context, stop func(), name string, probe types.Probe,
}

if successes == probe.GetSuccessThreshold() {
callback(name, true, nil)
callback(true, nil)
} else if failures == probe.GetFailureThreshold() {
callback(name, false, err)
callback(false, err)
}
time.Sleep(period)
}
Expand Down
25 changes: 12 additions & 13 deletions up.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func up() *cobra.Command {

for _, c := range containers {
name := c.Name
state := states[name]
state := states[c.Name]

if slices.Contains(exclude, name) {
state.Phase = types.ExcludedPhase
Expand All @@ -118,8 +118,6 @@ func up() *cobra.Command {

state.Phase = types.CreatingPhase

var pd proc.Proc

logFile, err := os.Create(filepath.Join("logs", name+".log"))
if err != nil {
if err != nil {
Expand All @@ -128,6 +126,7 @@ func up() *cobra.Command {
}
stdout := io.MultiWriter(logFile, states[c.Name].Stdout())
stderr := io.MultiWriter(logFile, states[c.Name].Stderr())
var pd proc.Proc
if c.Image == "" {
pd = &proc.HostProc{Container: c}
} else {
Expand All @@ -139,7 +138,7 @@ func up() *cobra.Command {
return err
}

go func(state *types.State) {
go func() {
defer handleCrash(stop)
wg.Add(1)
defer wg.Done()
Expand Down Expand Up @@ -172,7 +171,7 @@ func up() *cobra.Command {
time.Sleep(3 * time.Second)
}
}
}(state)
}()

go func() {
<-ctx.Done()
Expand All @@ -184,11 +183,11 @@ func up() *cobra.Command {
}()

if probe := c.LivenessProbe; probe != nil {
liveFunc := func(name string, live bool, err error) {
liveFunc := func(live bool, err error) {
if live {
states[name].Phase = types.LivePhase
state.Phase = types.LivePhase
} else {
states[name].Phase = types.DeadPhase
state.Phase = types.DeadPhase
}
if err != nil {
state.Log = types.LogEntry{Level: "error", Msg: err.Error()}
Expand All @@ -199,20 +198,20 @@ func up() *cobra.Command {
}
}
}
go probeLoop(ctx, stop, name, *probe, liveFunc)
go probeLoop(ctx, stop, *probe, liveFunc)
}
if probe := c.ReadinessProbe; probe != nil {
readyFunc := func(name string, ready bool, err error) {
readyFunc := func(ready bool, err error) {
if ready {
states[name].Phase = types.ReadyPhase
state.Phase = types.ReadyPhase
} else {
states[name].Phase = types.UnreadyPhase
state.Phase = types.UnreadyPhase
}
if err != nil {
state.Log = types.LogEntry{Level: "error", Msg: err.Error()}
}
}
go probeLoop(ctx, stop, name, *probe, readyFunc)
go probeLoop(ctx, stop, *probe, readyFunc)
}
time.Sleep(time.Second)
}
Expand Down

0 comments on commit e5b3912

Please sign in to comment.