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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions .chloggen/3267-custom-instr-vol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds Volume field to Instrumentation spec to enable user-definable volumes for auto-instrumentation.

# One or more tracking issues related to the change
issues: [3267]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
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"`
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
39 changes: 39 additions & 0 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v1alpha1
import (
"context"
"fmt"
"reflect"
"strconv"
"strings"

Expand Down Expand Up @@ -236,6 +237,37 @@ func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings
default:
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
}

var err error
err = validateInstrVolume(r.Spec.ApacheHttpd.Volume, r.Spec.ApacheHttpd.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.apachehttpd.volume and spec.apachehttpd.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.DotNet.Volume, r.Spec.DotNet.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.dotnet.volume and spec.dotnet.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.Go.Volume, r.Spec.Go.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.go.volume and spec.go.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.Java.Volume, r.Spec.Java.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.java.volume and spec.java.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.Nginx.Volume, r.Spec.Nginx.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.nginx.volume and spec.nginx.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.NodeJS.Volume, r.Spec.NodeJS.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.nodejs.volume and spec.nodejs.volumeSizeLimit cannot both be defined: %w", err)
}
err = validateInstrVolume(r.Spec.Python.Volume, r.Spec.Python.VolumeSizeLimit)
if err != nil {
return warnings, fmt.Errorf("spec.python.volume and spec.python.volumeSizeLimit cannot both be defined: %w", err)
}

return warnings, nil
}

Expand Down Expand Up @@ -270,6 +302,13 @@ func validateJaegerRemoteSamplerArgument(argument string) error {
return nil
}

func validateInstrVolume(volume corev1.Volume, volumeSizeLimit *resource.Quantity) error {
if !reflect.ValueOf(volume).IsZero() && volumeSizeLimit != nil {
return fmt.Errorf("unable to resolve volume size")
}
return nil
}

func NewInstrumentationWebhook(logger logr.Logger, scheme *runtime.Scheme, cfg config.Config) *InstrumentationWebhook {
return &InstrumentationWebhook{
logger: logger,
Expand Down
19 changes: 19 additions & 0 deletions apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/open-telemetry/opentelemetry-operator/internal/config"
)

var defaultVolumeSize = resource.MustParse("200Mi")

func TestInstrumentationDefaultingWebhook(t *testing.T) {
inst := &Instrumentation{}
err := InstrumentationWebhook{
Expand Down Expand Up @@ -113,6 +117,21 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
},
},
},
{
name: "with volume and volumeSizeLimit",
err: "spec.nodejs.volume and spec.nodejs.volumeSizeLimit cannot both be defined",
inst: Instrumentation{
Spec: InstrumentationSpec{
NodeJS: NodeJS{
Volume: corev1.Volume{
Name: "vol1",
},
VolumeSizeLimit: &defaultVolumeSize,
},
},
},
warnings: []string{"sampler type not set"},
},
}

for _, test := range tests {
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.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-09-05T15:16:50Z"
createdAt: "2024-09-13T05:53:46Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Loading
Loading