Skip to content

Commit 5c7ad70

Browse files
committed
Refactor order of check container function to shorten line length
1 parent 7fee2d6 commit 5c7ad70

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

container.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,30 @@ func checkContainer(ctx context.Context, cli *client.Client, response types.Cont
4141
usePID bool, useCGroup bool) bool {
4242

4343
log.Println(logNotice, "Checking container ...")
44-
if usePID {
45-
log.Println(logNotice, "Checking for PID existence ...")
46-
if checkProcess(response.State.Pid) {
47-
if useCGroup {
48-
log.Println(logNotice, "Checking for PID existence in CGroup ...")
49-
cgroup := fmt.Sprintf(dockerCGroupFormat, response.ID)
50-
if checkCGroup(response.State.Pid, cgroup) {
51-
log.Println(logNotice, "Successfully checked for PID existence in CGroup.")
52-
return true
53-
} else {
54-
log.Println(logNotice, "Failed to check for PID existence in CGroup.")
55-
return false
56-
}
57-
} else {
58-
log.Println(logNotice, "Successfully checked for PID existence, but skipped CGroup.")
59-
return true
60-
}
61-
} else {
62-
log.Println(logNotice, "Failed to check for PID existence.")
63-
return false
64-
}
65-
} else {
44+
if !usePID {
6645
log.Println(logInfo, "Skipped check for PID existence.")
6746
return true
6847
}
48+
49+
log.Println(logNotice, "Checking for PID existence ...")
50+
if !checkProcess(response.State.Pid) {
51+
log.Println(logNotice, "Failed to check for PID existence.")
52+
return false
53+
}
54+
if !useCGroup {
55+
log.Println(logNotice, "Successfully checked for PID existence, but skipped CGroup.")
56+
return true
57+
}
58+
59+
log.Println(logNotice, "Checking for PID existence in CGroup ...")
60+
cgroup := fmt.Sprintf(dockerCGroupFormat, response.ID)
61+
if !checkCGroup(response.State.Pid, cgroup) {
62+
log.Println(logNotice, "Failed to check for PID existence in CGroup.")
63+
return false
64+
}
65+
66+
log.Println(logNotice, "Successfully checked for PID existence in CGroup.")
67+
return true
6968
}
7069

7170
func startContainer(ctx context.Context, cli *client.Client, containerName string) bool {

0 commit comments

Comments
 (0)