@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/containers/common/libimage"
16
16
"github.com/containers/common/pkg/config"
17
+ "github.com/containers/image/v5/manifest"
17
18
"github.com/containers/podman/v5/libpod"
18
19
"github.com/containers/podman/v5/libpod/define"
19
20
ann "github.com/containers/podman/v5/pkg/annotations"
@@ -61,6 +62,66 @@ func getImageFromSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGen
61
62
return image , resolvedName , inspectData , err
62
63
}
63
64
65
+ func applyHealthCheckOverrides (s * specgen.SpecGenerator , healthCheckFromImage * manifest.Schema2HealthConfig ) error {
66
+ overrideHealthCheckConfig := s .HealthConfig
67
+ s .HealthConfig = healthCheckFromImage
68
+
69
+ if s .HealthConfig == nil {
70
+ return nil
71
+ }
72
+
73
+ if overrideHealthCheckConfig != nil {
74
+ if overrideHealthCheckConfig .Interval != 0 {
75
+ s .HealthConfig .Interval = overrideHealthCheckConfig .Interval
76
+ }
77
+ if overrideHealthCheckConfig .Retries != 0 {
78
+ s .HealthConfig .Retries = overrideHealthCheckConfig .Retries
79
+ }
80
+ if overrideHealthCheckConfig .Timeout != 0 {
81
+ s .HealthConfig .Timeout = overrideHealthCheckConfig .Timeout
82
+ }
83
+ if overrideHealthCheckConfig .StartPeriod != 0 {
84
+ s .HealthConfig .StartPeriod = overrideHealthCheckConfig .StartPeriod
85
+ }
86
+ }
87
+
88
+ disableInterval := false
89
+ if s .HealthConfig .Interval < 0 {
90
+ s .HealthConfig .Interval = 0
91
+ disableInterval = true
92
+ }
93
+
94
+ // NOTE: Zero means inherit.
95
+ if s .HealthConfig .Timeout == 0 {
96
+ hct , err := time .ParseDuration (define .DefaultHealthCheckTimeout )
97
+ if err != nil {
98
+ return err
99
+ }
100
+ s .HealthConfig .Timeout = hct
101
+ }
102
+ if s .HealthConfig .Interval == 0 && ! disableInterval {
103
+ hct , err := time .ParseDuration (define .DefaultHealthCheckInterval )
104
+ if err != nil {
105
+ return err
106
+ }
107
+ s .HealthConfig .Interval = hct
108
+ }
109
+
110
+ if s .HealthConfig .Retries == 0 {
111
+ s .HealthConfig .Retries = int (define .DefaultHealthCheckRetries )
112
+ }
113
+
114
+ if s .HealthConfig .StartPeriod == 0 {
115
+ hct , err := time .ParseDuration (define .DefaultHealthCheckStartPeriod )
116
+ if err != nil {
117
+ return err
118
+ }
119
+ s .HealthConfig .StartPeriod = hct
120
+ }
121
+
122
+ return nil
123
+ }
124
+
64
125
// Fill any missing parts of the spec generator (e.g. from the image).
65
126
// Returns a set of warnings or any fatal error that occurred.
66
127
func CompleteSpec (ctx context.Context , r * libpod.Runtime , s * specgen.SpecGenerator ) ([]string , error ) {
@@ -70,25 +131,9 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
70
131
return nil , err
71
132
}
72
133
if inspectData != nil {
73
- if s .HealthConfig == nil {
74
- // NOTE: the health check is only set for Docker images
75
- // but inspect will take care of it.
76
- s .HealthConfig = inspectData .HealthCheck
77
- if s .HealthConfig != nil {
78
- if s .HealthConfig .Timeout == 0 {
79
- hct , err := time .ParseDuration (define .DefaultHealthCheckTimeout )
80
- if err != nil {
81
- return nil , err
82
- }
83
- s .HealthConfig .Timeout = hct
84
- }
85
- if s .HealthConfig .Interval == 0 {
86
- hct , err := time .ParseDuration (define .DefaultHealthCheckInterval )
87
- if err != nil {
88
- return nil , err
89
- }
90
- s .HealthConfig .Interval = hct
91
- }
134
+ if s .HealthConfig == nil || len (s .HealthConfig .Test ) == 0 {
135
+ if err := applyHealthCheckOverrides (s , inspectData .HealthCheck ); err != nil {
136
+ return nil , err
92
137
}
93
138
}
94
139
0 commit comments