Skip to content

Commit

Permalink
roachprod: configure providers needed for DNS
Browse files Browse the repository at this point in the history
Before this change, DNS would only sync if the AWS provider was active.
This is now configurable.

Epic: None

Release note: None
  • Loading branch information
ajwerner committed Mar 12, 2024
1 parent edf3397 commit 1596150
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/cmd/roachprod/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,10 @@ func initFlags() {
"sql-instance", 0, "specific SQL/HTTP instance to connect to (this is a roachprod abstraction distinct from the internal instance ID)")
}

for _, cmd := range []*cobra.Command{startCmd, listCmd, syncCmd} {
cmd.Flags().StringSliceVar(&config.DNSRequiredProviders,
"dns-required-providers", config.DefaultDNSRequiredProviders,
"the cloud providers that must be active to refresh DNS entries",
)
}
}
17 changes: 17 additions & 0 deletions pkg/roachprod/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"path"
"regexp"
"slices"
"strings"

"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
Expand Down Expand Up @@ -57,6 +58,15 @@ var (

// EmailDomain used to form fully qualified usernames for gcloud and slack.
EmailDomain string

// DNSRequiredProviders is the list of cloud providers that must be active for
// DNS records to be synced when roachprod syncs its state.
DefaultDNSRequiredProviders = envOrDefaultStrings(
"ROACHPROD_DNS_REQUIRED_PROVIDERS", []string{"gce", "aws"},
)

// DNSRequiredProviders is the list of cloud providers that must be active for
DNSRequiredProviders []string
)

// EnvOrDefaultString returns the value of the environment variable with the
Expand All @@ -70,6 +80,13 @@ func EnvOrDefaultString(key, def string) string {
return def
}

func envOrDefaultStrings(key string, def []string) []string {
if v, ok := os.LookupEnv(key); ok {
return strings.Split(v, ",")
}
return def
}

func init() {
var err error
OSUser, err = user.Current()
Expand Down
12 changes: 11 additions & 1 deletion pkg/roachprod/roachprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,18 @@ func Sync(l *logger.Logger, options vm.ListOptions) (*cloud.Cloud, error) {
refreshDNS = false
}
}
if !vm.Providers[aws.ProviderName].Active() {
// If there are no DNS required providers, we shouldn't refresh DNS,
// it's probably a misconfiguration.
if len(config.DNSRequiredProviders) == 0 {
refreshDNS = false
} else {
// If any of the required providers is not active, we shouldn't refresh DNS.
for _, p := range config.DNSRequiredProviders {
if !vm.Providers[p].Active() {
refreshDNS = false
break
}
}
}
// DNS entries are maintained in the GCE DNS registry for all vms, from all
// clouds.
Expand Down

0 comments on commit 1596150

Please sign in to comment.