Skip to content

Commit 1703d3c

Browse files
author
eliranb
committed
Add imagePullPolicy to InitContainer configuration
- Introduced `imagePullPolicy` field to the InitContainer struct in lightrunjavaagent_types.go. - Updated deepcopy functions to handle the new imagePullPolicy field. - Modified Helm chart templates and values.yaml to support imagePullPolicy configuration. - Enhanced documentation to include imagePullPolicy details for better user guidance. - Updated CRD to reflect the new imagePullPolicy field for LightrunJavaAgent.
1 parent b5205fe commit 1703d3c

File tree

8 files changed

+73
-44
lines changed

8 files changed

+73
-44
lines changed

api/v1beta/lightrunjavaagent_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -30,6 +31,8 @@ type InitContainer struct {
3031
SharedVolumeMountPath string `json:"sharedVolumeMountPath"`
3132
// Image of the init container. Image name and tag will define platform and version of the agent
3233
Image string `json:"image"`
34+
// Pull policy for the init container. Can be one of: Always, IfNotPresent, or Never.
35+
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
3336
}
3437

3538
// LightrunJavaAgentSpec defines the desired state of LightrunJavaAgent

api/v1beta/zz_generated.deepcopy.go

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/lightrun-agents/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The values.yaml file includes the following configurable parameters for each Jav
3333
| `javaAgents[].containerSelector` | Selector for containers within the deployment to inject the Lightrun Java Agent. | Required |
3434
| `javaAgents[].deploymentName` | Name of the Kubernetes deployment to attach the Lightrun Java Agent. | Required |
3535
| `javaAgents[].initContainer.image` | Image for the Lightrun Java Agent init container. | Required |
36+
| `javaAgents[].initContainer.imagePullPolicy` | Image pull policy for the init container. Can be one of: Always, IfNotPresent, or Never. | Optional (if not provided, defaults to `"IfNotPresent"`) |
3637
| `javaAgents[].initContainer.sharedVolumeMountPath` | Mount path for the shared volume in the init container. | Optional (if not provided, defaults to `"/lightrun"`" |
3738
| `javaAgents[].initContainer.sharedVolumeName` | Name of the shared volume for the init container. | Optional (if not provided, defaults to `"lightrun-agent-init"`" |
3839
| `javaAgents[].name` | Name of the Lightrun Java Agent custom resource. | Required |
@@ -91,6 +92,7 @@ javaAgents:
9192
serverHostname: 'lightrun.example.com'
9293
initContainer:
9394
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
95+
imagePullPolicy: "IfNotPresent"
9496
agentPoolCredentials:
9597
existingSecret: ""
9698
apiKey: "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@ -104,6 +106,7 @@ javaAgents:
104106
namespace: 'my-namespace-2'
105107
initContainer:
106108
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
109+
imagePullPolicy: "IfNotPresent"
107110
deploymentName: "my-deployment-2"
108111
containerSelector:
109112
- my-container-2
@@ -139,6 +142,7 @@ javaAgents:
139142
agentCliFlags: "--lightrun_extra_class_path=<PATH_TO_JAR>:<PATH_TO_JAR>,lightrun_init_wait_time_ms"
140143
initContainer:
141144
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
145+
imagePullPolicy: "IfNotPresent"
142146
sharedVolumeName: 'my-shared-volume'
143147
sharedVolumeMountPath: '/mypath'
144148
agentPoolCredentials:
@@ -154,6 +158,7 @@ javaAgents:
154158
namespace: 'my-namespace-2'
155159
initContainer:
156160
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
161+
imagePullPolicy: "IfNotPresent"
157162
sharedVolumeName: 'my-shared-volume'
158163
sharedVolumeMountPath: '/mypath'
159164
deploymentName: "my-deployment-2"

charts/lightrun-agents/templates/java-agent-cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ metadata:
88
spec:
99
initContainer:
1010
image: {{ .initContainer.image }}
11+
imagePullPolicy: {{ .initContainer.imagePullPolicy | default "IfNotPresent" }}
1112
sharedVolumeName: {{ .initContainer.sharedVolumeName | default "lightrun-agent-init" }}
1213
sharedVolumeMountPath: {{ .initContainer.sharedVolumeMountPath | default "/lightrun" }}
1314
deploymentName: {{ .deploymentName }}

charts/lightrun-agents/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ javaAgents: []
1717
# serverHostname: 'lightrun.example.com'
1818
# initContainer:
1919
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
20+
# imagePullPolicy: "IfNotPresent"
2021
# agentPoolCredentials:
2122
# existingSecret: ""
2223
# apiKey: "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@@ -30,6 +31,7 @@ javaAgents: []
3031
# namespace: 'my-namespace-2'
3132
# initContainer:
3233
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
34+
# imagePullPolicy: "IfNotPresent"
3335
# deploymentName: "my-deployment-2"
3436
# containerSelector:
3537
# - my-container-2
@@ -63,6 +65,7 @@ javaAgents: []
6365
# agentCliFlags: "--lightrun_extra_class_path=<PATH_TO_JAR>:<PATH_TO_JAR>,lightrun_init_wait_time_ms"
6466
# initContainer:
6567
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
68+
# imagePullPolicy: "IfNotPresent"
6669
# sharedVolumeName: 'my-shared-volume'
6770
# sharedVolumeMountPath: '/mypath'
6871
# agentPoolCredentials:
@@ -78,6 +81,7 @@ javaAgents: []
7881
# namespace: 'my-namespace-2'
7982
# initContainer:
8083
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
84+
# imagePullPolicy: "IfNotPresent"
8185
# sharedVolumeName: 'my-shared-volume'
8286
# sharedVolumeMountPath: '/mypath'
8387
# deploymentName: "my-deployment-2"

config/crd/bases/agents.lightrun.com_lightrunjavaagents.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ spec:
9494
description: Image of the init container. Image name and tag will
9595
define platform and version of the agent
9696
type: string
97+
imagePullPolicy:
98+
description: Pull policy for the init container
99+
type: string
97100
sharedVolumeMountPath:
98101
description: Path in the app container where volume with agent
99102
will be mounted

docs/custom_resource.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ spec:
1616
# Mount path where volume will be parked. Various distributions may have it's limitations.
1717
# For example you can't mount volumes to any path except `/tmp` when using AWS Fargate
1818
sharedVolumeMountPath: "/lightrun"
19+
# imagePullPolicy for the init container. Can be one of: Always, IfNotPresent, or Never.
20+
imagePullPolicy: "IfNotPresent"
1921
# Name of the deployment that you are going to patch.
2022
# Has to be in the same namespace
2123
deploymentName: app

internal/controller/patch_funcs.go

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -100,53 +100,58 @@ func (r *LightrunJavaAgentReconciler) addVolume(deploymentApplyConfig *appsv1ac.
100100

101101
func (r *LightrunJavaAgentReconciler) addInitContainer(deploymentApplyConfig *appsv1ac.DeploymentApplyConfiguration, lightrunJavaAgent *agentv1beta.LightrunJavaAgent, secret *corev1.Secret) {
102102

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-
),
103+
// deploymentApplyConfig.Spec.Template.Spec.WithInitContainers(
104+
icac := 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"),
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(lightrunJavaAgent.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+
150+
if lightrunJavaAgent.Spec.InitContainer.ImagePullPolicy != nil {
151+
icac.WithImagePullPolicy(*lightrunJavaAgent.Spec.InitContainer.ImagePullPolicy)
152+
}
153+
154+
deploymentApplyConfig.Spec.Template.Spec.WithInitContainers(icac)
150155
}
151156

152157
func (r *LightrunJavaAgentReconciler) patchAppContainers(lightrunJavaAgent *agentv1beta.LightrunJavaAgent, origDeployment *appsv1.Deployment, deploymentApplyConfig *appsv1ac.DeploymentApplyConfiguration) error {

0 commit comments

Comments
 (0)