Skip to content

Commit 910234b

Browse files
committed
Merge branch 'check-port' into 'master'
check port See merge request !43
2 parents c4f0160 + 0f9b3c0 commit 910234b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cluster/calcium/create_container.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,23 @@ func (c *calcium) makeContainerOptions(quota map[string]int, specs types.Specs,
595595

596596
// labels
597597
// basic labels, and set meta in specs to labels
598-
ports := []string{}
599-
for _, port := range entry.Ports {
600-
ports = append(ports, string(port))
601-
}
602598
containerLabels := map[string]string{
603599
"ERU": "1",
604600
"version": utils.GetVersion(opts.Image),
605-
"ports": strings.Join(ports, ","),
606601
}
602+
// 如果有声明检查的端口就用这个端口
603+
// 否则还是按照publish出去端口来检查
604+
if entry.HealthCheckPort != 0 {
605+
//XXX 随便给个 tcp 吧
606+
containerLabels["ports"] = fmt.Sprintf("%d/tcp", entry.HealthCheckPort)
607+
} else {
608+
ports := []string{}
609+
for _, port := range entry.Ports {
610+
ports = append(ports, string(port))
611+
}
612+
containerLabels["ports"] = strings.Join(ports, ",")
613+
}
614+
607615
// 只要声明了ports,就免费赠送tcp健康检查,如果需要http健康检查,还要单独声明 healthcheck_url
608616
if entry.HealthCheckUrl != "" {
609617
containerLabels["healthcheck"] = "http"

types/specs.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Entrypoint struct {
2929
Exposes []Expose `yaml:"exposes,omitempty,flow"`
3030
NetworkMode string `yaml:"network_mode,omitempty"`
3131
RestartPolicy string `yaml:"restart,omitempty"`
32+
HealthCheckPort int `yaml:"healthcheck_port,omitempty,flow"`
3233
HealthCheckUrl string `yaml:"healthcheck_url,omitempty"`
3334
HealthCheckExpectedCode int `yaml:"healthcheck_expected_code,omitempty"`
3435
ExtraHosts []string `yaml:"hosts,omitempty,flow"`

0 commit comments

Comments
 (0)