|
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
8 | 8 | "sort" |
9 | | - "strings" |
10 | 9 |
|
11 | 10 | "github.com/kernel/hypeman-go" |
12 | 11 | ) |
@@ -155,78 +154,45 @@ func updateDesiredInstanceImage(instances []desiredInstance, composeName, servic |
155 | 154 | } |
156 | 155 |
|
157 | 156 | func buildComposeRestartPolicy(restart *composeRestartSpec) hypeman.RestartPolicyParam { |
158 | | - policy := hypeman.RestartPolicyParam{} |
159 | | - if restart.Policy != "" { |
160 | | - policy.Policy = hypeman.RestartPolicyPolicy(strings.ReplaceAll(restart.Policy, "-", "_")) |
161 | | - } |
162 | | - if restart.Backoff != "" { |
163 | | - policy.Backoff = hypeman.String(restart.Backoff) |
| 157 | + in := RestartPolicyInput{ |
| 158 | + Policy: restart.Policy, |
| 159 | + Backoff: restart.Backoff, |
| 160 | + StableAfter: restart.StableAfter, |
164 | 161 | } |
165 | 162 | if restart.MaxAttempts > 0 { |
166 | | - policy.MaxAttempts = hypeman.Int(int64(restart.MaxAttempts)) |
167 | | - } |
168 | | - if restart.StableAfter != "" { |
169 | | - policy.StableAfter = hypeman.String(restart.StableAfter) |
| 163 | + v := int64(restart.MaxAttempts) |
| 164 | + in.MaxAttempts = &v |
170 | 165 | } |
171 | | - return policy |
| 166 | + return BuildRestartPolicyParam(in) |
172 | 167 | } |
173 | 168 |
|
174 | 169 | func buildComposeHealthCheck(check *composeCheckSpec) hypeman.HealthCheckParam { |
175 | | - health := hypeman.HealthCheckParam{} |
176 | | - if check.Type != "" { |
177 | | - health.Type = hypeman.HealthCheckType(strings.ToLower(check.Type)) |
| 170 | + in := HealthCheckInput{ |
| 171 | + Type: check.Type, |
| 172 | + Interval: check.Interval, |
| 173 | + Timeout: check.Timeout, |
| 174 | + StartPeriod: check.StartPeriod, |
| 175 | + FailureThreshold: int64(check.FailureThreshold), |
| 176 | + SuccessThreshold: int64(check.SuccessThreshold), |
178 | 177 | } |
179 | 178 | if check.HTTP != nil { |
180 | | - health.Type = defaultHealthCheckType(health.Type, hypeman.HealthCheckTypeHTTP) |
181 | | - health.HTTP = hypeman.HealthCheckHTTPParam{ |
182 | | - Port: int64(check.HTTP.Port), |
183 | | - } |
184 | | - if check.HTTP.Path != "" { |
185 | | - health.HTTP.Path = hypeman.String(check.HTTP.Path) |
186 | | - } |
187 | | - if check.HTTP.Scheme != "" { |
188 | | - health.HTTP.Scheme = hypeman.HealthCheckHTTPScheme(strings.ToLower(check.HTTP.Scheme)) |
189 | | - } |
190 | | - if check.HTTP.ExpectedStatus > 0 { |
191 | | - health.HTTP.ExpectedStatus = hypeman.Int(int64(check.HTTP.ExpectedStatus)) |
| 179 | + in.HTTP = &HealthCheckHTTPInput{ |
| 180 | + Port: int64(check.HTTP.Port), |
| 181 | + Path: check.HTTP.Path, |
| 182 | + Scheme: check.HTTP.Scheme, |
| 183 | + ExpectedStatus: int64(check.HTTP.ExpectedStatus), |
192 | 184 | } |
193 | 185 | } |
194 | 186 | if check.TCP != nil { |
195 | | - health.Type = defaultHealthCheckType(health.Type, hypeman.HealthCheckTypeTcp) |
196 | | - health.Tcp = hypeman.HealthCheckTcpParam{Port: int64(check.TCP.Port)} |
| 187 | + in.TCP = &HealthCheckTCPInput{Port: int64(check.TCP.Port)} |
197 | 188 | } |
198 | 189 | if check.Exec != nil { |
199 | | - health.Type = defaultHealthCheckType(health.Type, hypeman.HealthCheckTypeExec) |
200 | | - health.Exec = hypeman.HealthCheckExecParam{ |
201 | | - Command: check.Exec.Command, |
202 | | - } |
203 | | - if check.Exec.WorkingDir != "" { |
204 | | - health.Exec.WorkingDir = hypeman.String(check.Exec.WorkingDir) |
| 190 | + in.Exec = &HealthCheckExecInput{ |
| 191 | + Command: check.Exec.Command, |
| 192 | + WorkingDir: check.Exec.WorkingDir, |
205 | 193 | } |
206 | 194 | } |
207 | | - if check.Interval != "" { |
208 | | - health.Interval = hypeman.String(check.Interval) |
209 | | - } |
210 | | - if check.Timeout != "" { |
211 | | - health.Timeout = hypeman.String(check.Timeout) |
212 | | - } |
213 | | - if check.StartPeriod != "" { |
214 | | - health.StartPeriod = hypeman.String(check.StartPeriod) |
215 | | - } |
216 | | - if check.FailureThreshold > 0 { |
217 | | - health.FailureThreshold = hypeman.Int(int64(check.FailureThreshold)) |
218 | | - } |
219 | | - if check.SuccessThreshold > 0 { |
220 | | - health.SuccessThreshold = hypeman.Int(int64(check.SuccessThreshold)) |
221 | | - } |
222 | | - return health |
223 | | -} |
224 | | - |
225 | | -func defaultHealthCheckType(current, fallback hypeman.HealthCheckType) hypeman.HealthCheckType { |
226 | | - if current != "" { |
227 | | - return current |
228 | | - } |
229 | | - return fallback |
| 195 | + return BuildHealthCheckParam(in) |
230 | 196 | } |
231 | 197 |
|
232 | 198 | func buildComposeIngressInput(instanceName, ingressName string, spec composeIngressRuleSpec) hypeman.IngressNewParams { |
|
0 commit comments