Skip to content

Commit f1bf6cf

Browse files
committed
Add httpAddr, sqlAddr, listenAddr in CrdbCluster API and migrated ports to addresses
1 parent ff902fd commit f1bf6cf

27 files changed

+271
-59
lines changed

apis/v1alpha1/cluster_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,31 @@ type CrdbClusterSpec struct {
4343
// (Optional) The database port (`--listen-addr` CLI parameter when starting the service)
4444
// Default: 26258
4545
// +optional
46+
// Deprecated: Use ListenAddr instead of GRPCPort
4647
GRPCPort *int32 `json:"grpcPort,omitempty"`
48+
// (Optional) The database port (`--listen-addr` CLI parameter when starting the service)
49+
// Default: ":26258"
50+
// +optional
51+
ListenAddr *string `json:"listenAddr,omitempty"`
4752
// (Optional) The web UI port (`--http-addr` CLI parameter when starting the service)
4853
// Default: 8080
4954
// +optional
55+
// Deprecated: Use HTTPAddr instead of HTTPPort
5056
HTTPPort *int32 `json:"httpPort,omitempty"`
57+
// (Optional) The IP address/hostname and port on which to listen for DB Console HTTP requests.
58+
// (`--http-addr` CLI parameter when starting the service)
59+
// Default: ":8080"
60+
// +optional
61+
HTTPAddr *string `json:"httpAddr,omitempty"`
5162
// (Optional) The SQL Port number
5263
// Default: 26257
5364
// +optional
65+
// Deprecated: Use SQLAddr instead of SQLPort
5466
SQLPort *int32 `json:"sqlPort,omitempty"`
67+
// (Optional) The IP address/hostname and port on which to listen for SQL connections from clients.
68+
// Default: ":26257"
69+
// +optional
70+
SQLAddr *string `json:"sqlAddr,omitempty"`
5571
// (Optional) TLSEnabled determines if TLS is enabled for your CockroachDB Cluster
5672
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="TLS Enabled",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
5773
// +optional

apis/v1alpha1/webhook.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929
)
3030

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

62-
if r.Spec.GRPCPort == nil {
63-
r.Spec.GRPCPort = &DefaultGRPCPort
62+
if r.Spec.GRPCPort == nil && r.Spec.ListenAddr == nil {
63+
r.Spec.ListenAddr = &DefaultGRPCAddr
64+
} else if r.Spec.GRPCPort != nil && r.Spec.ListenAddr == nil {
65+
listenAddr := fmt.Sprintf(":%d", *r.Spec.GRPCPort)
66+
r.Spec.ListenAddr = &listenAddr
67+
r.Spec.GRPCPort = nil
6468
}
6569

66-
if r.Spec.SQLPort == nil {
67-
r.Spec.SQLPort = &DefaultSQLPort
70+
if r.Spec.SQLPort == nil && r.Spec.SQLAddr == nil {
71+
r.Spec.SQLAddr = &DefaultSQLAddr
72+
} else if r.Spec.SQLPort != nil && r.Spec.SQLAddr == nil {
73+
sqlAddr := fmt.Sprintf(":%d", *r.Spec.SQLPort)
74+
r.Spec.SQLAddr = &sqlAddr
75+
r.Spec.SQLPort = nil
6876
}
6977

70-
if r.Spec.HTTPPort == nil {
71-
r.Spec.HTTPPort = &DefaultHTTPPort
78+
if r.Spec.HTTPPort == nil && r.Spec.HTTPAddr == nil {
79+
r.Spec.HTTPAddr = &DefaultHTTPAddr
80+
} else if r.Spec.HTTPPort != nil && r.Spec.HTTPAddr == nil {
81+
httpAddr := fmt.Sprintf(":%d", *r.Spec.HTTPPort)
82+
r.Spec.HTTPAddr = &httpAddr
83+
r.Spec.HTTPPort = nil
7284
}
7385

7486
if r.Spec.MaxUnavailable == nil && r.Spec.MinAvailable == nil {

apis/v1alpha1/webhook_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func TestCrdbClusterDefault(t *testing.T) {
3636
maxUnavailable := int32(1)
3737
policy := v1.PullIfNotPresent
3838
expected := CrdbClusterSpec{
39-
GRPCPort: &DefaultGRPCPort,
40-
HTTPPort: &DefaultHTTPPort,
41-
SQLPort: &DefaultSQLPort,
39+
ListenAddr: &DefaultGRPCAddr,
40+
SQLAddr: &DefaultSQLAddr,
41+
HTTPAddr: &DefaultHTTPAddr,
4242
MaxUnavailable: &maxUnavailable,
4343
Image: &PodImage{PullPolicyName: &policy},
4444
}

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,19 @@ spec:
10871087
type: object
10881088
grpcPort:
10891089
description: '(Optional) The database port (`--listen-addr` CLI parameter
1090-
when starting the service) Default: 26258'
1090+
when starting the service) Default: 26258 Deprecated: Use ListenAddr
1091+
instead of GRPCPort'
10911092
format: int32
10921093
type: integer
1094+
httpAddr:
1095+
description: '(Optional) The IP address/hostname and port on which
1096+
to listen for DB Console HTTP requests. (`--http-addr` CLI parameter
1097+
when starting the service) Default: ":8080"'
1098+
type: string
10931099
httpPort:
10941100
description: '(Optional) The web UI port (`--http-addr` CLI parameter
1095-
when starting the service) Default: 8080'
1101+
when starting the service) Default: 8080 Deprecated: Use HTTPAddr
1102+
instead of HTTPPort'
10961103
format: int32
10971104
type: integer
10981105
image:
@@ -1214,6 +1221,10 @@ spec:
12141221
- host
12151222
type: object
12161223
type: object
1224+
listenAddr:
1225+
description: '(Optional) The database port (`--listen-addr` CLI parameter
1226+
when starting the service) Default: ":26258"'
1227+
type: string
12171228
logConfigMap:
12181229
description: '(Optional) LogConfigMap define the config map which
12191230
contains log configuration used to send the logs through the proper
@@ -1389,8 +1400,13 @@ spec:
13891400
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
13901401
type: object
13911402
type: object
1403+
sqlAddr:
1404+
description: '(Optional) The IP address/hostname and port on which
1405+
to listen for SQL connections from clients. Default: ":26257"'
1406+
type: string
13921407
sqlPort:
1393-
description: '(Optional) The SQL Port number Default: 26257'
1408+
description: '(Optional) The SQL Port number Default: 26257 Deprecated:
1409+
Use SQLAddr instead of SQLPort'
13941410
format: int32
13951411
type: integer
13961412
tlsEnabled:

