Skip to content

Commit

Permalink
only env name start with "OTEL_" is allowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan-tree-zhou committed Jan 19, 2022
1 parent e1a0f4b commit d4efa35
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 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 (
"fmt"
"strconv"
"strings"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -28,6 +29,7 @@ const (
AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image"
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image"
AnnotationDefaultAutoInstrumentationPython = "instrumentation.opentelemetry.io/default-auto-instrumentation-python-image"
CustomizedEnvPrefix = "OTEL_"
)

// log is for logging in this package.
Expand Down Expand Up @@ -107,5 +109,31 @@ func (in *Instrumentation) validate() error {
}
case AlwaysOn, AlwaysOff, JaegerRemote, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler:
}

// validate customized environments
if err := in.validateEnv(in.Spec.Env); err != nil {
return err
}
if err := in.validateEnv(in.Spec.Java.Env); err != nil {
return err
}
if err := in.validateEnv(in.Spec.NodeJS.Env); err != nil {
return err
}
if err := in.validateEnv(in.Spec.Python.Env); err != nil {
return err
}

return nil
}

func (in *Instrumentation) validateEnv(envs []Env) error {
if len(envs) > 0 {
for _, env := range envs {
if !strings.HasPrefix(env.Name, CustomizedEnvPrefix) {
return fmt.Errorf("customized env name should start with \"OTEL_\": %s", env.Name)
}
}
}
return nil
}

0 comments on commit d4efa35

Please sign in to comment.