Skip to content

Commit

Permalink
Add httpAddr, sqlAddr, listenAddr in CrdbCluster API and migrated por…
Browse files Browse the repository at this point in the history
…ts to addresses
  • Loading branch information
prafull01 committed Oct 25, 2024
1 parent ff902fd commit 8c47b28
Show file tree
Hide file tree
Showing 25 changed files with 242 additions and 59 deletions.
16 changes: 16 additions & 0 deletions apis/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,31 @@ type CrdbClusterSpec struct {
// (Optional) The database port (`--listen-addr` CLI parameter when starting the service)
// Default: 26258
// +optional
// Deprecated: Use ListenAddr instead of GRPCPort
GRPCPort *int32 `json:"grpcPort,omitempty"`
// (Optional) The database port (`--listen-addr` CLI parameter when starting the service)
// Default: ":26258"
// +optional
ListenAddr *string `json:"listenAddr,omitempty"`
// (Optional) The web UI port (`--http-addr` CLI parameter when starting the service)
// Default: 8080
// +optional
// Deprecated: Use HTTPAddr instead of HTTPPort
HTTPPort *int32 `json:"httpPort,omitempty"`
// (Optional) The IP address/hostname and port on which to listen for DB Console HTTP requests.
// (`--http-addr` CLI parameter when starting the service)
// Default: ":8080"
// +optional
HTTPAddr *string `json:"httpAddr,omitempty"`
// (Optional) The SQL Port number
// Default: 26257
// +optional
// Deprecated: Use SQLAddr instead of SQLPort
SQLPort *int32 `json:"sqlPort,omitempty"`
// (Optional) The IP address/hostname and port on which to listen for SQL connections from clients.
// Default: ":26257"
// +optional
SQLAddr *string `json:"sqlAddr,omitempty"`
// (Optional) TLSEnabled determines if TLS is enabled for your CockroachDB Cluster
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="TLS Enabled",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
// +optional
Expand Down
36 changes: 24 additions & 12 deletions apis/v1alpha1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
)

