Skip to content

Commit 4602b67

Browse files
committed
[chore] move types outside of CR definition
1 parent daa05c5 commit 4602b67

33 files changed

+970
-936
lines changed

apis/v1alpha1/instrumentation_webhook.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2020

2121
"github.com/open-telemetry/opentelemetry-operator/internal/config"
22+
"github.com/open-telemetry/opentelemetry-operator/internal/instrumentation/types"
2223
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
2324
)
2425

@@ -47,38 +48,38 @@ type InstrumentationWebhook struct {
4748
}
4849

4950
func (w InstrumentationWebhook) Default(_ context.Context, obj runtime.Object) error {
50-
instrumentation, ok := obj.(*Instrumentation)
51+
instrumentation, ok := obj.(*types.Instrumentation)
5152
if !ok {
5253
return fmt.Errorf("expected an Instrumentation, received %T", obj)
5354
}
5455
return w.defaulter(instrumentation)
5556
}
5657

5758
func (w InstrumentationWebhook) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
58-
inst, ok := obj.(*Instrumentation)
59+
inst, ok := obj.(*types.Instrumentation)
5960
if !ok {
6061
return nil, fmt.Errorf("expected an Instrumentation, received %T", obj)
6162
}
6263
return w.validate(inst)
6364
}
6465

6566
func (w InstrumentationWebhook) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
66-
inst, ok := newObj.(*Instrumentation)
67+
inst, ok := newObj.(*types.Instrumentation)
6768
if !ok {
6869
return nil, fmt.Errorf("expected an Instrumentation, received %T", newObj)
6970
}
7071
return w.validate(inst)
7172
}
7273

7374
func (w InstrumentationWebhook) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
74-
inst, ok := obj.(*Instrumentation)
75+
inst, ok := obj.(*types.Instrumentation)
7576
if !ok || inst == nil {
7677
return nil, fmt.Errorf("expected an Instrumentation, received %T", obj)
7778
}
7879
return w.validate(inst)
7980
}
8081

81-
func (w InstrumentationWebhook) defaulter(r *Instrumentation) error {
82+
func (w InstrumentationWebhook) defaulter(r *types.Instrumentation) error {
8283
if r.Labels == nil {
8384
r.Labels = map[string]string{}
8485
}
@@ -198,12 +199,12 @@ func (w InstrumentationWebhook) defaulter(r *Instrumentation) error {
198199
return nil
199200
}
200201

201-
func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings, error) {
202+
func (w InstrumentationWebhook) validate(r *types.Instrumentation) (admission.Warnings, error) {
202203
var warnings []string
203204
switch r.Spec.Type {
204205
case "":
205206
warnings = append(warnings, "sampler type not set")
206-
case TraceIDRatio, ParentBasedTraceIDRatio:
207+
case types.TraceIDRatio, types.ParentBasedTraceIDRatio:
207208
if r.Spec.Argument != "" {
208209
rate, err := strconv.ParseFloat(r.Spec.Argument, 64)
209210
if err != nil {
@@ -213,7 +214,7 @@ func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings,
213214
return warnings, fmt.Errorf("spec.sampler.argument should be in rage [0..1]: %s", r.Spec.Argument)
214215
}
215216
}
216-
case JaegerRemote, ParentBasedJaegerRemote:
217+
case types.JaegerRemote, types.ParentBasedJaegerRemote:
217218
// value is a comma separated list of endpoint, pollingIntervalMs, initialSamplingRate
218219
// Example: `endpoint=http://localhost:14250,pollingIntervalMs=5000,initialSamplingRate=0.25`
219220
if r.Spec.Argument != "" {
@@ -223,7 +224,7 @@ func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings,
223224
return warnings, fmt.Errorf("spec.sampler.argument is not a valid argument for sampler %s: %w", r.Spec.Type, err)
224225
}
225226
}
226-
case AlwaysOn, AlwaysOff, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler:
227+
case types.AlwaysOn, types.AlwaysOff, types.ParentBasedAlwaysOn, types.ParentBasedAlwaysOff, types.XRaySampler:
227228
default:
228229
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Type)
229230
}
@@ -286,7 +287,7 @@ func (InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings,
286287
return warnings, nil
287288
}
288289

289-
func validateExporter(exporter Exporter) []string {
290+
func validateExporter(exporter types.Exporter) []string {
290291
var warnings []string
291292
if exporter.TLS != nil {
292293
tls := exporter.TLS
@@ -358,8 +359,12 @@ func SetupInstrumentationWebhook(mgr ctrl.Manager, cfg config.Config) error {
358359
cfg,
359360
)
360361
return ctrl.NewWebhookManagedBy(mgr).
361-
For(&Instrumentation{}).
362+
For(&types.Instrumentation{}).
362363
WithValidator(ivw).
363364
WithDefaulter(ivw).
364365
Complete()
365366
}
367+
368+
func init() {
369+
SchemeBuilder.Register(&types.Instrumentation{}, &types.InstrumentationList{})
370+
}

0 commit comments

Comments
 (0)