@@ -19,9 +19,17 @@ const BuildKitContainer = "buildkitd"
19
19
20
20
func (r * LocalRegistry ) ensureDeployment (ctx devspacecontext.Context ) (* appsv1.Deployment , error ) {
21
21
// Switching from a persistent registry, delete the statefulset.
22
- _ , err := ctx .KubeClient ().KubeClient ().AppsV1 ().StatefulSets (r .Namespace ).Get (ctx .Context (), r .Name , metav1.GetOptions {})
22
+ _ , err := ctx .KubeClient ().
23
+ KubeClient ().
24
+ AppsV1 ().
25
+ StatefulSets (r .Namespace ).
26
+ Get (ctx .Context (), r .Name , metav1.GetOptions {})
23
27
if err == nil {
24
- err := ctx .KubeClient ().KubeClient ().AppsV1 ().StatefulSets (r .Namespace ).Delete (ctx .Context (), r .Name , metav1.DeleteOptions {})
28
+ err := ctx .KubeClient ().
29
+ KubeClient ().
30
+ AppsV1 ().
31
+ StatefulSets (r .Namespace ).
32
+ Delete (ctx .Context (), r .Name , metav1.DeleteOptions {})
25
33
if err != nil && kerrors .IsNotFound (err ) {
26
34
return nil , err
27
35
}
@@ -31,29 +39,41 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
31
39
var existing * appsv1.Deployment
32
40
desired := r .getDeployment ()
33
41
kubeClient := ctx .KubeClient ()
34
- err = wait .PollUntilContextTimeout (ctx . Context (), time . Second , 30 * time . Second , true , func ( ctx context. Context ) ( bool , error ) {
35
- var err error
36
-
37
- existing , err = kubeClient . KubeClient (). AppsV1 (). Deployments ( r . Namespace ). Get ( ctx , r . Name , metav1. GetOptions {})
38
- if err == nil {
39
- return true , nil
40
- }
42
+ err = wait .PollUntilContextTimeout (
43
+ ctx . Context (),
44
+ time . Second ,
45
+ 30 * time . Second ,
46
+ true ,
47
+ func ( ctx context. Context ) ( bool , error ) {
48
+ var err error
41
49
42
- if kerrors .IsNotFound (err ) {
43
- existing , err = kubeClient .KubeClient ().AppsV1 ().Deployments (r .Namespace ).Create (ctx , desired , metav1.CreateOptions {})
50
+ existing , err = kubeClient .KubeClient ().
51
+ AppsV1 ().
52
+ Deployments (r .Namespace ).
53
+ Get (ctx , r .Name , metav1.GetOptions {})
44
54
if err == nil {
45
55
return true , nil
46
56
}
47
57
48
- if kerrors .IsAlreadyExists (err ) {
49
- return false , nil
58
+ if kerrors .IsNotFound (err ) {
59
+ existing , err = kubeClient .KubeClient ().
60
+ AppsV1 ().
61
+ Deployments (r .Namespace ).
62
+ Create (ctx , desired , metav1.CreateOptions {})
63
+ if err == nil {
64
+ return true , nil
65
+ }
66
+
67
+ if kerrors .IsAlreadyExists (err ) {
68
+ return false , nil
69
+ }
70
+
71
+ return false , err
50
72
}
51
73
52
74
return false , err
53
- }
54
-
55
- return false , err
56
- })
75
+ },
76
+ )
57
77
if err != nil {
58
78
return nil , err
59
79
}
@@ -72,7 +92,8 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
72
92
},
73
93
)
74
94
if kerrors .IsUnsupportedMediaType (err ) {
75
- ctx .Log ().Debugf ("Server-side apply not available on the server for localRegistry deployment: (%v)" , err )
95
+ ctx .Log ().
96
+ Debugf ("Server-side apply not available on the server for localRegistry deployment: (%v)" , err )
76
97
// Unsupport server-side apply, we use existing or created deployment
77
98
return existing , nil
78
99
}
@@ -96,11 +117,18 @@ func (r *LocalRegistry) getDeployment() *appsv1.Deployment {
96
117
Labels : map [string ]string {
97
118
"app" : r .Name ,
98
119
},
99
- Annotations : getAnnotations (r .LocalBuild ),
120
+ Annotations : getAnnotations (r .LocalBuild , r . Annotations ),
100
121
},
101
122
Spec : corev1.PodSpec {
102
123
EnableServiceLinks : new (bool ),
103
- Containers : getContainers (r .RegistryImage , r .BuildKitImage , "registry" , int32 (r .Port ), r .LocalBuild ),
124
+ Containers : getContainers (
125
+ r .RegistryImage ,
126
+ r .BuildKitImage ,
127
+ "registry" ,
128
+ int32 (r .Port ),
129
+ r .LocalBuild ,
130
+ r .Resources ,
131
+ ),
104
132
Volumes : []corev1.Volume {
105
133
{
106
134
VolumeSource : corev1.VolumeSource {
@@ -121,24 +149,42 @@ func (r *LocalRegistry) getDeployment() *appsv1.Deployment {
121
149
}
122
150
}
123
151
124
- func getAnnotations (localbuild bool ) map [string ]string {
125
- if ! localbuild {
126
- return map [string ]string {
152
+ func getAnnotations (isLocalbuild bool , annotations map [ string ] string ) map [string ]string {
153
+ if ! isLocalbuild {
154
+ combined := map [string ]string {
127
155
"container.apparmor.security.beta.kubernetes.io/buildkitd" : "unconfined" ,
128
156
}
157
+
158
+ for k , v := range annotations {
159
+ combined [k ] = v
160
+ }
161
+
162
+ return combined
129
163
}
130
- return map [string ]string {}
164
+
165
+ return annotations
131
166
}
132
167
133
168
// this returns a different deployment, if we're using a local docker build or not.
134
- func getContainers (registryImage , buildKitImage , volume string , port int32 , localbuild bool ) []corev1.Container {
135
- buildContainers := getRegistryContainers (registryImage , volume , port )
169
+ func getContainers (
170
+ registryImage , buildKitImage , volume string ,
171
+ port int32 ,
172
+ localbuild bool ,
173
+ registryResources * corev1.ResourceRequirements ,
174
+ ) []corev1.Container {
175
+ buildContainers := getRegistryContainers (registryImage , volume , port , registryResources )
136
176
if localbuild {
137
177
// in case we're using local builds just return the deployment with only the
138
178
// registry container inside
139
179
return buildContainers
140
180
}
141
181
182
+ resources := corev1.ResourceRequirements {}
183
+
184
+ if registryResources != nil {
185
+ resources = * registryResources
186
+ }
187
+
142
188
buildKitContainer := []corev1.Container {
143
189
{
144
190
Name : BuildKitContainer ,
@@ -185,6 +231,7 @@ func getContainers(registryImage, buildKitImage, volume string, port int32, loca
185
231
MountPath : "/home/user/.local/share/buildkit" ,
186
232
},
187
233
},
234
+ Resources : resources ,
188
235
},
189
236
}
190
237
@@ -193,7 +240,18 @@ func getContainers(registryImage, buildKitImage, volume string, port int32, loca
193
240
return append (buildKitContainer , buildContainers ... )
194
241
}
195
242
196
- func getRegistryContainers (registryImage , volume string , port int32 ) []corev1.Container {
243
+ func getRegistryContainers (
244
+ registryImage , volume string ,
245
+ port int32 ,
246
+ registryResources * corev1.ResourceRequirements ,
247
+ ) []corev1.Container {
248
+
249
+ resources := corev1.ResourceRequirements {}
250
+
251
+ if registryResources != nil {
252
+ resources = * registryResources
253
+ }
254
+
197
255
return []corev1.Container {
198
256
{
199
257
Name : "registry" ,
@@ -240,6 +298,7 @@ func getRegistryContainers(registryImage, volume string, port int32) []corev1.Co
240
298
MountPath : "/var/lib/registry" ,
241
299
},
242
300
},
301
+ Resources : resources ,
243
302
},
244
303
}
245
304
}
0 commit comments