Skip to content
Closed
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
27 changes: 16 additions & 11 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/open-telemetry/opentelemetry-operator/internal/config"
"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types"
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
)

Expand Down Expand Up @@ -47,38 +48,38 @@
}

func (w InstrumentationWebhook) Default(_ context.Context, obj runtime.Object) error {
instrumentation, ok := obj.(*Instrumentation)
instrumentation, ok := obj.(*types.Instrumentation)
if !ok {
return fmt.Errorf("expected an Instrumentation, received %T", obj)
}
return w.defaulter(instrumentation)
}

func (w InstrumentationWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
inst, ok := obj.(*Instrumentation)
inst, ok := obj.(*types.Instrumentation)
if !ok {
return nil, fmt.Errorf("expected an Instrumentation, received %T", obj)
}
return w.validate(inst)
}

func (w InstrumentationWebhook) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
inst, ok := newObj.(*Instrumentation)
inst, ok := newObj.(*types.Instrumentation)
if !ok {
return nil, fmt.Errorf("expected an Instrumentation, received %T", newObj)
}
return w.validate(inst)
}

func (w InstrumentationWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
inst, ok := obj.(*Instrumentation)
inst, ok := obj.(*types.Instrumentation)
if !ok || inst == nil {
return nil, fmt.Errorf("expected an Instrumentation, received %T", obj)
}
return w.validate(inst)
}

func (w InstrumentationWebhook) defaulter(r *Instrumentation) error {
func (w InstrumentationWebhook) defaulter(r *types.Instrumentation) error {
if r.Labels == nil {
r.Labels = map[string]string{}
}
Expand Down Expand Up @@ -198,12 +199,12 @@
return nil
}

func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings, error) {
func (w InstrumentationWebhook) validate(r *types.Instrumentation) (admission.Warnings, error) {
var warnings []string
switch r.Spec.Type {
case "":
warnings = append(warnings, "sampler type not set")
case TraceIDRatio, ParentBasedTraceIDRatio:
case types.TraceIDRatio, types.ParentBasedTraceIDRatio:
if r.Spec.Argument != "" {
rate, err := strconv.ParseFloat(r.Spec.Argument, 64)
if err != nil {
Expand All @@ -213,7 +214,7 @@
return warnings, fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", r.Spec.Argument)
}
}
case JaegerRemote, ParentBasedJaegerRemote:
case types.JaegerRemote, types.ParentBasedJaegerRemote:
// value is a comma separated list of endpoint, pollingIntervalMs, initialSamplingRate
// Example: `endpoint=http://localhost:14250,pollingIntervalMs=5000,initialSamplingRate=0.25`
if r.Spec.Argument != "" {
Expand All @@ -223,7 +224,7 @@
return warnings, fmt.Errorf("spec.sampler.argument is not a valid argument for sampler %s: %w", r.Spec.Type, err)
}
}
case AlwaysOn, AlwaysOff, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler:
case types.AlwaysOn, types.AlwaysOff, types.ParentBasedAlwaysOn, types.ParentBasedAlwaysOff, types.XRaySampler:
default:
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Type)
}
Expand Down Expand Up @@ -286,7 +287,7 @@
return warnings, nil
}

func validateExporter(exporter Exporter) []string {
func validateExporter(exporter types.Exporter) []string {
var warnings []string
if exporter.TLS != nil {
tls := exporter.TLS
Expand Down Expand Up @@ -358,8 +359,12 @@
cfg,
)
return ctrl.NewWebhookManagedBy(mgr).
For(&Instrumentation{}).
For(&types.Instrumentation{}).
WithValidator(ivw).
WithDefaulter(ivw).
Complete()
}

func init() {
SchemeBuilder.Register(&types.Instrumentation{}, &types.InstrumentationList{})

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / run-e2e-tests / build-test-images

cannot use &types.InstrumentationList{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".InstrumentationList) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / run-e2e-tests / build-test-images

cannot use &types.Instrumentation{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".Instrumentation) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

cannot use &types.InstrumentationList{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".InstrumentationList) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register (typecheck)

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

cannot use &types.Instrumentation{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".Instrumentation) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / Security

cannot use &types.InstrumentationList{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".InstrumentationList) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register

Check failure on line 369 in apis/v1alpha1/instrumentation_webhook.go

View workflow job for this annotation

GitHub Actions / Security

cannot use &types.Instrumentation{} (value of type *"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types".Instrumentation) as func(*"k8s.io/apimachinery/pkg/runtime".Scheme) error value in argument to SchemeBuilder.Register
}
Loading
Loading