Skip to content

Commit 37f8193

Browse files
committed
Fix
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 9e2060b commit 37f8193

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

apis/v1alpha1/instrumentation_webhook.go

+8
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ func (w InstrumentationWebhook) validate(r *Instrumentation) (admission.Warnings
236236
default:
237237
return warnings, fmt.Errorf("spec.sampler.type is not valid: %s", r.Spec.Sampler.Type)
238238
}
239+
240+
if r.Spec.Exporter.TLS != nil {
241+
tls := r.Spec.Exporter.TLS
242+
if tls.Key != "" && tls.Cert == "" || tls.Cert != "" && tls.Key == "" {
243+
warnings = append(warnings, "both exporter.tls.key and exporter.tls.cert mut be set")
244+
}
245+
}
246+
239247
return warnings, nil
240248
}
241249

apis/v1alpha1/instrumentation_webhook_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,40 @@ func TestInstrumentationValidatingWebhook(t *testing.T) {
113113
},
114114
},
115115
},
116+
{
117+
name: "tls cert set but missing key",
118+
inst: Instrumentation{
119+
Spec: InstrumentationSpec{
120+
Sampler: Sampler{
121+
Type: ParentBasedTraceIDRatio,
122+
Argument: "0.99",
123+
},
124+
Exporter: Exporter{
125+
TLS: &TLS{
126+
Cert: "cert",
127+
},
128+
},
129+
},
130+
},
131+
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
132+
},
133+
{
134+
name: "tls key set but missing cert",
135+
inst: Instrumentation{
136+
Spec: InstrumentationSpec{
137+
Sampler: Sampler{
138+
Type: ParentBasedTraceIDRatio,
139+
Argument: "0.99",
140+
},
141+
Exporter: Exporter{
142+
TLS: &TLS{
143+
Key: "key",
144+
},
145+
},
146+
},
147+
},
148+
warnings: []string{"both exporter.tls.key and exporter.tls.cert mut be set"},
149+
},
116150
}
117151

118152
for _, test := range tests {

pkg/instrumentation/podmutator.go

+18-39
Original file line numberDiff line numberDiff line change
@@ -467,45 +467,24 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context
467467
}
468468

469469
func (pm *instPodMutator) validateInstrumentations(ctx context.Context, inst languageInstrumentations, podNamespace string) error {
470-
var errs []error
471-
if inst.Java.Instrumentation != nil {
472-
if err := pm.validateInstrumentation(ctx, *inst.Java.Instrumentation, podNamespace); err != nil {
473-
errs = append(errs, err)
474-
}
475-
}
476-
if inst.Python.Instrumentation != nil {
477-
if err := pm.validateInstrumentation(ctx, *inst.Python.Instrumentation, podNamespace); err != nil {
478-
errs = append(errs, err)
479-
}
480-
}
481-
if inst.NodeJS.Instrumentation != nil {
482-
if err := pm.validateInstrumentation(ctx, *inst.NodeJS.Instrumentation, podNamespace); err != nil {
483-
errs = append(errs, err)
484-
}
485-
}
486-
if inst.DotNet.Instrumentation != nil {
487-
if err := pm.validateInstrumentation(ctx, *inst.DotNet.Instrumentation, podNamespace); err != nil {
488-
errs = append(errs, err)
489-
}
490-
}
491-
if inst.Go.Instrumentation != nil {
492-
if err := pm.validateInstrumentation(ctx, *inst.Go.Instrumentation, podNamespace); err != nil {
493-
errs = append(errs, err)
494-
}
495-
}
496-
if inst.ApacheHttpd.Instrumentation != nil {
497-
if err := pm.validateInstrumentation(ctx, *inst.ApacheHttpd.Instrumentation, podNamespace); err != nil {
498-
errs = append(errs, err)
499-
}
500-
}
501-
if inst.Nginx.Instrumentation != nil {
502-
if err := pm.validateInstrumentation(ctx, *inst.Nginx.Instrumentation, podNamespace); err != nil {
503-
errs = append(errs, err)
504-
}
470+
instrumentations := []struct {
471+
instrumentation *v1alpha1.Instrumentation
472+
}{
473+
{inst.Java.Instrumentation},
474+
{inst.Python.Instrumentation},
475+
{inst.NodeJS.Instrumentation},
476+
{inst.DotNet.Instrumentation},
477+
{inst.Go.Instrumentation},
478+
{inst.ApacheHttpd.Instrumentation},
479+
{inst.Nginx.Instrumentation},
480+
{inst.Sdk.Instrumentation},
505481
}
506-
if inst.Sdk.Instrumentation != nil {
507-
if err := pm.validateInstrumentation(ctx, *inst.Sdk.Instrumentation, podNamespace); err != nil {
508-
errs = append(errs, err)
482+
var errs []error
483+
for _, i := range instrumentations {
484+
if i.instrumentation != nil {
485+
if err := pm.validateInstrumentation(ctx, i.instrumentation, podNamespace); err != nil {
486+
errs = append(errs, err)
487+
}
509488
}
510489
}
511490

@@ -515,7 +494,7 @@ func (pm *instPodMutator) validateInstrumentations(ctx context.Context, inst lan
515494
return nil
516495
}
517496

518-
func (pm *instPodMutator) validateInstrumentation(ctx context.Context, inst v1alpha1.Instrumentation, podNamespace string) error {
497+
func (pm *instPodMutator) validateInstrumentation(ctx context.Context, inst *v1alpha1.Instrumentation, podNamespace string) error {
519498
// Check if secret and configmap exists
520499
// If they don't exist pod cannot start
521500
var errs []error

tests/e2e-instrumentation/instrumentation-java-tls/chainsaw-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: chainsaw.kyverno.io/v1alpha1
33
kind: Test
44
metadata:
55
creationTimestamp: null
6-
name: instrumentation-java
6+
name: instrumentation-java-tls
77
spec:
88
steps:
99
- name: step-00

tests/e2e-instrumentation/instrumentation-java-tls/generate-certs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -ex
44

55
# CA key and cert
66
openssl req -new -nodes -x509 -days 9650 -keyout ca.key -out ca.crt -subj "/C=US/ST=California/L=Mountain View/O=Your Organization/OU=Your Unit/CN=localhost"
7-
# Server
8-
openssl req -new -nodes -x509 -CA ca.crt -CAkey ca.key -days 9650 -set_serial 01 -keyout server.key -out server.crt -subj "/C=US/ST=California/L=Mountain View/O=Your Organization/OU=Your Unit/CN=svc.cluster.local/CN=localhost" -addext "subjectAltName = DNS:simplest-collector,DNS:*.tracing-system.svc.cluster.local,DNS:localhost"
7+
# Server, E.g. use NDS:*.default.svc.cluster.local for arbitrary collector name deployed in the default namespace
8+
openssl req -new -nodes -x509 -CA ca.crt -CAkey ca.key -days 9650 -set_serial 01 -keyout server.key -out server.crt -subj "/C=US/ST=California/L=Mountain View/O=Your Organization/OU=Your Unit/CN=svc.cluster.local/CN=localhost" -addext "subjectAltName = DNS:simplest-collector,DNS:localhost"
99
# Client
1010
openssl req -new -nodes -x509 -CA ca.crt -CAkey ca.key -days 9650 -set_serial 01 -keyout client.key -out client.crt -subj "/C=US/ST=California/L=Mountain View/O=Your Organization/OU=Your Unit/CN=svc.cluster.local/CN=localhost"
1111

0 commit comments

Comments
 (0)