Skip to content

Commit

Permalink
chore(kubernetes): Improve logging when envs not found
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Dec 8, 2023
1 parent cb5a466 commit ba0d427
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/kubernetes/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import (
"context"
"errors"
"fmt"
"strings"

log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var ErrEnvVarNotFound = errors.New("env var not found")
var (
ErrEnvVarNotFound = errors.New("env var not found")
ErrNoDiscoveryEnvs = errors.New("discovery envs not found")
)

func FindEnvVar(pod v1.Pod, envName string) (*v1.EnvVar, error) {
for _, container := range pod.Spec.Containers {
Expand All @@ -21,7 +25,7 @@ func FindEnvVar(pod v1.Pod, envName string) (*v1.EnvVar, error) {
}
}
log.WithField("name", envName).Trace("failed to find env")
return nil, fmt.Errorf("%v: %s", ErrEnvVarNotFound, envName)
return nil, fmt.Errorf("%w: %s", ErrEnvVarNotFound, envName)
}

var (
Expand All @@ -44,6 +48,9 @@ func (client KubeClient) GetValueFromEnv(ctx context.Context, pod v1.Pod, envNam
}
}
if err != nil {
if errors.Is(err, ErrEnvVarNotFound) {
return "", fmt.Errorf("%w: %s", ErrNoDiscoveryEnvs, strings.Join(envNames, ", "))
}
return "", err
}

Expand Down

0 comments on commit ba0d427

Please sign in to comment.