Skip to content

Commit 11ef349

Browse files
authored
Merge pull request #1326 from shin-/compose-json-annotations
Allow marshalling of Compose config to JSON
2 parents 00e6843 + e7788d6 commit 11ef349

9 files changed

Lines changed: 854 additions & 189 deletions

File tree

cli/command/stack/kubernetes/convert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func fromComposeServiceConfig(s composeTypes.ServiceConfig) v1beta2.ServiceConfi
222222
ReadOnly: s.ReadOnly,
223223
Secrets: fromComposeServiceSecrets(s.Secrets),
224224
StdinOpen: s.StdinOpen,
225-
StopGracePeriod: s.StopGracePeriod,
225+
StopGracePeriod: composetypes.ConvertDurationPtr(s.StopGracePeriod),
226226
Tmpfs: s.Tmpfs,
227227
Tty: s.Tty,
228228
User: userID,
@@ -285,8 +285,8 @@ func fromComposeHealthcheck(h *composeTypes.HealthCheckConfig) *v1beta2.HealthCh
285285
}
286286
return &v1beta2.HealthCheckConfig{
287287
Test: h.Test,
288-
Timeout: h.Timeout,
289-
Interval: h.Interval,
288+
Timeout: composetypes.ConvertDurationPtr(h.Timeout),
289+
Interval: composetypes.ConvertDurationPtr(h.Interval),
290290
Retries: h.Retries,
291291
}
292292
}

cli/command/stack/kubernetes/warnings_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestWarnings(t *testing.T) {
13-
duration := 5 * time.Second
13+
duration := composetypes.Duration(5 * time.Second)
1414
attempts := uint64(3)
1515
config := &composetypes.Config{
1616
Version: "3.4",
@@ -26,9 +26,9 @@ func TestWarnings(t *testing.T) {
2626
DependsOn: []string{"ignored"},
2727
Deploy: composetypes.DeployConfig{
2828
UpdateConfig: &composetypes.UpdateConfig{
29-
Delay: 5 * time.Second,
29+
Delay: composetypes.Duration(5 * time.Second),
3030
FailureAction: "rollback",
31-
Monitor: 10 * time.Second,
31+
Monitor: composetypes.Duration(10 * time.Second),
3232
MaxFailureRatio: 0.5,
3333
},
3434
RestartPolicy: &composetypes.RestartPolicy{

cli/compose/convert/service.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func Service(
141141
Dir: service.WorkingDir,
142142
User: service.User,
143143
Mounts: mounts,
144-
StopGracePeriod: service.StopGracePeriod,
144+
StopGracePeriod: composetypes.ConvertDurationPtr(service.StopGracePeriod),
145145
StopSignal: service.StopSignal,
146146
TTY: service.Tty,
147147
OpenStdin: service.StdinOpen,
@@ -414,13 +414,13 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
414414

415415
}
416416
if healthcheck.Timeout != nil {
417-
timeout = *healthcheck.Timeout
417+
timeout = time.Duration(*healthcheck.Timeout)
418418
}
419419
if healthcheck.Interval != nil {
420-
interval = *healthcheck.Interval
420+
interval = time.Duration(*healthcheck.Interval)
421421
}
422422
if healthcheck.StartPeriod != nil {
423-
startPeriod = *healthcheck.StartPeriod
423+
startPeriod = time.Duration(*healthcheck.StartPeriod)
424424
}
425425
if healthcheck.Retries != nil {
426426
retries = int(*healthcheck.Retries)
@@ -458,11 +458,12 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
458458
return nil, errors.Errorf("unknown restart policy: %s", restart)
459459
}
460460
}
461+
461462
return &swarm.RestartPolicy{
462463
Condition: swarm.RestartPolicyCondition(source.Condition),
463-
Delay: source.Delay,
464+
Delay: composetypes.ConvertDurationPtr(source.Delay),
464465
MaxAttempts: source.MaxAttempts,
465-
Window: source.Window,
466+
Window: composetypes.ConvertDurationPtr(source.Window),
466467
}, nil
467468
}
468469

@@ -476,9 +477,9 @@ func convertUpdateConfig(source *composetypes.UpdateConfig) *swarm.UpdateConfig
476477
}
477478
return &swarm.UpdateConfig{
478479
Parallelism: parallel,
479-
Delay: source.Delay,
480+
Delay: time.Duration(source.Delay),
480481
FailureAction: source.FailureAction,
481-
Monitor: source.Monitor,
482+
Monitor: time.Duration(source.Monitor),
482483
MaxFailureRatio: source.MaxFailureRatio,
483484
Order: source.Order,
484485
}

cli/compose/convert/service_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
124124

125125
func TestConvertHealthcheck(t *testing.T) {
126126
retries := uint64(10)
127-
timeout := 30 * time.Second
128-
interval := 2 * time.Millisecond
127+
timeout := composetypes.Duration(30 * time.Second)
128+
interval := composetypes.Duration(2 * time.Millisecond)
129129
source := &composetypes.HealthCheckConfig{
130130
Test: []string{"EXEC", "touch", "/foo"},
131131
Timeout: &timeout,
@@ -134,8 +134,8 @@ func TestConvertHealthcheck(t *testing.T) {
134134
}
135135
expected := &container.HealthConfig{
136136
Test: source.Test,
137-
Timeout: timeout,
138-
Interval: interval,
137+
Timeout: time.Duration(timeout),
138+
Interval: time.Duration(interval),
139139
Retries: 10,
140140
}
141141

0 commit comments

Comments
 (0)