@@ -57,7 +57,39 @@ func TestParseHealthCheck(t *testing.T) {
|
||||
Retries: 2,
|
||||
StartPeriod: 3,
|
||||
}
|
||||
output, err := parseHealthCheck(check)
|
||||
output, err := parseHealthCheck(check, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to convert HealthCheckConfig: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(output, expected) {
|
||||
t.Errorf("Structs are not equal, expected: %v, output: %v", expected, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHttpHealthCheck(t *testing.T) {
|
||||
helperValue := uint64(2)
|
||||
check := types.HealthCheckConfig{
|
||||
Timeout: durationTypesPtr(1 * time.Second),
|
||||
Interval: durationTypesPtr(2 * time.Second),
|
||||
Retries: &helperValue,
|
||||
StartPeriod: durationTypesPtr(3 * time.Second),
|
||||
}
|
||||
label := types.Labels{
|
||||
HealthCheckLivenessHTTPGetPath: "ping",
|
||||
HealthCheckLivenessHTTPGetPort: "80",
|
||||
}
|
||||
|
||||
// CMD-SHELL or SHELL is included Test within docker/cli, thus we remove the first value in Test
|
||||
expected := kobject.HealthCheck{
|
||||
HTTPPath: "ping",
|
||||
HTTPPort: 80,
|
||||
Timeout: 1,
|
||||
Interval: 2,
|
||||
Retries: 2,
|
||||
StartPeriod: 3,
|
||||
}
|
||||
output, err := parseHealthCheck(check, label)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to convert HealthCheckConfig: %s", err)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ const (
|
||||
HealthCheckReadinessRetries = "kompose.service.healthcheck.readiness.retries"
|
||||
// HealthCheckReadinessStartPeriod defines readiness health check start period
|
||||
HealthCheckReadinessStartPeriod = "kompose.service.healthcheck.readiness.start_period"
|
||||
// HealthCheckLivenessHTTPGetPath defines liveness health check HttpGet path
|
||||
HealthCheckLivenessHTTPGetPath = "kompose.service.healthcheck.liveness.http_get_path"
|
||||
// HealthCheckLivenessHTTPGetPort defines liveness health check HttpGet port
|
||||
HealthCheckLivenessHTTPGetPort = "kompose.service.healthcheck.liveness.http_get_port"
|
||||
|
||||
// ServiceTypeHeadless ...
|
||||
ServiceTypeHeadless = "Headless"
|
||||
|
||||
@@ -288,8 +288,11 @@ func parseHealthCheckReadiness(labels types.Labels) (kobject.HealthCheck, error)
|
||||
/* Convert the HealthCheckConfig as designed by Docker to
|
||||
a Kubernetes-compatible format.
|
||||
*/
|
||||
func parseHealthCheck(composeHealthCheck types.HealthCheckConfig) (kobject.HealthCheck, error) {
|
||||
func parseHealthCheck(composeHealthCheck types.HealthCheckConfig, labels types.Labels) (kobject.HealthCheck, error) {
|
||||
var timeout, interval, retries, startPeriod int32
|
||||
var test []string
|
||||
var httpPort int32
|
||||
var httpPath string
|
||||
|
||||
// Here we convert the timeout from 1h30s (example) to 36030 seconds.
|
||||
if composeHealthCheck.Timeout != nil {
|
||||
@@ -320,9 +323,24 @@ func parseHealthCheck(composeHealthCheck types.HealthCheckConfig) (kobject.Healt
|
||||
startPeriod = int32(parse.Seconds())
|
||||
}
|
||||
|
||||
if composeHealthCheck.Test != nil {
|
||||
test = composeHealthCheck.Test[1:]
|
||||
}
|
||||
|
||||
for key, value := range labels {
|
||||
switch key {
|
||||
case HealthCheckLivenessHTTPGetPath:
|
||||
httpPath = value
|
||||
case HealthCheckLivenessHTTPGetPort:
|
||||
httpPort = cast.ToInt32(value)
|
||||
}
|
||||
}
|
||||
|
||||
// Due to docker/cli adding "CMD-SHELL" to the struct, we remove the first element of composeHealthCheck.Test
|
||||
return kobject.HealthCheck{
|
||||
Test: composeHealthCheck.Test[1:],
|
||||
Test: test,
|
||||
HTTPPath: httpPath,
|
||||
HTTPPort: httpPort,
|
||||
Timeout: timeout,
|
||||
Interval: interval,
|
||||
Retries: retries,
|
||||
@@ -384,7 +402,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
|
||||
// HealthCheck Liveness
|
||||
if composeServiceConfig.HealthCheck != nil && !composeServiceConfig.HealthCheck.Disable {
|
||||
var err error
|
||||
serviceConfig.HealthChecks.Liveness, err = parseHealthCheck(*composeServiceConfig.HealthCheck)
|
||||
serviceConfig.HealthChecks.Liveness, err = parseHealthCheck(*composeServiceConfig.HealthCheck, *&composeServiceConfig.Labels)
|
||||
if err != nil {
|
||||
return kobject.KomposeObject{}, errors.Wrap(err, "Unable to parse health check")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user