Skip to content

Commit 73a6a82

Browse files
author
Leonid Podolinskiy
authored
agentCliFlags (#3)
* DEVOPS-719 add customAgentPath to CR spec * update crd in example and helm chart * redo customAgentPath to agentCliFlags * add a reference to example app src in docs
1 parent 1d5efb9 commit 73a6a82

12 files changed

+82
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2929
#
3030
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
3131
# lightrun.com/lightrun-k8s-operator-bundle:$VERSION and lightrun.com/lightrun-k8s-operator-catalog:$VERSION.
32-
IMAGE_TAG_BASE ?= lightruncom/lightrun-k8s-operator#TODO: replace with dockerhub
32+
IMAGE_TAG_BASE ?= lightruncom/lightrun-k8s-operator
3333
#IMAGE_TAG_BASE ?= local-registry:5432/lightrun-k8s-operator
3434

3535
# BUNDLE_IMG defines the image:tag used for the bundle.

api/v1beta/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ limitations under the License.
1515
*/
1616

1717
// Package v1beta contains API Schema definitions for the agents v1beta API group
18-
//+kubebuilder:object:generate=true
19-
//+groupName=agents.lightrun.com
18+
// +kubebuilder:object:generate=true
19+
// +groupName=agents.lightrun.com
2020
package v1beta
2121

2222
import (

api/v1beta/lightrunjavaagent_types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ type LightrunJavaAgentSpec struct {
5555
ServerHostname string `json:"serverHostname"`
5656

5757
// Agent configuration to be changed from default values
58+
// https://docs.lightrun.com/jvm/agent-configuration/#setting-agent-properties-from-the-agentconfig-file
5859
// +optional
5960
AgentConfig map[string]string `json:"agentConfig,omitempty"`
6061

62+
// Add cli flags to the agent "-agentpath:/lightrun/agent/lightrun_agent.so=<AgentCliFlags>"
63+
// https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
64+
// +optional
65+
AgentCliFlags string `json:"agentCliFlags,omitempty"`
66+
6167
// Agent tags that will be shown in the portal / IDE plugin
6268
AgentTags []string `json:"agentTags"`
6369

@@ -89,7 +95,7 @@ type LightrunJavaAgent struct {
8995
Status LightrunJavaAgentStatus `json:"status,omitempty"`
9096
}
9197

92-
//+kubebuilder:object:root=true
98+
// +kubebuilder:object:root=true
9399
// LightrunJavaAgentList contains a list of LightrunJavaAgent
94100
type LightrunJavaAgentList struct {
95101
metav1.TypeMeta `json:",inline"`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ spec:
4949
spec:
5050
description: LightrunJavaAgentSpec defines the desired state of LightrunJavaAgent
5151
properties:
52+
agentCliFlags:
53+
description: Add cli flags to the agent "-agentpath:/lightrun/agent/lightrun_agent.so=<AgentCliFlags>"
54+
https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
55+
type: string
5256
agentConfig:
5357
additionalProperties:
5458
type: string
5559
description: Agent configuration to be changed from default values
60+
https://docs.lightrun.com/jvm/agent-configuration/#setting-agent-properties-from-the-agentconfig-file
5661
type: object
5762
agentEnvVarName:
5863
description: Env variable that will be patched with the -agentpath

config/samples/operator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ spec:
5555
spec:
5656
description: LightrunJavaAgentSpec defines the desired state of LightrunJavaAgent
5757
properties:
58+
agentCliFlags:
59+
description: Add cli flags to the agent "-agentpath:/lightrun/agent/lightrun_agent.so=<AgentCliFlags>"
60+
https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
61+
type: string
5862
agentConfig:
5963
additionalProperties:
6064
type: string
6165
description: Agent configuration to be changed from default values
66+
https://docs.lightrun.com/jvm/agent-configuration/#setting-agent-properties-from-the-agentconfig-file
6267
type: object
6368
agentEnvVarName:
6469
description: Env variable that will be patched with the -agentpath

controllers/lightrunjavaagent_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re
144144
break
145145
}
146146
}
147-
r.unpatchJavaToolEnv(&originalDeployment.Spec.Template.Spec.Containers[conIndex], lightrunJavaAgent.Spec.AgentEnvVarName, lightrunJavaAgent.Spec.InitContainer.SharedVolumeMountPath)
147+
r.unpatchJavaToolEnv(&originalDeployment.Spec.Template.Spec.Containers[conIndex], lightrunJavaAgent.Spec.AgentEnvVarName, lightrunJavaAgent.Spec.InitContainer.SharedVolumeMountPath, lightrunJavaAgent.Spec.AgentCliFlags)
148148
}
149149
err = r.Patch(ctx, originalDeployment, clientSidePatch)
150150
if err != nil {
@@ -267,7 +267,7 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re
267267
break
268268
}
269269
}
270-
err = r.patchJavaToolEnv(&originalDeployment.Spec.Template.Spec.Containers[conIndex], lightrunJavaAgent.Spec.AgentEnvVarName, lightrunJavaAgent.Spec.InitContainer.SharedVolumeMountPath)
270+
err = r.patchJavaToolEnv(&originalDeployment.Spec.Template.Spec.Containers[conIndex], lightrunJavaAgent.Spec.AgentEnvVarName, lightrunJavaAgent.Spec.InitContainer.SharedVolumeMountPath, lightrunJavaAgent.Spec.AgentCliFlags)
271271
if err != nil {
272272
log.Error(err, "failed to patch "+lightrunJavaAgent.Spec.AgentEnvVarName)
273273
return r.errorStatus(ctx, lightrunJavaAgent, err)

controllers/lightrunjavaagent_controller_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var _ = Describe("LightrunJavaAgent controller", func() {
3030
agentPlatform = "linux"
3131
initVolumeName = "lightrun-agent-init"
3232
javaEnv = "JAVA_TOOL_OPTIONS"
33+
defaultAgentPath = "-agentpath:/lightrun/agent/lightrun_agent.so"
34+
agentCliFlags = "--lightrun_extra_class_path=<PATH_TO_JAR>"
3335
)
3436
var containerSelector = []string{"app", "app2"}
3537
var agentConfig map[string]string = map[string]string{"max_log_cpu_cost": "2"}
@@ -91,6 +93,7 @@ var _ = Describe("LightrunJavaAgent controller", func() {
9193
AgentName: agentName,
9294
AgentTags: agentTags,
9395
AgentConfig: agentConfig,
96+
AgentCliFlags: agentCliFlags,
9497
AgentEnvVarName: javaEnv,
9598
ContainerSelector: containerSelector,
9699
InitContainer: agentsv1beta.InitContainer{
@@ -198,7 +201,7 @@ var _ = Describe("LightrunJavaAgent controller", func() {
198201
}).Should(BeTrue())
199202
})
200203

201-
It("Should patch Env Vars of containers", func() {
204+
It("Should patch Env Vars of containers with agentCliFlags value", func() {
202205
Eventually(func() bool {
203206
if err := k8sClient.Get(ctx, deplRequest, &patchedDepl); err != nil {
204207
return false
@@ -207,13 +210,11 @@ var _ = Describe("LightrunJavaAgent controller", func() {
207210
for _, envVar := range container.Env {
208211
if envVar.Name == javaEnv {
209212
if container.Name == "app" {
210-
if envVar.Value != "-agentpath:/lightrun/agent/lightrun_agent.so" {
211-
//logger.Info("first container", envVar.Name, envVar.Value)
213+
if envVar.Value != defaultAgentPath+"="+agentCliFlags {
212214
return false
213215
}
214216
} else if container.Name == "app2" {
215-
if envVar.Value != "-Djava.net.preferIPv4Stack=true -agentpath:/lightrun/agent/lightrun_agent.so" {
216-
//logger.Info("second container", envVar.Name, envVar.Value)
217+
if envVar.Value != "-Djava.net.preferIPv4Stack=true "+defaultAgentPath+"="+agentCliFlags {
217218
return false
218219
}
219220
}
@@ -481,6 +482,30 @@ var _ = Describe("LightrunJavaAgent controller", func() {
481482
}).Should(BeTrue())
482483
})
483484

485+
It("Should patch Env Vars of containers with default agent path", func() {
486+
Eventually(func() bool {
487+
if err := k8sClient.Get(ctx, deplRequest2, &patchedDepl2); err != nil {
488+
return false
489+
}
490+
for _, container := range patchedDepl2.Spec.Template.Spec.Containers {
491+
for _, envVar := range container.Env {
492+
if envVar.Name == javaEnv {
493+
if container.Name == "app" {
494+
if envVar.Value != defaultAgentPath {
495+
return false
496+
}
497+
} else if container.Name == "app2" {
498+
if envVar.Value != "-Djava.net.preferIPv4Stack=true "+defaultAgentPath {
499+
return false
500+
}
501+
}
502+
}
503+
}
504+
}
505+
return true
506+
}).Should(BeTrue())
507+
})
508+
484509
It("Should delete deployment", func() {
485510
depl := appsv1.Deployment{
486511
ObjectMeta: metav1.ObjectMeta{

controllers/patch_funcs.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ func (r *LightrunJavaAgentReconciler) patchAppContainers(lightrunJavaAgent *agen
158158
}
159159

160160
// Client side patch, as we can't update value from 2 sources
161-
func (r *LightrunJavaAgentReconciler) patchJavaToolEnv(container *corev1.Container, targetEnvVar string, mountPath string) error {
161+
func (r *LightrunJavaAgentReconciler) patchJavaToolEnv(container *corev1.Container, targetEnvVar string, mountPath string, agentCliFlags string) error {
162162
agentArg := "-agentpath:" + mountPath + "/agent/lightrun_agent.so"
163+
if agentCliFlags != "" {
164+
agentArg += "=" + agentCliFlags
165+
}
163166

164167
javaToolOptionsIndex := -1
165168

@@ -186,8 +189,12 @@ func (r *LightrunJavaAgentReconciler) patchJavaToolEnv(container *corev1.Contain
186189
return nil
187190
}
188191

189-
func (r *LightrunJavaAgentReconciler) unpatchJavaToolEnv(container *corev1.Container, targetEnvVar string, mountPath string) *corev1.Container {
192+
func (r *LightrunJavaAgentReconciler) unpatchJavaToolEnv(container *corev1.Container, targetEnvVar string, mountPath string, agentCliFlags string) *corev1.Container {
190193
agentArg := "-agentpath:" + mountPath + "/agent/lightrun_agent.so"
194+
if agentCliFlags != "" {
195+
agentArg += "=" + agentCliFlags
196+
}
197+
191198
var updatedSlice []corev1.EnvVar
192199
for _, envVar := range container.Env {
193200
if envVar.Name == targetEnvVar {

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ kubectl create namespace lightrun-agent-test
5252
kubectl apply -f https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/operator.yaml -n lightrun-operator
5353
```
5454

55-
3. Create simple deployment for test
55+
3. Create simple deployment for test
56+
> _App source code [PrimeMain.java](../examples/app/PrimeMain.java)_
5657
```sh
5758
kubectl apply -f https://raw.githubusercontent.com/lightrun-platform/lightrun-k8s-operator/main/examples/deployment.yaml -n lightrun-agent-test
5859
```

examples/lightrunjavaagent.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
# platform - `linux/alpine`
1010
# agent version - first part of the tag (1.7.0)
1111
# init container sub-version - last part of the tag (init.0)
12-
image: "lightruncom/k8s-operator-init-java-agent-linux:1.7.0-init.0"
12+
image: "lightruncom/k8s-operator-init-java-agent-linux:1.8.3-init.0"
1313
# Volume name in case you have some convention in the names
1414
sharedVolumeName: lightrun-agent-init
1515
# Mount path where volume will be parked. Various distributions may have it's limitations.
@@ -34,11 +34,18 @@ spec:
3434
# You can find list of available options here https://docs.lightrun.com/jvm/agent-configuration/
3535
agentConfig:
3636
max_log_cpu_cost: "2"
37+
38+
# agentCliFlags is used if need to pass additional flags to the agent,
39+
# that are not part of configuration file.
40+
# https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
41+
# Example below
42+
# agentCliFlags: --lightrun_extra_class_path=<PATH_TO_JAR>:<PATH_TO_JAR>,lightrun_init_wait_time_ms
43+
3744
# Tags that agent will be using. You'll see them in the UI and in the IDE plugin as well
3845
agentTags:
3946
- operator
4047
- example
41-
- 1.7.0
48+
- 1.8.3
4249
# Agent name. If not provided, pod name will be used
4350
#agentName: "operator-test-agent"
4451
# List of container names inside the pod of the deployment

examples/operator.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ spec:
5050
spec:
5151
description: LightrunJavaAgentSpec defines the desired state of LightrunJavaAgent
5252
properties:
53+
agentCliFlags:
54+
description: Add cli flags to the agent "-agentpath:/lightrun/agent/lightrun_agent.so=<AgentCliFlags>"
55+
https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
56+
type: string
5357
agentConfig:
5458
additionalProperties:
5559
type: string
5660
description: Agent configuration to be changed from default values
61+
https://docs.lightrun.com/jvm/agent-configuration/#setting-agent-properties-from-the-agentconfig-file
5762
type: object
5863
agentEnvVarName:
5964
description: Env variable that will be patched with the -agentpath

helm-chart/crds/lightrunjavaagent_crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ spec:
4848
spec:
4949
description: LightrunJavaAgentSpec defines the desired state of LightrunJavaAgent
5050
properties:
51+
agentCliFlags:
52+
description: Add cli flags to the agent "-agentpath:/lightrun/agent/lightrun_agent.so=<AgentCliFlags>"
53+
https://docs.lightrun.com/jvm/agent-configuration/#additional-command-line-flags
54+
type: string
5155
agentConfig:
5256
additionalProperties:
5357
type: string
5458
description: Agent configuration to be changed from default values
59+
https://docs.lightrun.com/jvm/agent-configuration/#setting-agent-properties-from-the-agentconfig-file
5560
type: object
5661
agentEnvVarName:
5762
description: Env variable that will be patched with the -agentpath

0 commit comments

Comments
 (0)