Skip to content

Commit cf1153d

Browse files
authored
feat(bigtable): update admin.go to support instance edition (#14479)
Adding support for new Editions type in admin.go
1 parent 377ac2a commit cf1153d

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

bigtable/admin.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,13 +1370,26 @@ const (
13701370
DEVELOPMENT = InstanceType(btapb.Instance_DEVELOPMENT)
13711371
)
13721372

1373+
// Edition is the edition of the instance.
1374+
type Edition int32
1375+
1376+
const (
1377+
// EditionUnspecified defaults to ENTERPRISE
1378+
EditionUnspecified Edition = Edition(btapb.Instance_EDITION_UNSPECIFIED)
1379+
// Enterprise edition is the default edition.
1380+
Enterprise Edition = Edition(btapb.Instance_ENTERPRISE)
1381+
// EnterprisePlus edition is the edition with higher limits and more features than Enterprise edition.
1382+
EnterprisePlus Edition = Edition(btapb.Instance_ENTERPRISE_PLUS)
1383+
)
1384+
13731385
// InstanceInfo represents information about an instance
13741386
type InstanceInfo struct {
13751387
Name string // name of the instance
13761388
DisplayName string // display name for UIs
13771389
InstanceState InstanceState
13781390
InstanceType InstanceType
13791391
Labels map[string]string
1392+
Edition Edition
13801393
}
13811394

13821395
// InstanceConf contains the information necessary to create an Instance
@@ -1387,6 +1400,7 @@ type InstanceConf struct {
13871400
StorageType StorageType
13881401
InstanceType InstanceType
13891402
Labels map[string]string
1403+
Edition Edition
13901404

13911405
// AutoscalingConfig configures the autoscaling properties on the cluster
13921406
// created with the instance. It is optional.
@@ -1409,6 +1423,7 @@ type InstanceWithClustersConfig struct {
14091423
Clusters []ClusterConfig
14101424
InstanceType InstanceType
14111425
Labels map[string]string
1426+
Edition Edition
14121427
// Tags maps TagKey resource names (e.g., "tagKeys/123") to TagValue
14131428
// resource names (e.g., "tagValues/456") to be associated with the instance.
14141429
Tags map[string]string
@@ -1426,6 +1441,7 @@ func (iac *InstanceAdminClient) CreateInstance(ctx context.Context, conf *Instan
14261441
InstanceType: conf.InstanceType,
14271442
Labels: conf.Labels,
14281443
Tags: conf.Tags,
1444+
Edition: conf.Edition,
14291445
Clusters: []ClusterConfig{
14301446
{
14311447
InstanceID: conf.InstanceId,
@@ -1458,6 +1474,7 @@ func (iac *InstanceAdminClient) CreateInstanceWithClusters(ctx context.Context,
14581474
Type: btapb.Instance_Type(conf.InstanceType),
14591475
Labels: conf.Labels,
14601476
Tags: conf.Tags,
1477+
Edition: btapb.Instance_Edition(conf.Edition),
14611478
},
14621479
Clusters: clusters,
14631480
}
@@ -1493,6 +1510,10 @@ func (iac *InstanceAdminClient) updateInstance(ctx context.Context, conf *Instan
14931510
ireq.Instance.Type = btapb.Instance_Type(conf.InstanceType)
14941511
mask.Paths = append(mask.Paths, "type")
14951512
}
1513+
if conf.Edition != EditionUnspecified {
1514+
ireq.Instance.Edition = btapb.Instance_Edition(conf.Edition)
1515+
mask.Paths = append(mask.Paths, "edition")
1516+
}
14961517
if conf.Labels != nil {
14971518
ireq.Instance.Labels = conf.Labels
14981519
mask.Paths = append(mask.Paths, "labels")
@@ -1601,6 +1622,7 @@ func (iac *InstanceAdminClient) Instances(ctx context.Context) ([]*InstanceInfo,
16011622
InstanceState: InstanceState(i.State),
16021623
InstanceType: InstanceType(i.Type),
16031624
Labels: i.Labels,
1625+
Edition: Edition(i.Edition),
16041626
})
16051627
}
16061628
if len(res.FailedLocations) > 0 {
@@ -1637,6 +1659,7 @@ func (iac *InstanceAdminClient) InstanceInfo(ctx context.Context, instanceID str
16371659
InstanceState: InstanceState(res.State),
16381660
InstanceType: InstanceType(res.Type),
16391661
Labels: res.Labels,
1662+
Edition: Edition(res.Edition),
16401663
}, nil
16411664
}
16421665

bigtable/admin_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,58 @@ func TestInstanceAdmin_CreateInstance_WithAutoscaling(t *testing.T) {
12401240
}
12411241
}
12421242

1243+
func TestInstanceAdmin_CreateInstance_WithEdition(t *testing.T) {
1244+
mock := &mockAdminClock{}
1245+
c := setupClient(t, mock)
1246+
1247+
err := c.CreateInstance(context.Background(), &InstanceConf{
1248+
InstanceId: "myinst",
1249+
DisplayName: "myinst",
1250+
InstanceType: PRODUCTION,
1251+
ClusterId: "mycluster",
1252+
Zone: "us-central1-a",
1253+
StorageType: SSD,
1254+
Edition: EnterprisePlus,
1255+
})
1256+
if err != nil {
1257+
t.Fatalf("CreateInstance failed: %v", err)
1258+
}
1259+
1260+
got := mock.createInstanceReq.Instance.Edition
1261+
want := btapb.Instance_ENTERPRISE_PLUS
1262+
if got != want {
1263+
t.Errorf("got edition %v, want %v", got, want)
1264+
}
1265+
}
1266+
1267+
func TestInstanceAdmin_CreateInstanceWithClusters_WithEdition(t *testing.T) {
1268+
mock := &mockAdminClock{}
1269+
c := setupClient(t, mock)
1270+
1271+
err := c.CreateInstanceWithClusters(context.Background(), &InstanceWithClustersConfig{
1272+
InstanceID: "myinst",
1273+
DisplayName: "myinst",
1274+
InstanceType: PRODUCTION,
1275+
Edition: EnterprisePlus,
1276+
Clusters: []ClusterConfig{
1277+
{
1278+
ClusterID: "mycluster",
1279+
Zone: "us-central1-a",
1280+
StorageType: SSD,
1281+
},
1282+
},
1283+
})
1284+
if err != nil {
1285+
t.Fatalf("CreateInstanceWithClusters failed: %v", err)
1286+
}
1287+
1288+
got := mock.createInstanceReq.Instance.Edition
1289+
want := btapb.Instance_ENTERPRISE_PLUS
1290+
if got != want {
1291+
t.Errorf("got edition %v, want %v", got, want)
1292+
}
1293+
}
1294+
12431295
// Test that CreateInstance with a tags argument completes without error.
12441296
// We cannot verify tag creation itself, as tags are not stored in the Instance metadata
12451297
// and thus are not observable here.

bigtable/integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,7 @@ func TestIntegration_AdminCreateInstance(t *testing.T) {
23782378
InstanceType: DEVELOPMENT,
23792379
Labels: map[string]string{"test-label-key": "test-label-value"},
23802380
Tags: map[string]string{"tagKeys/12345": "tagValues/6789"},
2381+
Edition: Enterprise,
23812382
}
23822383

23832384
// CreateInstance can be flaky; retry before marking as failing.
@@ -2403,6 +2404,9 @@ func TestIntegration_AdminCreateInstance(t *testing.T) {
24032404
if got, want := iInfo.Labels, conf.Labels; !cmp.Equal(got, want) {
24042405
t.Fatalf("Labels: %v, want: %v", got, want)
24052406
}
2407+
if iInfo.Edition != Enterprise {
2408+
t.Fatalf("Instance edition is not Enterprise: %v", iInfo.Edition)
2409+
}
24062410

24072411
// Update everything we can about the instance in one call.
24082412
confWithClusters := &InstanceWithClustersConfig{

0 commit comments

Comments
 (0)