Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user-specified instrumentation volume #3285

Merged
merged 23 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ type Java struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand Down Expand Up @@ -154,6 +158,10 @@ type NodeJS struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand All @@ -175,6 +183,10 @@ type Python struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand All @@ -196,6 +208,10 @@ type DotNet struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand All @@ -215,6 +231,10 @@ type Go struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand All @@ -236,6 +256,10 @@ type ApacheHttpd struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just deprecate this in favor of the volume claim template?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open a separate issue for that, I don't think it should be within the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand Down Expand Up @@ -272,6 +296,10 @@ type Nginx struct {
// +optional
Image string `json:"image,omitempty"`

// Volume defines the volume used for auto-instrumentation.
// The default volume is an emptyDir with size limit VolumeSizeLimit
Volume corev1.Volume `json:"volume,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Apache HTTPD server version. One of 2.4 or 2.2. Default is 2.4<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -926,6 +933,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -1636,6 +1650,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -2054,6 +2075,13 @@ All extensions are copied to a single directory; if a JAR with the same name exi
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -2515,6 +2543,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -3195,6 +3230,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down Expand Up @@ -3605,6 +3647,13 @@ If the former var had been defined, then the other vars would be ignored.<br/>
Resources describes the compute resource requirements.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volume</b></td>
<td>[Volume](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#volume-v1-core)</td>
<td>
Volume defines the volume used for auto-instrumentation. Cannot be used with <b>volumeLimitSize</b>.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>volumeLimitSize</b></td>
<td>int or string</td>
Expand Down
11 changes: 3 additions & 8 deletions pkg/instrumentation/apachehttpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func injectApacheHttpdagent(_ logr.Logger, apacheSpec v1alpha1.ApacheHttpd, pod
// caller checks if there is at least one container
container := &pod.Spec.Containers[index]

volume, _ := instrVolume(apacheSpec.Volume, apacheAgentVolume, apacheSpec.VolumeSizeLimit)

// inject env vars
for _, env := range apacheSpec.Env {
idx := getIndexOfEnv(container.Env, env.Name)
Expand Down Expand Up @@ -135,14 +137,7 @@ func injectApacheHttpdagent(_ logr.Logger, apacheSpec v1alpha1.ApacheHttpd, pod
// Copy OTEL module to a shared volume
if isApacheInitContainerMissing(pod, apacheAgentInitContainerName) {
// Inject volume for agent
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
Name: apacheAgentVolume,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: volumeSize(apacheSpec.VolumeSizeLimit),
},
}})

pod.Spec.Volumes = append(pod.Spec.Volumes, volume)
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{
Name: apacheAgentInitContainerName,
Image: apacheSpec.Image,
Expand Down
18 changes: 8 additions & 10 deletions pkg/instrumentation/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt
return pod, err
}

volume, err := instrVolume(dotNetSpec.Volume, dotnetVolumeName, dotNetSpec.VolumeSizeLimit)
if err != nil {
return pod, err
}

// check if OTEL_DOTNET_AUTO_HOME env var is already set in the container
// if it is already set, then we assume that .NET Auto-instrumentation is already configured for this container
if getIndexOfEnv(container.Env, envDotNetOTelAutoHome) > -1 {
Expand Down Expand Up @@ -110,27 +115,20 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt
setDotNetEnvVar(container, envDotNetSharedStore, dotNetSharedStorePath, concatEnvValues)

container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: dotnetVolumeName,
Name: volume.Name,
MountPath: dotnetInstrMountPath,
})

// We just inject Volumes and init containers for the first processed container.
if isInitContainerMissing(pod, dotnetInitContainerName) {
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
Name: dotnetVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: volumeSize(dotNetSpec.VolumeSizeLimit),
},
}})

pod.Spec.Volumes = append(pod.Spec.Volumes, volume)
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{
Name: dotnetInitContainerName,
Image: dotNetSpec.Image,
Command: []string{"cp", "-r", "/autoinstrumentation/.", dotnetInstrMountPath},
Resources: dotNetSpec.Resources,
VolumeMounts: []corev1.VolumeMount{{
Name: dotnetVolumeName,
Name: volume.Name,
MountPath: dotnetInstrMountPath,
}},
})
Expand Down
17 changes: 17 additions & 0 deletions pkg/instrumentation/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package instrumentation

import (
"fmt"
"reflect"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -123,6 +124,22 @@ func isInstrWithoutContainers(inst instrumentationWithContainers) int {
return 0
}

func instrVolume(volume corev1.Volume, name string, volumeSizeLimit *resource.Quantity) (corev1.Volume, error) {
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
if !reflect.ValueOf(volume).IsZero() && volumeSizeLimit != nil {
return volume, fmt.Errorf("both Volume and VolumeSizeLimit cannot be defined simultaneously")
} else if !reflect.ValueOf(volume).IsZero() {
return volume, nil
}
swiatekm marked this conversation as resolved.
Show resolved Hide resolved

return corev1.Volume{
Name: name,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: volumeSize(volumeSizeLimit),
},
}}, nil
}

func volumeSize(quantity *resource.Quantity) *resource.Quantity {
if quantity == nil {
return &defaultSize
Expand Down
Loading
Loading