@@ -99,54 +99,57 @@ func (r *LightrunJavaAgentReconciler) addVolume(deploymentApplyConfig *appsv1ac.
9999}
100100
101101func (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" ),
115114 ),
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" ),
120119 ),
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 (
131126 corev1.ResourceList {
132127 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
134129 },
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+ },
148135 ),
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 )
150153}
151154
152155func (r * LightrunJavaAgentReconciler ) patchAppContainers (lightrunJavaAgent * agentv1beta.LightrunJavaAgent , origDeployment * appsv1.Deployment , deploymentApplyConfig * appsv1ac.DeploymentApplyConfiguration ) error {
@@ -275,53 +278,57 @@ func (r *LightrunJavaAgentReconciler) addVolumeToStatefulSet(statefulSetApplyCon
275278}
276279
277280func (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" ),
290293 ),
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" ),
295298 ),
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 (
306305 corev1.ResourceList {
307306 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
309308 },
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+ },
323314 ),
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 )
325332}
326333
327334func (r * LightrunJavaAgentReconciler ) patchStatefulSetAppContainers (lightrunJavaAgent * agentv1beta.LightrunJavaAgent , origStatefulSet * appsv1.StatefulSet , statefulSetApplyConfig * appsv1ac.StatefulSetApplyConfiguration ) error {
0 commit comments