Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cbdcconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Config struct {
GCP Config_GCP `yaml:"gcp"`
Azure Config_Azure `yaml:"azure"`
Capella Config_Capella `yaml:"capella"`
DNS Config_DNS `yaml:"dns"`

DefaultDeployer string `yaml:"default-deployer"`
DefaultExpiry time.Duration `yaml:"default-expiry"`
Expand Down Expand Up @@ -119,6 +120,11 @@ type Config_Capella struct {
UploadServerLogsHostName string `yaml:"upload-server-logs-host-name"`
}

type Config_DNS struct {
Enabled StringBool `yaml:"enabled"`
Hostname string `yaml:"hostname"`
}

func DefaultConfigPath() (string, error) {
homePath, err := os.UserHomeDir()
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion clusterdef/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type DockerCluster struct {
CbasMemoryMB int `yaml:"cbas-memory,omitempty"`
EventingMemoryMB int `yaml:"eventing-memory,omitempty"`

Analytics AnalyticsSettings `yaml:"analytics,omitempty"`
Analytics AnalyticsSettings `yaml:"analytics,omitempty"`
EnableDNS bool `yaml:"dns,omitempty"`
EnableLoadBalancer bool `yaml:"load-balancer,omitempty"`
}

type AnalyticsSettings struct {
Expand Down
17 changes: 17 additions & 0 deletions cmd/cmdhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ func (h *CmdHelper) getDockerDeployer(ctx context.Context) (*dockerdeploy.Deploy
dockerHost := config.Docker.Host
dockerNetwork := config.Docker.Network

var dnsProvider dockerdeploy.DnsProvider
if config.DNS.Enabled.Value() {
if config.AWS.Enabled.ValueOr(false) {
awsCreds := h.GetAWSCredentials(ctx)

dnsProvider = &dockerdeploy.AwsDnsProvider{
Logger: logger,
Region: config.AWS.Region,
Credentials: awsCreds,
Hostname: config.DNS.Hostname,
}
} else {
logger.Warn("could not enable DNS provider, AWS is not enabled")
}
}

dockerCli, err := client.NewClientWithOpts(
client.WithHost(dockerHost),
client.WithAPIVersionNegotiation(),
Expand All @@ -123,6 +139,7 @@ func (h *CmdHelper) getDockerDeployer(ctx context.Context) (*dockerdeploy.Deploy
NetworkName: dockerNetwork,
GhcrUsername: githubUser,
GhcrPassword: githubToken,
DnsProvider: dnsProvider,
})
if err != nil {
return nil, errors.Wrap(err, "failed to initializer deployer")
Expand Down
65 changes: 57 additions & 8 deletions cmd/connstr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,36 @@ var connstrCmd = &cobra.Command{

useTLS, _ := cmd.Flags().GetBool("tls")
noTLS, _ := cmd.Flags().GetBool("no-tls")
useCb2, _ := cmd.Flags().GetBool("couchbase2")
dataApi, _ := cmd.Flags().GetBool("data-api")
cb2Mode, _ := cmd.Flags().GetBool("couchbase2")
dapiMode, _ := cmd.Flags().GetBool("data-api")
analyticsMode, _ := cmd.Flags().GetBool("analytics")

if useTLS && noTLS {
logger.Fatal("cannot request both TLS and non-TLS")
}

connstrType := ""
if cb2Mode {
if connstrType != "" {
logger.Fatal("cannot request both couchbase2 and other connstr types")
}

connstrType = "couchbase2"
}
if dapiMode {
if connstrType != "" {
logger.Fatal("cannot request both data-api and other connstr types")
}

connstrType = "data-api"
}
if analyticsMode {
if connstrType != "" {
logger.Fatal("cannot request both analytics and other connstr types")
}

connstrType = "analytics"
}

_, deployer, cluster := helper.IdentifyCluster(ctx, args[0])

Expand All @@ -30,7 +58,7 @@ var connstrCmd = &cobra.Command{
}

var connStr string
if useCb2 {
if connstrType == "couchbase2" {
if noTLS {
logger.Fatal("cannot request non-TLS for couchbase2")
}
Expand All @@ -39,7 +67,7 @@ var connstrCmd = &cobra.Command{
if connStr == "" {
logger.Fatal("couchbase2 endpoint is unavailable")
}
} else if dataApi {
} else if connstrType == "data-api" {
if noTLS {
logger.Fatal("cannot request non-TLS for Data API")
}
Expand All @@ -49,10 +77,28 @@ var connstrCmd = &cobra.Command{
if connStr == "" {
logger.Fatal("data API endpoint is unavailable")
}
} else {
if useTLS && noTLS {
logger.Fatal("cannot request both TLS and non-TLS")
} else if useTLS {
} else if connstrType == "analytics" {
if useTLS {
connStr = connectInfo.AnalyticsTls
if connStr == "" {
logger.Fatal("TLS endpoint is unavailable")
}
} else if noTLS {
connStr = connectInfo.Analytics
if connStr == "" {
logger.Fatal("non-TLS endpoint is unavailable")
}
} else {
connStr = connectInfo.Analytics
if connStr == "" {
connStr = connectInfo.AnalyticsTls
}
if connStr == "" {
logger.Fatal("no endpoint available")
}
}
} else if connstrType == "" {
if useTLS {
connStr = connectInfo.ConnStrTls
if connStr == "" {
logger.Fatal("TLS endpoint is unavailable")
Expand All @@ -71,6 +117,8 @@ var connstrCmd = &cobra.Command{
logger.Fatal("no endpoint available")
}
}
} else {
logger.Fatal("unknown connstr type", zap.String("type", connstrType))
}

fmt.Printf("%s\n", connStr)
Expand All @@ -84,4 +132,5 @@ func init() {
connstrCmd.PersistentFlags().Bool("tls", false, "Explicitly requests a TLS endpoint")
connstrCmd.PersistentFlags().Bool("no-tls", false, "Explicitly requests non-TLS endpoint")
connstrCmd.PersistentFlags().Bool("data-api", false, "Requests a Data API connstr")
connstrCmd.PersistentFlags().Bool("analytics", false, "Requests an Analytics connstr")
}
103 changes: 100 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/route53"
"github.com/couchbaselabs/cbdinocluster/cbdcconfig"
"github.com/couchbaselabs/cbdinocluster/utils/awscontrol"
"github.com/couchbaselabs/cbdinocluster/utils/azurecontrol"
"github.com/couchbaselabs/cbdinocluster/utils/caocontrol"
"github.com/couchbaselabs/cbdinocluster/utils/cloudinstancecontrol"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/google/go-github/v53/github"
Expand Down Expand Up @@ -454,7 +454,7 @@ var initCmd = &cobra.Command{
dockerNetwork = flagDockerNetwork
} else {
fmt.Printf("Listing docker networks:\n")
networks, _ := dockerCli.NetworkList(ctx, types.NetworkListOptions{})
networks, _ := dockerCli.NetworkList(ctx, network.ListOptions{})
for _, network := range networks {
fmt.Printf(" %s\n", network.Name)
}
Expand Down Expand Up @@ -490,7 +490,7 @@ var initCmd = &cobra.Command{
fmt.Printf("Creating dinonet network (subnet: %s, %s, %s).\n",
subnet, ipRange, gateway)

_, err := dockerCli.NetworkCreate(ctx, "dinonet", types.NetworkCreate{
_, err := dockerCli.NetworkCreate(ctx, "dinonet", network.CreateOptions{
Driver: "ipvlan",
IPAM: &network.IPAM{
Driver: "default",
Expand Down Expand Up @@ -1283,6 +1283,98 @@ var initCmd = &cobra.Command{
saveConfig()
}

printDnsConfig := func() {
fmt.Printf(" Enabled: %t\n", curConfig.DNS.Enabled.Value())
fmt.Printf(" Hostname: %s\n", curConfig.DNS.Hostname)
}
{
flagDisableDns, _ := cmd.Flags().GetBool("disable-dns")
flagDnsHostname, _ := cmd.Flags().GetString("dns-hostname")

dnsEnabled := curConfig.DNS.Enabled.ValueOr(true)
dnsHostname := curConfig.DNS.Hostname

for {
if flagDisableDns {
fmt.Printf("DNS disabled via flags.\n")
dnsEnabled = false
break
}

dnsEnabled = readBool(
"Would you like to enable DNS?",
dnsEnabled)
if !dnsEnabled {
break
}

if !curConfig.AWS.Enabled.ValueOr(false) {
fmt.Printf("AWS must be configured to use DNS.\n")
dnsEnabled = false
}

awsCfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
fmt.Printf("Failed to loads AWS environment: %s\n", err)
dnsEnabled = false
continue
}

route53Client := route53.New(route53.Options{
Region: curConfig.AWS.Region,
Credentials: awsCfg.Credentials,
})

zones, err := route53Client.ListHostedZones(ctx, nil)
if err != nil {
fmt.Printf("Failed to execute command (list hosted zones) with AWS credentials: %s\n", err)
dnsEnabled = false
continue
}

fmt.Printf("Found %d hosted zones\n", len(zones.HostedZones))
for _, zone := range zones.HostedZones {
zoneName := strings.TrimSuffix(*zone.Name, ".")
fmt.Printf(" %s (%s)\n", zoneName, *zone.Id)
}

if flagDnsHostname != "" {
fmt.Printf("DNS hostname specified via flags:\n %s\n", flagDnsHostname)
dnsHostname = flagDnsHostname
} else {
dnsHostname = readString(
"What DNS hostname should we use?",
dnsHostname, false)
}
if dnsHostname == "" {
fmt.Printf("The DNS hostname is required.\n")
dnsEnabled = false
continue
}

foundHostname := false
for _, zone := range zones.HostedZones {
zoneName := strings.TrimSuffix(*zone.Name, ".")
if zoneName == dnsHostname {
foundHostname = true
break
}
}

if !foundHostname {
fmt.Printf("The specified DNS hostname does not match any of the hosted zones.\n")
dnsEnabled = false
continue
}

break
}

curConfig.DNS.Enabled.Set(dnsEnabled)
curConfig.DNS.Hostname = dnsHostname
saveConfig()
}

printBaseConfig := func() {
fmt.Printf(" Default Deployer: %s\n", curConfig.DefaultDeployer)
fmt.Printf(" Default Expiry: %s\n", curConfig.DefaultExpiry.String())
Expand Down Expand Up @@ -1345,6 +1437,9 @@ var initCmd = &cobra.Command{
fmt.Printf("Using Capella configuration:\n")
printCapellaConfig()

fmt.Printf("Using DNS configuration:\n")
printDnsConfig()

fmt.Printf("Using Base configuration:\n")
printBaseConfig()
},
Expand Down Expand Up @@ -1379,5 +1474,7 @@ func init() {
initCmd.Flags().Bool("disable-aws", false, "Disable AWS")
initCmd.Flags().String("aws-region", "", "AWS default region to use")
initCmd.Flags().Bool("disable-azure", false, "Disable Azure")
initCmd.Flags().Bool("disable-dns", false, "Disable DNS")
initCmd.Flags().String("dns-hostname", "", "DNS hostname prefix to use")
initCmd.Flags().String("upload-server-logs-host-name", "", "Upload server logs host name")
}
12 changes: 7 additions & 5 deletions deployment/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ type ClusterInfo interface {
}

type ConnectInfo struct {
ConnStr string
ConnStrTls string
ConnStrCb2 string
Mgmt string
MgmtTls string
ConnStr string
ConnStrTls string
ConnStrCb2 string
Analytics string
AnalyticsTls string
Mgmt string
MgmtTls string
DataApiConnstr string
}

Expand Down
Loading