Skip to content

Commit

Permalink
feat: add Spec.Java.Command support
Browse files Browse the repository at this point in the history
custom the InitContainers copy command,eg with config file
  • Loading branch information
lanxenet committed Aug 29, 2023
1 parent 7c5799f commit d6c88b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 4 additions & 1 deletion bundle/manifests/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1570,7 +1573,7 @@ spec:
served: true
storage: true
subresources:
status: {}
status: { }
status:
acceptedNames:
kind: ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/instrumentation/javaagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d6c88b9

Please sign in to comment.