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 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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 VolumeClaimTemplate field to Instrumentation spec to enable user-definable ephemeral 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 @@ -162,6 +162,10 @@ type Java struct {
// +optional
Image string `json:"image,omitempty"`

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,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 @@ -196,6 +200,10 @@ type NodeJS struct {
// +optional
Image string `json:"image,omitempty"`

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty"`

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

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty"`

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

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty"`

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

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty"`

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

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,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?

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

// VolumeClaimTemplate defines a ephemeral volume used for auto-instrumentation.
// If omitted, an emptyDir is used with size limit VolumeSizeLimit
VolumeClaimTemplate corev1.PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty"`

// VolumeSizeLimit defines size limit for volume used for auto-instrumentation.
// The default size is 200Mi.
VolumeSizeLimit *resource.Quantity `json:"volumeLimitSize,omitempty"`
Expand Down
38 changes: 38 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 @@ -237,6 +238,36 @@ func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
}

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

warnings = append(warnings, validateExporter(r.Spec.Exporter)...)

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

func validateInstrVolume(volumeClaimTemplate corev1.PersistentVolumeClaimTemplate, volumeSizeLimit *resource.Quantity) error {
if !reflect.ValueOf(volumeClaimTemplate).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
21 changes: 21 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,23 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
},
},
},
{
name: "with volume and volumeSizeLimit",
err: "spec.nodejs.volumeClaimTemplate and spec.nodejs.volumeSizeLimit cannot both be defined",
inst: Instrumentation{
Spec: InstrumentationSpec{
NodeJS: NodeJS{
VolumeClaimTemplate: corev1.PersistentVolumeClaimTemplate{
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
},
},
VolumeSizeLimit: &defaultVolumeSize,
},
},
},
warnings: []string{"sampler type not set"},
},
{
name: "exporter: tls cert set but missing key",
inst: Instrumentation{
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-10-10T15:31:51Z"
createdAt: "2024-10-15T04:21:30Z"
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