From b6c42aa98d8e806c69097e0c3c33bbed84137aae Mon Sep 17 00:00:00 2001 From: Daniel Stokes Date: Tue, 29 Oct 2024 12:28:47 -0500 Subject: [PATCH] fix health validation and path --- src/apm/health.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/apm/health.go b/src/apm/health.go index b2a61a8c..50c35fc7 100644 --- a/src/apm/health.go +++ b/src/apm/health.go @@ -83,21 +83,24 @@ func (i *HealthInjector) Inject(ctx context.Context, inst v1alpha2.Instrumentati return pod, err } + // inject Health instrumentation spec env vars. + for _, env := range inst.Spec.Agent.Env { + idx := getIndexOfEnv(container.Env, env.Name) + if idx == -1 { + container.Env = append(container.Env, env) + } + } + heathFileIdx := getIndexOfEnv(container.Env, envHealthFleetControlFile) if heathFileIdx == -1 { return pod, fmt.Errorf("missing required %q env variable", envHealthFleetControlFile) } - healthMountPath := filepath.Base(container.Env[heathFileIdx].Value) + healthMountPath := filepath.Dir(container.Env[heathFileIdx].Value) if healthMountPath == "" { return pod, fmt.Errorf("env variable %q configured incorrectly. requires a full path", envHealthFleetControlFile) } - - // inject Health instrumentation spec env vars. - for _, env := range inst.Spec.Agent.Env { - idx := getIndexOfEnv(container.Env, env.Name) - if idx == -1 { - container.Env = append(container.Env, env) - } + if healthMountPath == "/" { + return pod, fmt.Errorf("env variable %q configured incorrectly. cannot be the root", envHealthFleetControlFile) } //set defaults