var (
// DefaultGRPCPort is the default port used for GRPC communication
DefaultGRPCPort int32 = 26258
// DefaultSQLPort is the default port used for SQL connections
DefaultSQLPort int32 = 26257
// DefaultHTTPPort is the default port for the Web UI
DefaultHTTPPort int32 = 8080
// DefaultGRPCAddr is the default grpc address used for GRPC communication
DefaultGRPCAddr string = ":26258"
// DefaultSQLAddr is the default sql address used for SQL connections
DefaultSQLAddr string = ":26257"
// DefaultHTTPAddr is the default http address for the Web UI
DefaultHTTPAddr string = ":8080"
// DefaultMaxUnavailable is the default max unavailable nodes during a rollout
DefaultMaxUnavailable int32 = 1
)
Expand All @@ -59,16 +59,28 @@ func (r *CrdbCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (r *CrdbCluster) Default() {
webhookLog.Info("default", "name", r.Name)

if r.Spec.GRPCPort == nil {
r.Spec.GRPCPort = &DefaultGRPCPort
if r.Spec.GRPCPort == nil && r.Spec.ListenAddr == nil {
r.Spec.ListenAddr = &DefaultGRPCAddr
} else if r.Spec.GRPCPort != nil && r.Spec.ListenAddr == nil {
listenAddr := fmt.Sprintf(":%d", *r.Spec.GRPCPort)
r.Spec.ListenAddr = &listenAddr
r.Spec.GRPCPort = nil
}

if r.Spec.SQLPort == nil {
r.Spec.SQLPort = &DefaultSQLPort
if r.Spec.SQLPort == nil && r.Spec.SQLAddr == nil {
r.Spec.SQLAddr = &DefaultSQLAddr
} else if r.Spec.SQLPort != nil && r.Spec.SQLAddr == nil {
sqlAddr := fmt.Sprintf(":%d", *r.Spec.SQLPort)
r.Spec.SQLAddr = &sqlAddr
r.Spec.SQLPort = nil
}

if r.Spec.HTTPPort == nil {
r.Spec.HTTPPort = &DefaultHTTPPort
if r.Spec.HTTPPort == nil && r.Spec.HTTPAddr == nil {
r.Spec.HTTPAddr = &DefaultHTTPAddr
} else if r.Spec.HTTPPort != nil && r.Spec.HTTPAddr == nil {
httpAddr := fmt.Sprintf(":%d", *r.Spec.HTTPPort)
r.Spec.HTTPAddr = &httpAddr
r.Spec.HTTPPort = nil
}

if r.Spec.MaxUnavailable == nil && r.Spec.MinAvailable == nil {
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestCrdbClusterDefault(t *testing.T) {
maxUnavailable := int32(1)
policy := v1.PullIfNotPresent
expected := CrdbClusterSpec{
GRPCPort: &DefaultGRPCPort,
HTTPPort: &DefaultHTTPPort,
SQLPort: &DefaultSQLPort,
ListenAddr: &DefaultGRPCAddr,
SQLAddr: &DefaultSQLAddr,
HTTPAddr: &DefaultHTTPAddr,
MaxUnavailable: &maxUnavailable,
Image: &PodImage{PullPolicyName: &policy},
}
Expand Down
15 changes: 15 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,12 +1087,19 @@ spec:
type: object
grpcPort:
description: '(Optional) The database port (`--listen-addr` CLI parameter
when starting the service) Default: 26258'
when starting the service) Default: 26258 Deprecated: Use ListenAddr
instead of GRPCPort'
format: int32
type: integer
httpAddr:
description: '(Optional) The IP address/hostname and port on which
to listen for DB Console HTTP requests. (`--http-addr` CLI parameter
when starting the service) Default: ":8080"'
type: string
httpPort:
description: '(Optional) The web UI port (`--http-addr` CLI parameter
when starting the service) Default: 8080'
when starting the service) Default: 8080 Deprecated: Use HTTPAddr
instead of HTTPPort'
format: int32
type: integer
image:
Expand Down Expand Up @@ -1214,6 +1221,10 @@ spec:
- host
type: object
type: object
listenAddr:
description: '(Optional) The database port (`--listen-addr` CLI parameter
when starting the service) Default: ":26258"'
type: string
logConfigMap:
description: '(Optional) LogConfigMap define the config map which
contains log configuration used to send the logs through the proper
Expand Down Expand Up @@ -1389,8 +1400,13 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
sqlAddr:
description: '(Optional) The IP address/hostname and port on which
to listen for SQL connections from clients. Default: ":26257"'
type: string
sqlPort:
description: '(Optional) The SQL Port number Default: 26257'
description: '(Optional) The SQL Port number Default: 26257 Deprecated:
Use SQLAddr instead of SQLPort'
format: int32
type: integer
tlsEnabled:
Expand Down
16 changes: 16 additions & 0 deletions e2e/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestCreateInsecureCluster(t *testing.T) {
WithImage(e2e.MajorVersion).WithClusterLogging("logging-configmap").
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates 3-node insecure cluster",
Expand Down Expand Up @@ -105,6 +108,9 @@ func TestCreatesSecureCluster(t *testing.T) {
WithImage(e2e.MajorVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates 3-node secure cluster",
Expand Down Expand Up @@ -160,6 +166,10 @@ func TestCreateSecureClusterWithInvalidVersion(t *testing.T) {
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
WithImage(testcase.imageVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

if testcase.cockroachVersion != "" {
os.Setenv(relatedImageEnvName, e2e.NonExistentVersion)
builder = builder.WithCockroachDBVersion(testcase.cockroachVersion)
Expand Down Expand Up @@ -221,6 +231,9 @@ func TestCreateSecureClusterWithNonCRDBImage(t *testing.T) {
WithImage(testcase.imageVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

if testcase.cockroachVersion != "" {
os.Setenv(relatedImageEnvName, e2e.InvalidImage)
builder = builder.WithCockroachDBVersion(testcase.cockroachVersion)
Expand Down Expand Up @@ -268,6 +281,9 @@ func TestCreateSecureClusterWithCRDBVersionSet(t *testing.T) {
WithPVDataStore("1Gi").
WithCockroachDBVersion(crdbVersion).WithImageObject(nil)

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

require.NoError(subT, sb.Create(builder.Cr()))
testutil.RequireClusterToBeReadyEventuallyTimeout(subT, sb, builder,
e2e.CreateClusterTimeout)
Expand Down
6 changes: 6 additions & 0 deletions e2e/decommission/decommission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func TestDecommissionFunctionalityWithPrune(t *testing.T) {
WithImage(e2e.MajorVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

testutil.Steps{
{
Name: "creates a 4-node secure cluster and tests db",
Expand Down Expand Up @@ -126,6 +129,9 @@ func TestDecommissionFunctionality(t *testing.T) {
WithImage(e2e.MajorVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

testutil.Steps{
{
Name: "creates a 4-node secure cluster and tests db",
Expand Down
4 changes: 4 additions & 0 deletions e2e/pvcresize/pvcresize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func TestPVCResize(t *testing.T) {
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
WithImage(e2e.MajorVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster db",
Expand Down
15 changes: 15 additions & 0 deletions e2e/upgrades/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func TestUpgradesMajorVersion20_1To20_2(t *testing.T) {
WithImage("cockroachdb/cockroach:v20.1.16").
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster",
Expand Down Expand Up @@ -211,6 +214,9 @@ func TestUpgradesMinorVersionThenRollback(t *testing.T) {
WithImage(e2e.MinorVersion1).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster",
Expand Down Expand Up @@ -276,6 +282,9 @@ func TestUpgradeWithInvalidVersion(t *testing.T) {
WithImage(e2e.MinorVersion1).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster",
Expand Down Expand Up @@ -326,6 +335,9 @@ func TestUpgradeWithInvalidImage(t *testing.T) {
WithImage(e2e.MinorVersion1).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster",
Expand Down Expand Up @@ -376,6 +388,9 @@ func TestUpgradeWithMajorVersionExcludingMajorFeature(t *testing.T) {
WithImage(e2e.SkipFeatureVersion).
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 1-node secure cluster",
Expand Down
8 changes: 8 additions & 0 deletions e2e/upgradessha256/upgradessha256_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func TestUpgradesMinorVersion(t *testing.T) {
WithCockroachDBVersion("v20.2.8").
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()
steps := testutil.Steps{
{
Name: "creates a 3-nodes secure cluster",
Expand Down Expand Up @@ -116,6 +118,9 @@ func TestUpgradesMajorVersion20to21(t *testing.T) {
WithCockroachDBVersion("v20.2.10").
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-nodes secure cluster",
Expand Down Expand Up @@ -170,6 +175,9 @@ func TestUpgradesMajorVersion20_1To20_2(t *testing.T) {
WithCockroachDBVersion("v20.1.16").
WithPVDataStore("1Gi")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "creates a 3-node secure cluster",
Expand Down
6 changes: 6 additions & 0 deletions e2e/versionchecker/versionchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func TestVersionCheckerJobPodPending(t *testing.T) {
corev1.ResourceMemory: apiresource.MustParse("1000T"),
},
})

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()
steps := testutil.Steps{
{
Name: "start an unschedulable job",
Expand Down Expand Up @@ -97,6 +100,9 @@ func TestLoggingAPIValidCheck(t *testing.T) {
WithPVDataStore("32Mi").
WithClusterLogging("logging-configmap")

// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
builder.Cr().Default()

steps := testutil.Steps{
{
Name: "validate the logging API input",
Expand Down
Loading

0 comments on commit 8c47b28

Please sign in to comment.