Skip to content

Commit 6bed105

Browse files
committed
More validation
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 2849547 commit 6bed105

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

apis/v1alpha1/instrumentation_webhook.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,28 @@ func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings
237237
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
238238
}
239239

240-
if r.Spec.Exporter.TLS != nil {
241-
tls := r.Spec.Exporter.TLS
240+
warnings = append(warnings, validateExporter(r.Spec.Exporter)...)
241+
242+
return warnings, nil
243+
}
244+
245+
func validateExporter(exporter Exporter) []string {
246+
var warnings []string
247+
if exporter.TLS != nil {
248+
tls := exporter.TLS
242249
if tls.Key != "" && tls.Cert == "" || tls.Cert != "" && tls.Key == "" {
243250
warnings = append(warnings, "both exporter.tls.key and exporter.tls.cert mut be set")
244251
}
252+
253+
if !strings.HasPrefix(exporter.Endpoint, "https://") {
254+
warnings = append(warnings, "exporter.tls is configured but exporter.endpoint is not enabling TLS with https://")
255+
}
256+
}
257+
if strings.HasPrefix(exporter.Endpoint, "https://") && exporter.TLS == nil {
258+
warnings = append(warnings, "exporter is using https:// but exporter.tls is unset")
245259
}
246260

247-
return warnings, nil
261+
return warnings
248262
}
249263

250264
func validateJaegerRemoteSamplerArgument(argument string) error {

apis/v1alpha1/instrumentation_webhook_test.go

+40-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
114114
},
115115
},
116116
{
117-
name: "tls cert set but missing key",
117+
name: "exporter: tls cert set but missing key",
118118
inst: Instrumentation{
119119
Spec: InstrumentationSpec{
120120
Sampler: Sampler{
121121
Type: ParentBasedTraceIDRatio,
122122
Argument: "0.99",
123123
},
124124
Exporter: Exporter{
125+
Endpoint: "https://collector:4317",
125126
TLS: &TLS{
126127
Cert: "cert",
127128
},
@@ -131,14 +132,15 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
131132
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
132133
},
133134
{
134-
name: "tls key set but missing cert",
135+
name: "exporter: tls key set but missing cert",
135136
inst: Instrumentation{
136137
Spec: InstrumentationSpec{
137138
Sampler: Sampler{
138139
Type: ParentBasedTraceIDRatio,
139140
Argument: "0.99",
140141
},
141142
Exporter: Exporter{
143+
Endpoint: "https://collector:4317",
142144
TLS: &TLS{
143145
Key: "key",
144146
},
@@ -148,14 +150,49 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
148150
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
149151
},
150152
{
151-
name: "no warning set",
153+
name: "exporter: tls set but using http://",
152154
inst: Instrumentation{
153155
Spec: InstrumentationSpec{
154156
Sampler: Sampler{
155157
Type: ParentBasedTraceIDRatio,
156158
Argument: "0.99",
157159
},
158160
Exporter: Exporter{
161+
Endpoint: "http://collector:4317",
162+
TLS: &TLS{
163+
Key: "key",
164+
Cert: "cert",
165+
},
166+
},
167+
},
168+
},
169+
warnings: []string{"exporter.tls is configured but exporter.endpoint is not enabling TLS with https://"},
170+
},
171+
{
172+
name: "exporter: exporter using http://, but the tls is nil",
173+
inst: Instrumentation{
174+
Spec: InstrumentationSpec{
175+
Sampler: Sampler{
176+
Type: ParentBasedTraceIDRatio,
177+
Argument: "0.99",
178+
},
179+
Exporter: Exporter{
180+
Endpoint: "https://collector:4317",
181+
},
182+
},
183+
},
184+
warnings: []string{"exporter is using https:// but exporter.tls is unset"},
185+
},
186+
{
187+
name: "exporter no warning set",
188+
inst: Instrumentation{
189+
Spec: InstrumentationSpec{
190+
Sampler: Sampler{
191+
Type: ParentBasedTraceIDRatio,
192+
Argument: "0.99",
193+
},
194+
Exporter: Exporter{
195+
Endpoint: "https://collector:4317",
159196
TLS: &TLS{
160197
Key: "key",
161198
Cert: "cert",

0 commit comments

Comments
 (0)