msp: provision and load EXTERNAL_DNS_NAME envvar (#58275)

This commit is contained in:
Robert Lin 2023-11-13 00:58:30 -08:00 committed by GitHub
parent 9c7d092513
commit e1f590b27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -129,11 +129,16 @@ func NewStack(stacks *stack.Set, vars Variables) (crossStackOutput *CrossStackOu
// convention across MSP services.
cloudRunBuilder.AddEnv("DIAGNOSTICS_SECRET", diagnosticsSecret.HexValue)
// Add the domain as an environment variable.
dnsName := pointers.DerefZero(vars.Environment.EnvironmentServiceSpec).Domain.GetDNSName()
if dnsName != "" {
cloudRunBuilder.AddEnv("EXTERNAL_DNS_NAME", dnsName)
}
// Add user-configured env vars
if err := addContainerEnvVars(cloudRunBuilder, vars.Environment.Env, vars.Environment.SecretEnv, envVariablesData{
ProjectID: vars.ProjectID,
ServiceDnsName: pointers.DerefZero(vars.Environment.EnvironmentServiceSpec).
Domain.GetDNSName(),
ProjectID: vars.ProjectID,
ServiceDnsName: dnsName,
}); err != nil {
return nil, errors.Wrap(err, "add user env vars")
}

View File

@ -9,14 +9,18 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)
// Contract loads standardized MSP-provisioned configuration.
type Contract struct {
// Port is the port the service must listen on.
Port int
// ExternalDNSName is the DNS name the service uses, if one is configured.
ExternalDNSName *string
}
func newContract(env *Env) Contract {
return Contract{
Port: env.GetInt("PORT", "", "service port"),
Port: env.GetInt("PORT", "", "service port"),
ExternalDNSName: env.GetOptional("EXTERNAL_DNS_NAME", "external DNS name provisioned for the service"),
}
}
@ -86,8 +90,12 @@ func (e *Env) Get(name, defaultValue, description string) string {
}
// GetOptional returns the value with the given name.
func (e *Env) GetOptional(name, description string) string {
return e.get(name, "", description)
func (e *Env) GetOptional(name, description string) *string {
v, ok := e.env[name]
if !ok {
return nil
}
return &v
}
// GetInt returns the value with the given name interpreted as an integer. If no