e2e/create/create_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func TestCreateInsecureCluster(t *testing.T) {
6565
WithImage(e2e.MajorVersion).WithClusterLogging("logging-configmap").
6666
WithPVDataStore("1Gi")
6767

68+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
69+
builder.Cr().Default()
70+
6871
steps := testutil.Steps{
6972
{
7073
Name: "creates 3-node insecure cluster",
@@ -105,6 +108,9 @@ func TestCreatesSecureCluster(t *testing.T) {
105108
WithImage(e2e.MajorVersion).
106109
WithPVDataStore("1Gi")
107110

111+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
112+
builder.Cr().Default()
113+
108114
steps := testutil.Steps{
109115
{
110116
Name: "creates 3-node secure cluster",
@@ -160,6 +166,10 @@ func TestCreateSecureClusterWithInvalidVersion(t *testing.T) {
160166
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
161167
WithImage(testcase.imageVersion).
162168
WithPVDataStore("1Gi")
169+
170+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
171+
builder.Cr().Default()
172+
163173
if testcase.cockroachVersion != "" {
164174
os.Setenv(relatedImageEnvName, e2e.NonExistentVersion)
165175
builder = builder.WithCockroachDBVersion(testcase.cockroachVersion)
@@ -221,6 +231,9 @@ func TestCreateSecureClusterWithNonCRDBImage(t *testing.T) {
221231
WithImage(testcase.imageVersion).
222232
WithPVDataStore("1Gi")
223233

234+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
235+
builder.Cr().Default()
236+
224237
if testcase.cockroachVersion != "" {
225238
os.Setenv(relatedImageEnvName, e2e.InvalidImage)
226239
builder = builder.WithCockroachDBVersion(testcase.cockroachVersion)
@@ -268,6 +281,9 @@ func TestCreateSecureClusterWithCRDBVersionSet(t *testing.T) {
268281
WithPVDataStore("1Gi").
269282
WithCockroachDBVersion(crdbVersion).WithImageObject(nil)
270283

284+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
285+
builder.Cr().Default()
286+
271287
require.NoError(subT, sb.Create(builder.Cr()))
272288
testutil.RequireClusterToBeReadyEventuallyTimeout(subT, sb, builder,
273289
e2e.CreateClusterTimeout)

e2e/decommission/decommission_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func TestDecommissionFunctionalityWithPrune(t *testing.T) {
6464
WithImage(e2e.MajorVersion).
6565
WithPVDataStore("1Gi")
6666

67+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
68+
builder.Cr().Default()
69+
6770
testutil.Steps{
6871
{
6972
Name: "creates a 4-node secure cluster and tests db",
@@ -126,6 +129,9 @@ func TestDecommissionFunctionality(t *testing.T) {
126129
WithImage(e2e.MajorVersion).
127130
WithPVDataStore("1Gi")
128131

132+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
133+
builder.Cr().Default()
134+
129135
testutil.Steps{
130136
{
131137
Name: "creates a 4-node secure cluster and tests db",

e2e/pvcresize/pvcresize_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func TestPVCResize(t *testing.T) {
5656
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
5757
WithImage(e2e.MajorVersion).
5858
WithPVDataStore("1Gi")
59+
60+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
61+
builder.Cr().Default()
62+
5963
steps := testutil.Steps{
6064
{
6165
Name: "creates a 3-node secure cluster db",

e2e/upgrades/upgrades_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func TestUpgradesMajorVersion20_1To20_2(t *testing.T) {
154154
WithImage("cockroachdb/cockroach:v20.1.16").
155155
WithPVDataStore("1Gi")
156156

157+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
158+
builder.Cr().Default()
159+
157160
steps := testutil.Steps{
158161
{
159162
Name: "creates a 3-node secure cluster",
@@ -211,6 +214,9 @@ func TestUpgradesMinorVersionThenRollback(t *testing.T) {
211214
WithImage(e2e.MinorVersion1).
212215
WithPVDataStore("1Gi")
213216

217+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
218+
builder.Cr().Default()
219+
214220
steps := testutil.Steps{
215221
{
216222
Name: "creates a 3-node secure cluster",
@@ -276,6 +282,9 @@ func TestUpgradeWithInvalidVersion(t *testing.T) {
276282
WithImage(e2e.MinorVersion1).
277283
WithPVDataStore("1Gi")
278284

285+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
286+
builder.Cr().Default()
287+
279288
steps := testutil.Steps{
280289
{
281290
Name: "creates a 3-node secure cluster",
@@ -326,6 +335,9 @@ func TestUpgradeWithInvalidImage(t *testing.T) {
326335
WithImage(e2e.MinorVersion1).
327336
WithPVDataStore("1Gi")
328337

338+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
339+
builder.Cr().Default()
340+
329341
steps := testutil.Steps{
330342
{
331343
Name: "creates a 3-node secure cluster",
@@ -376,6 +388,9 @@ func TestUpgradeWithMajorVersionExcludingMajorFeature(t *testing.T) {
376388
WithImage(e2e.SkipFeatureVersion).
377389
WithPVDataStore("1Gi")
378390

391+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
392+
builder.Cr().Default()
393+
379394
steps := testutil.Steps{
380395
{
381396
Name: "creates a 1-node secure cluster",

e2e/upgradessha256/upgradessha256_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func TestUpgradesMinorVersion(t *testing.T) {
5858
WithCockroachDBVersion("v20.2.8").
5959
WithPVDataStore("1Gi")
6060

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

121+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
122+
builder.Cr().Default()
123+
119124
steps := testutil.Steps{
120125
{
121126
Name: "creates a 3-nodes secure cluster",
@@ -170,6 +175,9 @@ func TestUpgradesMajorVersion20_1To20_2(t *testing.T) {
170175
WithCockroachDBVersion("v20.1.16").
171176
WithPVDataStore("1Gi")
172177

178+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
179+
builder.Cr().Default()
180+
173181
steps := testutil.Steps{
174182
{
175183
Name: "creates a 3-node secure cluster",

e2e/versionchecker/versionchecker_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func TestVersionCheckerJobPodPending(t *testing.T) {
6262
corev1.ResourceMemory: apiresource.MustParse("1000T"),
6363
},
6464
})
65+
66+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
67+
builder.Cr().Default()
6568
steps := testutil.Steps{
6669
{
6770
Name: "start an unschedulable job",
@@ -97,6 +100,9 @@ func TestLoggingAPIValidCheck(t *testing.T) {
97100
WithPVDataStore("32Mi").
98101
WithClusterLogging("logging-configmap")
99102

103+
// This defaulting is done by webhook mutation config, but in tests we are doing it manually.
104+
builder.Cr().Default()
105+
100106
steps := testutil.Steps{
101107
{
102108
Name: "validate the logging API input",

0 commit comments

Comments
 (0)