@@ -99,54 +99,57 @@ func (r *LightrunJavaAgentReconciler) addVolume(deploymentApplyConfig *appsv1ac.
99
99
}
100
100
101
101
func (r * LightrunJavaAgentReconciler ) addInitContainer (deploymentApplyConfig * appsv1ac.DeploymentApplyConfiguration , lightrunJavaAgent * agentv1beta.LightrunJavaAgent , secret * corev1.Secret ) {
102
-
103
- deploymentApplyConfig .Spec .Template .Spec .WithInitContainers (
104
- corev1ac .Container ().
105
- WithName (initContainerName ).
106
- WithImage (lightrunJavaAgent .Spec .InitContainer .Image ).
107
- WithVolumeMounts (
108
- corev1ac .VolumeMount ().WithName (lightrunJavaAgent .Spec .InitContainer .SharedVolumeName ).WithMountPath ("/tmp/" ),
109
- corev1ac .VolumeMount ().WithName (cmVolumeName ).WithMountPath ("/tmp/cm/" ),
110
- ).WithEnv (
111
- corev1ac .EnvVar ().WithName ("LIGHTRUN_KEY" ).WithValueFrom (
112
- corev1ac .EnvVarSource ().WithSecretKeyRef (
113
- corev1ac .SecretKeySelector ().WithName (secret .Name ).WithKey ("lightrun_key" ),
114
- ),
102
+ spec := lightrunJavaAgent .Spec
103
+ isImagePullPolicyConfigured := spec .InitContainer .ImagePullPolicy != ""
104
+ initContainerApplyConfig := corev1ac .Container ().
105
+ WithName (initContainerName ).
106
+ WithImage (spec .InitContainer .Image ).
107
+ WithVolumeMounts (
108
+ corev1ac .VolumeMount ().WithName (spec .InitContainer .SharedVolumeName ).WithMountPath ("/tmp/" ),
109
+ corev1ac .VolumeMount ().WithName (cmVolumeName ).WithMountPath ("/tmp/cm/" ),
110
+ ).WithEnv (
111
+ corev1ac .EnvVar ().WithName ("LIGHTRUN_KEY" ).WithValueFrom (
112
+ corev1ac .EnvVarSource ().WithSecretKeyRef (
113
+ corev1ac .SecretKeySelector ().WithName (secret .Name ).WithKey ("lightrun_key" ),
115
114
),
116
- corev1ac . EnvVar (). WithName ( "PINNED_CERT" ). WithValueFrom (
117
- corev1ac .EnvVarSource ().WithSecretKeyRef (
118
- corev1ac .SecretKeySelector ().WithName ( secret . Name ). WithKey ( "pinned_cert_hash" ),
119
- ),
115
+ ),
116
+ corev1ac .EnvVar ().WithName ( "PINNED_CERT" ). WithValueFrom (
117
+ corev1ac .EnvVarSource ().WithSecretKeyRef (
118
+ corev1ac . SecretKeySelector (). WithName ( secret . Name ). WithKey ( "pinned_cert_hash" ),
120
119
),
121
- corev1ac .EnvVar ().WithName ("LIGHTRUN_SERVER" ).WithValue (lightrunJavaAgent .Spec .ServerHostname ),
122
- ).
123
- WithResources (
124
- corev1ac .ResourceRequirements ().
125
- WithLimits (
126
- corev1.ResourceList {
127
- corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
128
- corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )), // 500 * 10^6 = 500M
129
- },
130
- ).WithRequests (
120
+ ),
121
+ corev1ac .EnvVar ().WithName ("LIGHTRUN_SERVER" ).WithValue (spec .ServerHostname ),
122
+ ).
123
+ WithResources (
124
+ corev1ac .ResourceRequirements ().
125
+ WithLimits (
131
126
corev1.ResourceList {
132
127
corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
133
- corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )),
128
+ corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )), // 500 * 10^6 = 500M
134
129
},
135
- ),
136
- ).
137
- WithSecurityContext (
138
- corev1ac .SecurityContext ().
139
- WithCapabilities (
140
- corev1ac .Capabilities ().WithDrop (corev1 .Capability ("ALL" )),
141
- ).
142
- WithAllowPrivilegeEscalation (false ).
143
- WithRunAsNonRoot (true ).
144
- WithSeccompProfile (
145
- corev1ac .SeccompProfile ().
146
- WithType (corev1 .SeccompProfileTypeRuntimeDefault ),
147
- ),
130
+ ).WithRequests (
131
+ corev1.ResourceList {
132
+ corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
133
+ corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )),
134
+ },
148
135
),
149
- )
136
+ ).
137
+ WithSecurityContext (
138
+ corev1ac .SecurityContext ().
139
+ WithCapabilities (
140
+ corev1ac .Capabilities ().WithDrop (corev1 .Capability ("ALL" )),
141
+ ).
142
+ WithAllowPrivilegeEscalation (false ).
143
+ WithRunAsNonRoot (true ).
144
+ WithSeccompProfile (
145
+ corev1ac .SeccompProfile ().
146
+ WithType (corev1 .SeccompProfileTypeRuntimeDefault ),
147
+ ),
148
+ )
149
+ if isImagePullPolicyConfigured {
150
+ initContainerApplyConfig .WithImagePullPolicy (spec .InitContainer .ImagePullPolicy )
151
+ }
152
+ deploymentApplyConfig .Spec .Template .Spec .WithInitContainers (initContainerApplyConfig )
150
153
}
151
154
152
155
func (r * LightrunJavaAgentReconciler ) patchAppContainers (lightrunJavaAgent * agentv1beta.LightrunJavaAgent , origDeployment * appsv1.Deployment , deploymentApplyConfig * appsv1ac.DeploymentApplyConfiguration ) error {
@@ -275,53 +278,57 @@ func (r *LightrunJavaAgentReconciler) addVolumeToStatefulSet(statefulSetApplyCon
275
278
}
276
279
277
280
func (r * LightrunJavaAgentReconciler ) addInitContainerToStatefulSet (statefulSetApplyConfig * appsv1ac.StatefulSetApplyConfiguration , lightrunJavaAgent * agentv1beta.LightrunJavaAgent , secret * corev1.Secret ) {
278
- statefulSetApplyConfig .Spec . Template . Spec . WithInitContainers (
279
- corev1ac . Container ().
280
- WithName ( initContainerName ).
281
- WithImage ( lightrunJavaAgent . Spec . InitContainer . Image ).
282
- WithVolumeMounts (
283
- corev1ac . VolumeMount (). WithName ( lightrunJavaAgent . Spec . InitContainer . SharedVolumeName ). WithMountPath ( "/tmp/" ),
284
- corev1ac .VolumeMount ().WithName (cmVolumeName ).WithMountPath ("/tmp/cm /" ),
285
- ). WithEnv (
286
- corev1ac . EnvVar (). WithName ( "LIGHTRUN_KEY" ). WithValueFrom (
287
- corev1ac .EnvVarSource ().WithSecretKeyRef (
288
- corev1ac .SecretKeySelector ().WithName ( secret . Name ). WithKey ( "lightrun_key" ),
289
- ),
281
+ spec := lightrunJavaAgent .Spec
282
+ isImagePullPolicyConfigured := spec . InitContainer . ImagePullPolicy != ""
283
+ initContainerApplyConfig := corev1ac . Container ( ).
284
+ WithName ( initContainerName ).
285
+ WithImage ( spec . InitContainer . Image ).
286
+ WithVolumeMounts (
287
+ corev1ac .VolumeMount ().WithName (spec . InitContainer . SharedVolumeName ).WithMountPath ("/tmp/" ),
288
+ corev1ac . VolumeMount (). WithName ( cmVolumeName ). WithMountPath ( "/tmp/cm/" ),
289
+ ). WithEnv (
290
+ corev1ac .EnvVar ().WithName ( "LIGHTRUN_KEY" ). WithValueFrom (
291
+ corev1ac .EnvVarSource ().WithSecretKeyRef (
292
+ corev1ac . SecretKeySelector (). WithName ( secret . Name ). WithKey ( "lightrun_key" ),
290
293
),
291
- corev1ac . EnvVar (). WithName ( "PINNED_CERT" ). WithValueFrom (
292
- corev1ac .EnvVarSource ().WithSecretKeyRef (
293
- corev1ac .SecretKeySelector ().WithName ( secret . Name ). WithKey ( "pinned_cert_hash" ),
294
- ),
294
+ ),
295
+ corev1ac .EnvVar ().WithName ( "PINNED_CERT" ). WithValueFrom (
296
+ corev1ac .EnvVarSource ().WithSecretKeyRef (
297
+ corev1ac . SecretKeySelector (). WithName ( secret . Name ). WithKey ( "pinned_cert_hash" ),
295
298
),
296
- corev1ac .EnvVar ().WithName ("LIGHTRUN_SERVER" ).WithValue (lightrunJavaAgent .Spec .ServerHostname ),
297
- ).
298
- WithResources (
299
- corev1ac .ResourceRequirements ().
300
- WithLimits (
301
- corev1.ResourceList {
302
- corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
303
- corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )), // 64M
304
- },
305
- ).WithRequests (
299
+ ),
300
+ corev1ac .EnvVar ().WithName ("LIGHTRUN_SERVER" ).WithValue (spec .ServerHostname ),
301
+ ).
302
+ WithResources (
303
+ corev1ac .ResourceRequirements ().
304
+ WithLimits (
306
305
corev1.ResourceList {
307
306
corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
308
- corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )),
307
+ corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )), // 64M
309
308
},
310
- ),
311
- ).
312
- WithSecurityContext (
313
- corev1ac .SecurityContext ().
314
- WithCapabilities (
315
- corev1ac .Capabilities ().WithDrop (corev1 .Capability ("ALL" )),
316
- ).
317
- WithAllowPrivilegeEscalation (false ).
318
- WithRunAsNonRoot (true ).
319
- WithSeccompProfile (
320
- corev1ac .SeccompProfile ().
321
- WithType (corev1 .SeccompProfileTypeRuntimeDefault ),
322
- ),
309
+ ).WithRequests (
310
+ corev1.ResourceList {
311
+ corev1 .ResourceCPU : * resource .NewMilliQuantity (int64 (50 ), resource .BinarySI ),
312
+ corev1 .ResourceMemory : * resource .NewScaledQuantity (int64 (64 ), resource .Scale (6 )),
313
+ },
323
314
),
324
- )
315
+ ).
316
+ WithSecurityContext (
317
+ corev1ac .SecurityContext ().
318
+ WithCapabilities (
319
+ corev1ac .Capabilities ().WithDrop (corev1 .Capability ("ALL" )),
320
+ ).
321
+ WithAllowPrivilegeEscalation (false ).
322
+ WithRunAsNonRoot (true ).
323
+ WithSeccompProfile (
324
+ corev1ac .SeccompProfile ().
325
+ WithType (corev1 .SeccompProfileTypeRuntimeDefault ),
326
+ ),
327
+ )
328
+ if isImagePullPolicyConfigured {
329
+ initContainerApplyConfig .WithImagePullPolicy (spec .InitContainer .ImagePullPolicy )
330
+ }
331
+ statefulSetApplyConfig .Spec .Template .Spec .WithInitContainers (initContainerApplyConfig )
325
332
}
326
333
327
334
func (r * LightrunJavaAgentReconciler ) patchStatefulSetAppContainers (lightrunJavaAgent * agentv1beta.LightrunJavaAgent , origStatefulSet * appsv1.StatefulSet , statefulSetApplyConfig * appsv1ac.StatefulSetApplyConfiguration ) error {
0 commit comments