Skip to content

Commit 560e389

Browse files
imeliraneliranb
andauthored
DEVOPS-2782-lightrun-agents-helm-chart-add-new-field-of-workload-name (#47)
* Update Lightrun agents configuration to introduce `workloadName` and `workloadType` fields, deprecating `deploymentName`. Enhance README with migration guidance and examples for both Deployments and StatefulSets. Improve validation logic to ensure correct configuration usage. * Fix pr comments --------- Co-authored-by: eliranb <[email protected]>
1 parent b649aa3 commit 560e389

File tree

4 files changed

+105
-17
lines changed

4 files changed

+105
-17
lines changed

charts/lightrun-agents/README.md

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ The values.yaml file includes the following configurable parameters for each Jav
3131
| `javaAgents[].agentPoolCredentials.pinnedCertHash` | 64 character sha256 certificate public key hash for pinning. | Required if `existingSecret` not set |
3232
| `javaAgents[].agentTags` | [List of Lightrun Java Agent tags](https://docs.lightrun.com/jvm/tagging/#manage-lightrun-java-agent-tags). | Optional `[]` (empty list) |
3333
| `javaAgents[].containerSelector` | Selector for containers within the deployment to inject the Lightrun Java Agent. | Required |
34-
| `javaAgents[].deploymentName` | Name of the Kubernetes deployment to attach the Lightrun Java Agent. | Required |
34+
| `javaAgents[].workloadName` | Name of the Kubernetes workload (Deployment or StatefulSet) to attach the Lightrun Java Agent. **Recommended over `deploymentName`**. | Required (if `deploymentName` not used) |
35+
| `javaAgents[].workloadType` | Type of the Kubernetes workload. Must be either `"Deployment"` or `"StatefulSet"`. **Required when using `workloadName`**. | Required (if `workloadName` is used) |
36+
| `javaAgents[].deploymentName` | **[DEPRECATED]** Name of the Kubernetes deployment to attach the Lightrun Java Agent. Use `workloadName` and `workloadType` instead. | Required (if `workloadName` not used) |
3537
| `javaAgents[].initContainer.image` | Image for the Lightrun Java Agent init container. | Required |
3638
| `javaAgents[].initContainer.sharedVolumeMountPath` | Mount path for the shared volume in the init container. | Optional (if not provided, defaults to `"/lightrun"`" |
3739
| `javaAgents[].initContainer.sharedVolumeName` | Name of the shared volume for the init container. | Optional (if not provided, defaults to `"lightrun-agent-init"`" |
@@ -73,19 +75,56 @@ Use the -n flag to specify a namespace, either using the same namespace where yo
7375
helm install <release-name> lightrun-k8s-operator/lightrun-agents -n <namespace> -f values.yaml
7476
```
7577

78+
## Migration from Legacy Configuration
79+
80+
If you are currently using the `deploymentName` field, you should migrate to the new `workloadName` and `workloadType` fields for better clarity and StatefulSet support:
81+
82+
**Legacy Configuration (deprecated):**
83+
```yaml
84+
javaAgents:
85+
- name: 'my-service'
86+
namespace: 'my-namespace'
87+
deploymentName: "my-deployment" # deprecated
88+
# ... other fields
89+
```
90+
91+
**New Configuration (recommended):**
92+
```yaml
93+
javaAgents:
94+
- name: 'my-service'
95+
namespace: 'my-namespace'
96+
workloadName: "my-deployment" # new field
97+
workloadType: "Deployment" # new field (required)
98+
# ... other fields
99+
```
100+
101+
**For StatefulSets:**
102+
```yaml
103+
javaAgents:
104+
- name: 'my-service'
105+
namespace: 'my-namespace'
106+
workloadName: "my-statefulset" # new field
107+
workloadType: "StatefulSet" # new field (required)
108+
# ... other fields
109+
```
110+
111+
> **Note:** You cannot use both `deploymentName` and `workloadName`/`workloadType` in the same configuration. The chart validation will fail if both are specified.
112+
76113
## Examples
77114

78115
### Basic
79116

80-
- The `my-service-1` does not use an `existingSecret` and instead the `agentPoolCredentials.apiKey` and `agentPoolCredentials.pinnedCertHash` are provided directly.
81-
82-
- The `my-service-2` uses an `existingSecret` named `my-existing-secret`
117+
- The `my-service-1` uses the new workload configuration (recommended) for a Deployment and does not use an `existingSecret`
118+
- The `my-service-2` uses the new workload configuration for a StatefulSet and uses an `existingSecret` named `my-existing-secret`
119+
- The `my-service-3` shows the legacy configuration using `deploymentName` (deprecated but still supported)
83120

84121
```yaml
85122
javaAgents:
86123
- name: 'my-service-1'
87124
namespace: 'my-namespace-1'
88-
deploymentName: "my-deployment-1"
125+
# New workload configuration (recommended)
126+
workloadName: "my-deployment-1"
127+
workloadType: "Deployment"
89128
containerSelector:
90129
- my-container-1
91130
serverHostname: 'lightrun.example.com'
@@ -104,7 +143,9 @@ javaAgents:
104143
namespace: 'my-namespace-2'
105144
initContainer:
106145
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
107-
deploymentName: "my-deployment-2"
146+
# StatefulSet configuration
147+
workloadName: "my-statefulset-2"
148+
workloadType: "StatefulSet"
108149
containerSelector:
109150
- my-container-2
110151
serverHostname: 'lightrun.example.com'
@@ -117,19 +158,36 @@ javaAgents:
117158
- service-my-other-server
118159
- region-us_east_1
119160
- provider-aws
161+
- name: 'my-service-3'
162+
namespace: 'my-namespace-3'
163+
# Legacy configuration (deprecated but still supported)
164+
deploymentName: "my-deployment-3"
165+
containerSelector:
166+
- my-container-3
167+
serverHostname: 'lightrun.example.com'
168+
initContainer:
169+
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
170+
agentPoolCredentials:
171+
existingSecret: "my-existing-secret"
172+
apiKey: ""
173+
pinnedCertHash: ""
174+
agentTags:
175+
- env-production
176+
- service-legacy
120177
```
121178
122179
### Full
123180
124-
- The `my-service-1` does not use an `existingSecret` and instead the `agentPoolCredentials.apiKey` and `agentPoolCredentials.pinnedCertHash` are provided directly.
125-
126-
- The `my-service-2` uses an `existingSecret` named `my-existing-secret`
181+
- The `my-service-1` uses the new workload configuration for a Deployment with full configuration options
182+
- The `my-service-2` uses the new workload configuration for a StatefulSet with an `existingSecret`
127183

128184
```yaml
129185
javaAgents:
130186
- name: 'my-service-1'
131187
namespace: 'my-namespace-1'
132-
deploymentName: "my-deployment-1"
188+
# New workload configuration (recommended)
189+
workloadName: "my-deployment-1"
190+
workloadType: "Deployment"
133191
containerSelector:
134192
- my-container-1
135193
serverHostname: 'lightrun.example.com'
@@ -156,7 +214,9 @@ javaAgents:
156214
image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
157215
sharedVolumeName: 'my-shared-volume'
158216
sharedVolumeMountPath: '/mypath'
159-
deploymentName: "my-deployment-2"
217+
# StatefulSet configuration with full options
218+
workloadName: "my-statefulset-2"
219+
workloadType: "StatefulSet"
160220
containerSelector:
161221
- my-container-2
162222
serverHostname: 'lightrun.example.com'

charts/lightrun-agents/templates/_checkConfig.tpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ Compile all warnings into a single message, and call fail.
2222
{{- if not .initContainer.image }}
2323
{{- $objectErrorMsgs = append $objectErrorMsgs "Init Container Image Checker:\n Error: The 'initContainer.image' field is missing. Please provide the 'initContainer.image' parameter." -}}
2424
{{- end }}
25-
{{- if not .deploymentName }}
26-
{{- $objectErrorMsgs = append $objectErrorMsgs "Deployment Name Checker:\n Error: The 'deploymentName' field is missing. Please provide the 'deploymentName' parameter." -}}
25+
26+
{{- /* Workload configuration validation */}}
27+
{{- $hasDeploymentName := .deploymentName }}
28+
{{- $hasWorkloadConfig := and .workloadName .workloadType }}
29+
30+
{{- if and $hasDeploymentName $hasWorkloadConfig }}
31+
{{- $objectErrorMsgs = append $objectErrorMsgs "Workload Configuration Checker:\n Error: Both 'deploymentName' (legacy) and 'workloadName'/'workloadType' (new) are specified. Please use only one configuration method: either 'deploymentName' OR 'workloadName' with 'workloadType'." -}}
32+
{{- else if not (or $hasDeploymentName $hasWorkloadConfig) }}
33+
{{- $objectErrorMsgs = append $objectErrorMsgs "Workload Configuration Checker:\n Error: No workload configuration specified. Please provide either 'deploymentName' (legacy) OR 'workloadName' with 'workloadType' (recommended)." -}}
2734
{{- end }}
35+
2836
{{- if not .containerSelector }}
2937
{{- $objectErrorMsgs = append $objectErrorMsgs "Container Selector Checker:\n Error: The 'containerSelector' field is missing. Please provide the 'containerSelector' parameter." -}}
3038
{{- end }}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ spec:
1010
image: {{ .initContainer.image }}
1111
sharedVolumeName: {{ .initContainer.sharedVolumeName | default "lightrun-agent-init" }}
1212
sharedVolumeMountPath: {{ .initContainer.sharedVolumeMountPath | default "/lightrun" }}
13+
{{- if .workloadName }}
14+
workloadName: {{ .workloadName }}
15+
{{- end }}
16+
{{- if .workloadType }}
17+
workloadType: {{ .workloadType }}
18+
{{- end }}
19+
{{- if .deploymentName }}
1320
deploymentName: {{ .deploymentName }}
21+
{{- end }}
1422
containerSelector: {{- toYaml .containerSelector | nindent 4 }}
1523
{{- if .agentPoolCredentials.existingSecret }}
1624
secretName: {{ .agentPoolCredentials.existingSecret }}

charts/lightrun-agents/values.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ javaAgents: []
1111
#javaAgents:
1212
# - name: 'my-service-1'
1313
# namespace: 'my-namespace-1'
14-
# deploymentName: "my-deployment-1"
14+
# # New workload configuration (recommended)
15+
# workloadName: "my-deployment-1"
16+
# workloadType: "Deployment" # or "StatefulSet"
17+
# # Legacy configuration (deprecated, use workloadName and workloadType instead)
18+
# # deploymentName: "my-deployment-1"
1519
# containerSelector:
1620
# - my-container-1
1721
# serverHostname: 'lightrun.example.com'
@@ -30,7 +34,9 @@ javaAgents: []
3034
# namespace: 'my-namespace-2'
3135
# initContainer:
3236
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
33-
# deploymentName: "my-deployment-2"
37+
# # Example of StatefulSet configuration
38+
# workloadName: "my-statefulset-2"
39+
# workloadType: "StatefulSet"
3440
# containerSelector:
3541
# - my-container-2
3642
# serverHostname: 'lightrun.example.com'
@@ -53,7 +59,11 @@ javaAgents: []
5359
#javaAgents:
5460
# - name: 'my-service-1'
5561
# namespace: 'my-namespace-1'
56-
# deploymentName: "my-deployment-1"
62+
# # New workload configuration (recommended)
63+
# workloadName: "my-deployment-1"
64+
# workloadType: "Deployment" # or "StatefulSet"
65+
# # Legacy configuration (deprecated, use workloadName and workloadType instead)
66+
# # deploymentName: "my-deployment-1"
5767
# containerSelector:
5868
# - my-container-1
5969
# serverHostname: 'lightrun.example.com'
@@ -80,7 +90,9 @@ javaAgents: []
8090
# image: "lightruncom/k8s-operator-init-java-agent-linux:latest"
8191
# sharedVolumeName: 'my-shared-volume'
8292
# sharedVolumeMountPath: '/mypath'
83-
# deploymentName: "my-deployment-2"
93+
# # Example of StatefulSet configuration
94+
# workloadName: "my-statefulset-2"
95+
# workloadType: "StatefulSet"
8496
# containerSelector:
8597
# - my-container-2
8698
# serverHostname: 'lightrun.example.com'

0 commit comments

Comments
 (0)