diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 101d99f40b..32d7b8ac57 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -119,6 +119,10 @@ type Java struct { // +optional Image string `json:"image,omitempty"` + // Command defines the command to copy the auto-instrumentation JAR. + // +optional + Command []string `json:"command,omitempty"` + // Env defines java specific env vars. There are four layers for env vars' definitions and // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. // If the former var had been defined, then the other vars would be ignored. diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index 234784dd15..091f1ea26d 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -77,6 +77,10 @@ func (r *Instrumentation) Default() { r.Spec.Java.Image = val } } + if len(r.Spec.Java.Command) == 0 { + r.Spec.Java.Command = []string{"cp", "/javaagent.jar", "/otel-auto-instrumentation/javaagent.jar"} + } + if r.Spec.Java.Resources.Limits == nil { r.Spec.Java.Resources.Limits = corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index 817eacb1ec..ea53ce59f5 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -871,6 +871,9 @@ spec: description: Image is a container image with javaagent auto-instrumentation JAR. type: string + command: + description: Command is a command to run in the container. + type: string resources: description: Resources describes the compute resource requirements. properties: @@ -1570,7 +1573,7 @@ spec: served: true storage: true subresources: - status: {} + status: { } status: acceptedNames: kind: "" diff --git a/pkg/instrumentation/javaagent.go b/pkg/instrumentation/javaagent.go index 9c3ba12386..c1ca37504d 100644 --- a/pkg/instrumentation/javaagent.go +++ b/pkg/instrumentation/javaagent.go @@ -68,7 +68,7 @@ func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1. pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ Name: initContainerName, Image: javaSpec.Image, - Command: []string{"cp", "/javaagent.jar", "/otel-auto-instrumentation/javaagent.jar"}, + Command: javaSpec.Command, Resources: javaSpec.Resources, VolumeMounts: []corev1.VolumeMount{{ Name: volumeName,