@@ -2,12 +2,14 @@ package kube
2
2
3
3
import (
4
4
"fmt"
5
+ "log"
5
6
"strings"
6
7
"time"
7
8
8
9
"github.com/compose-spec/compose-go/types"
9
10
apps "k8s.io/api/apps/v1"
10
11
core "k8s.io/api/core/v1"
12
+ resource "k8s.io/apimachinery/pkg/api/resource"
11
13
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
12
14
"k8s.io/apimachinery/pkg/runtime"
13
15
"k8s.io/apimachinery/pkg/util/intstr"
@@ -17,7 +19,13 @@ func MapToKubernetesObjects(model *types.Config, name string) (map[string]runtim
17
19
objects := map [string ]runtime.Object {}
18
20
19
21
for _ , service := range model .Services {
20
- objects [fmt .Sprintf ("%s-service.yaml" , service .Name )] = mapToService (model , service )
22
+ svcObject := mapToService (model , service )
23
+ if svcObject != nil {
24
+ objects [fmt .Sprintf ("%s-service.yaml" , service .Name )] = svcObject
25
+ } else {
26
+ log .Println ("Missing port mapping from service config." )
27
+ }
28
+
21
29
if service .Deploy != nil && service .Deploy .Mode == "global" {
22
30
daemonset , err := mapToDaemonset (service , model , name )
23
31
if err != nil {
@@ -33,7 +41,8 @@ func MapToKubernetesObjects(model *types.Config, name string) (map[string]runtim
33
41
}
34
42
for _ , vol := range service .Volumes {
35
43
if vol .Type == "volume" {
36
- objects [fmt .Sprintf ("%s-persistentvolumeclain.yaml" , service .Name )] = mapToPVC (service , vol )
44
+ vol .Source = strings .ReplaceAll (vol .Source , "_" , "-" )
45
+ objects [fmt .Sprintf ("%s-persistentvolumeclaim.yaml" , vol .Source )] = mapToPVC (service , vol )
37
46
}
38
47
}
39
48
}
@@ -51,7 +60,9 @@ func mapToService(model *types.Config, service types.ServiceConfig) *core.Servic
51
60
Protocol : toProtocol (p .Protocol ),
52
61
})
53
62
}
54
-
63
+ if len (ports ) == 0 {
64
+ return nil
65
+ }
55
66
return & core.Service {
56
67
TypeMeta : meta.TypeMeta {
57
68
Kind : "Service" ,
@@ -167,13 +178,27 @@ func toDeploymentStrategy(deploy *types.DeployConfig) apps.DeploymentStrategy {
167
178
}
168
179
169
180
func mapToPVC (service types.ServiceConfig , vol types.ServiceVolumeConfig ) runtime.Object {
181
+ rwaccess := core .ReadWriteOnce
182
+ if vol .ReadOnly {
183
+ rwaccess = core .ReadOnlyMany
184
+ }
170
185
return & core.PersistentVolumeClaim {
186
+ TypeMeta : meta.TypeMeta {
187
+ Kind : "PersistentVolumeClaim" ,
188
+ APIVersion : "v1" ,
189
+ },
171
190
ObjectMeta : meta.ObjectMeta {
172
191
Name : vol .Source ,
173
192
Labels : map [string ]string {"com.docker.compose.service" : service .Name },
174
193
},
175
194
Spec : core.PersistentVolumeClaimSpec {
176
- VolumeName : vol .Source ,
195
+ VolumeName : vol .Source ,
196
+ AccessModes : []core.PersistentVolumeAccessMode {rwaccess },
197
+ Resources : core.ResourceRequirements {
198
+ Requests : core.ResourceList {
199
+ core .ResourceStorage : resource .MustParse ("100Mi" ),
200
+ },
201
+ },
177
202
},
178
203
}
179
204
}
0 commit comments