func RunAs(env *Env) string {
	if env.RunAs != "" {
		if env.RunAs == RunAsJob {
			return RunAsJob
		}
		return RunAsLocal
	}
	if RunningInKubernetes() && !RunningInTelepresence() {
		return RunAsJob
	}
	return RunAsLocal
}
RunAs returns a string containing the type of environment the tests should run as.

- service: run as a gRPC service pod (save results to database)
- local: run using the standard Go runner (do not save results to database)
- job: run as a k8 job (run-once, save results to database)
package config
import (
	"fmt"
	"github.com/kelseyhightower/envconfig"
	"github.com/pkg/errors"
	"os"
)
const (
	envDevelopment = "development"
	RunAsLocal     = "local"  
	RunAsJob       = "job"    
)
var (
	KubernetesServiceHostKey = "KUBERNETES_SERVICE_HOST"
	TelepresenceRootKey      = "TELEPRESENCE_ROOT"
)
type Env struct {
	Env string `envconfig:"ENV" default:"development"`
	GCPProjectID string `envconfig:"GCP_PROJECT_ID"`
	PrintOutputToEventLog bool `envconfig:"PRINT_OUTPUT_TO_EVENT_LOG" default:"false"`
	RunAs string `envconfig:"RUN_AS"`
	DbUrl string `envconfig:"DB_URL"`
}
func (e *Env) validate() error {
	checks := []struct {
		bad    bool
		errMsg string
	}{
		{
			e.Env != envDevelopment,
			fmt.Sprintf("invalid env is specified: %q", e.Env),
		},
	}
	for _, check := range checks {
		if check.bad {
			return errors.Errorf(check.errMsg)
		}
	}
	return nil
}
func ReadFromEnv() (*Env, error) {
	var env Env
	if err := envconfig.Process("", &env); err != nil {
		return nil, errors.Wrap(err, "failed to process envconfig")
	}
	if err := env.validate(); err != nil {
		return nil, errors.Wrap(err, "validation failed")
	}
	return &env, nil
}
func RunningInKubernetes() bool {
	_, set := os.LookupEnv(KubernetesServiceHostKey)
	return set
}
func RunningInTelepresence() bool {
	_, set := os.LookupEnv(TelepresenceRootKey)
	return set
}