Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds cao based cb cluster deployment #24

Closed
Closed
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
8,340 changes: 8,340 additions & 0 deletions cbdcconfig/cao/2.5/crd.yaml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will leaving a hard coded crd not cause issues in the future? Will this method mean we need to manually update this file when it goes stale?

Copy link
Author

@boseabhishek boseabhishek Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you do cbdinocluster init, it lets you set everything e.g. operator version, admission version, namespaces, path to crd file and cao bin etc - when you choose cao as your preferred deployer

Large diffs are not rendered by default.

Binary file added cbdcconfig/cao/bin/cao
Binary file not shown.
18 changes: 18 additions & 0 deletions cbdcconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Config struct {
GCP Config_GCP `yaml:"gcp"`
Azure Config_Azure `yaml:"azure"`
Capella Config_Capella `yaml:"capella"`
Cao Config_Cao `yaml:"cao"`

DefaultDeployer string `yaml:"default-deployer"`
DefaultExpiry time.Duration `yaml:"default-expiry"`
Expand Down Expand Up @@ -107,6 +108,23 @@ type Config_Capella struct {
DefaultGcpRegion string `yaml:"default-gcp-region"`
}

type Config_Cao struct {
Enabled StringBool `yaml:"enabled"`
KubeConfigPath string `yaml:"kubeconfig"`

// for pulling ghcr images
NeedGhcrAccess StringBool `yaml:"needGhcrAccess"`
GhcrToken string `yaml:"ghcrToken"`
GhcrUser string `yaml:"ghcrUser"`

OperatorVersion string `yaml:"operatorVersion"`
OperatorNamespace string `yaml:"operatorNamespace"`
AdmissionVersion string `yaml:"admissionVersion"`
AdmissionNamespace string `yaml:"admissionNamespace"`
CrdPath string `yaml:"crdPath"`
CaoBinPath string `yaml:"caoBinPath"`
}

func DefaultConfigPath() (string, error) {
homePath, err := os.UserHomeDir()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions cbdcconfig/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ const (
DEFAULT_CAPELLA_ENDPOINT = "https://api.cloud.couchbase.com"
DEFAULT_CAPELLA_PROVIDER = "aws"
)

const (
// ONLY, released(public) operator/admission controller images are used here
// This is because we are NOT testing on unreleased(private/ghcr) operator/admission controlle
// We use CNG w/ operator from version 2.5.0+
DEFAULT_CAO_OPERATOR_VERSION = "2.5.0"
// We use CNG w/ admission from version 2.5.0+
DEFAULT_CAO_ADMISSION_VERSION = "2.5.0"
// We use CNG w/ admission from version 2.5.0+
DEFAULT_CAO_CRD_FILE_PATH = "cbdcconfig/cao/2.5/crd.yaml"
// cao binary doesn't chnage usually, unlesss a new command/flag need to be used.
DEFAULT_CAO_BIN_PATH = "./cbdcconfig/cao/bin/cao"

DEFAULT_NAMESPACE = "default"
)
10 changes: 8 additions & 2 deletions clusterdef/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ type NodeGroup struct {
// any existing nodes when doing modifications.
ForceNew bool `yaml:"force-new,omitempty"`

Version string `yaml:"version,omitempty"`
Services []Service `yaml:"services,omitempty"`
Version string `yaml:"version,omitempty"`
ServerImage string `yaml:"srvImage,omitempty"`
Services []Service `yaml:"services,omitempty"`

Docker DockerNodeGroup `yaml:"docker,omitempty"`
Cloud CloudNodeGroup `yaml:"cloud,omitempty"`
Cao CaoNodeGroup `yaml:"cao,omitempty"`
}

type DockerNodeGroup struct {
Expand All @@ -25,3 +27,7 @@ type CloudNodeGroup struct {
DiskSize int `yaml:"disk-size,omitempty"`
DiskIops int `yaml:"disk-iops,omitempty"`
}

type CaoNodeGroup struct {
CNGImage string `yaml:"cngImage,omitempty"`
}
74 changes: 72 additions & 2 deletions cmd/cmdhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/couchbaselabs/cbdinocluster/cbdcconfig"
"github.com/couchbaselabs/cbdinocluster/deployment"
"github.com/couchbaselabs/cbdinocluster/deployment/caodeploy"
"github.com/couchbaselabs/cbdinocluster/deployment/clouddeploy"
"github.com/couchbaselabs/cbdinocluster/deployment/dockerdeploy"
"github.com/couchbaselabs/cbdinocluster/utils/caocontrol"
"github.com/couchbaselabs/cbdinocluster/utils/capellacontrol"
"github.com/docker/docker/client"
"github.com/pkg/errors"
Expand Down Expand Up @@ -160,6 +162,55 @@ func (h *CmdHelper) getCloudDeployer(ctx context.Context) (*clouddeploy.Deployer
return prov, nil
}

func (h *CmdHelper) getCaoDeployer(ctx context.Context) (*caodeploy.Deployer, error) {
logger := h.GetLogger()
config := h.GetConfig(ctx)

if !config.Cao.Enabled.Value() {
return nil, nil
}

kubeConfigPath := config.Cao.KubeConfigPath

client, err := caocontrol.NewController(&caocontrol.ControllerOptions{
Logger: logger,
KubeConfigPath: kubeConfigPath,
})
if err != nil {
return nil, errors.Wrap(err, "failed to create cao controller")
}

caoOperatorVer := config.Cao.OperatorVersion
caoAdmissionVer := config.Cao.AdmissionVersion
operatorNamespace := config.Cao.AdmissionNamespace
admissionNamespace := config.Cao.OperatorNamespace
caoCRDPath := config.Cao.CrdPath
caoBinPath := config.Cao.CaoBinPath

dopts := &caodeploy.NewDeployerOptions{
Logger: logger,
Client: client,
OperatorVer: caoOperatorVer,
AdmissionVer: caoAdmissionVer,
CrdPath: caoCRDPath,
CaoBinPath: caoBinPath,
AdmissionNamespace: admissionNamespace,
OperatorNamespace: operatorNamespace,
}

if config.Cao.NeedGhcrAccess.Value() {
dopts.GhcrUser = config.Cao.GhcrUser
dopts.GhcrToken = config.Cao.GhcrToken
}

caoDeployer, err := caodeploy.NewDeployer(dopts)
if err != nil {
return nil, errors.Wrap(err, "failed to create cao deployer")
}

return caoDeployer, nil
}

func (h *CmdHelper) GetAllDeployers(ctx context.Context) map[string]deployment.Deployer {
logger := h.GetLogger()

Expand All @@ -175,6 +226,11 @@ func (h *CmdHelper) GetAllDeployers(ctx context.Context) map[string]deployment.D
out["cloud"] = cloudDeployer
}

caoDeployer, _ := h.getCaoDeployer(ctx)
if caoDeployer != nil {
out["cao"] = caoDeployer
}

logger.Info("identified available deployers",
zap.Strings("deployers", maps.Keys(out)))

Expand All @@ -188,9 +244,12 @@ func (h *CmdHelper) GetAllDeployers(ctx context.Context) map[string]deployment.D
func (h *CmdHelper) GetDeployer(ctx context.Context) deployment.Deployer {
config := h.GetConfig(ctx)

if config.DefaultDeployer == "cloud" {
switch config.DefaultDeployer {
case "cloud":
return h.GetCloudDeployer(ctx)
} else {
case "cao":
return h.GetCaoDeployer(ctx)
default:
return h.GetDockerDeployer(ctx)
}
}
Expand Down Expand Up @@ -260,6 +319,17 @@ func (h *CmdHelper) GetCloudDeployer(ctx context.Context) *clouddeploy.Deployer
return deployer
}

func (h *CmdHelper) GetCaoDeployer(ctx context.Context) *caodeploy.Deployer {
logger := h.GetLogger()

deployer, err := h.getCaoDeployer(ctx)
if err != nil {
logger.Fatal("failed to get cao deployer", zap.Error(err))
}

return deployer
}

func (h *CmdHelper) GetAWSCredentials(ctx context.Context) aws.Credentials {
logger := h.GetLogger()
cbdcConfig := h.GetConfig(ctx)
Expand Down
Loading
Loading