1
1
package manifest
2
2
3
3
import (
4
+ "fmt"
5
+ "path"
4
6
"strings"
5
7
6
8
"github.com/docker/buildx/util/platformutil"
@@ -25,9 +27,8 @@ type DeploymentOpt struct {
25
27
}
26
28
27
29
BuildkitFlags []string
28
- // BuildkitConfig
29
- // when not empty, will create configmap with buildkit.toml and mounted
30
- BuildkitConfig []byte
30
+ // files mounted at /etc/buildkitd
31
+ ConfigFiles map [string ][]byte
31
32
32
33
Rootless bool
33
34
NodeSelector map [string ]string
@@ -43,7 +44,7 @@ const (
43
44
AnnotationPlatform = "buildx.docker.com/platform"
44
45
)
45
46
46
- func NewDeployment (opt * DeploymentOpt ) (d * appsv1.Deployment , c * corev1.ConfigMap , err error ) {
47
+ func NewDeployment (opt * DeploymentOpt ) (d * appsv1.Deployment , c [] * corev1.ConfigMap , err error ) {
47
48
labels := map [string ]string {
48
49
"app" : opt .Name ,
49
50
}
@@ -103,38 +104,36 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c *corev1.ConfigMa
103
104
},
104
105
},
105
106
}
106
-
107
- if len (opt .BuildkitConfig ) > 0 {
108
- c = & corev1.ConfigMap {
107
+ for _ , cfg := range splitConfigFiles (opt .ConfigFiles ) {
108
+ cc := & corev1.ConfigMap {
109
109
TypeMeta : metav1.TypeMeta {
110
110
APIVersion : corev1 .SchemeGroupVersion .String (),
111
111
Kind : "ConfigMap" ,
112
112
},
113
113
ObjectMeta : metav1.ObjectMeta {
114
114
Namespace : opt .Namespace ,
115
- Name : opt .Name + "-config" ,
115
+ Name : opt .Name + "-" + cfg . name ,
116
116
Annotations : annotations ,
117
117
},
118
- Data : map [string ]string {
119
- "buildkitd.toml" : string (opt .BuildkitConfig ),
120
- },
118
+ Data : cfg .files ,
121
119
}
122
120
123
121
d .Spec .Template .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {{
124
- Name : "config" ,
125
- MountPath : "/etc/buildkit" ,
122
+ Name : cfg . name ,
123
+ MountPath : path . Join ( "/etc/buildkit" , cfg . path ) ,
126
124
}}
127
125
128
126
d .Spec .Template .Spec .Volumes = []corev1.Volume {{
129
127
Name : "config" ,
130
128
VolumeSource : corev1.VolumeSource {
131
129
ConfigMap : & corev1.ConfigMapVolumeSource {
132
130
LocalObjectReference : corev1.LocalObjectReference {
133
- Name : c .Name ,
131
+ Name : cc .Name ,
134
132
},
135
133
},
136
134
},
137
135
}}
136
+ c = append (c , cc )
138
137
}
139
138
140
139
if opt .Qemu .Install {
@@ -208,3 +207,35 @@ func toRootless(d *appsv1.Deployment) error {
208
207
d .Spec .Template .ObjectMeta .Annotations ["container.seccomp.security.alpha.kubernetes.io/" + containerName ] = "unconfined"
209
208
return nil
210
209
}
210
+
211
+ type config struct {
212
+ name string
213
+ path string
214
+ files map [string ]string
215
+ }
216
+
217
+ func splitConfigFiles (m map [string ][]byte ) []config {
218
+ var c []config
219
+ idx := map [string ]int {}
220
+ nameIdx := 0
221
+ for k , v := range m {
222
+ dir := path .Dir (k )
223
+ i , ok := idx [dir ]
224
+ if ! ok {
225
+ idx [dir ] = len (c )
226
+ i = len (c )
227
+ name := "config"
228
+ if dir != "." {
229
+ nameIdx ++
230
+ name = fmt .Sprintf ("%s-%d" , name , nameIdx )
231
+ }
232
+ c = append (c , config {
233
+ path : dir ,
234
+ name : name ,
235
+ files : map [string ]string {},
236
+ })
237
+ }
238
+ c [i ].files [path .Base (k )] = string (v )
239
+ }
240
+ return c
241
+ }
0 commit comments