Skip to content

Commit 1bce843

Browse files
authored
feat(bigtable): Add support for creating Instance with tags (#13459)
1 parent 5ea1f5f commit 1bce843

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

bigtable/admin.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,10 @@ type InstanceConf struct {
13841384
// latency and more throughput by removing node boundaries. It is optional,
13851385
// with the default being 1X.
13861386
NodeScalingFactor NodeScalingFactor
1387+
1388+
// Tags maps TagKey resource names (e.g., "tagKeys/123") to TagValue
1389+
// resource names (e.g., "tagValues/456") to be associated with the instance.
1390+
Tags map[string]string
13871391
}
13881392

13891393
// InstanceWithClustersConfig contains the information necessary to create an Instance
@@ -1392,6 +1396,9 @@ type InstanceWithClustersConfig struct {
13921396
Clusters []ClusterConfig
13931397
InstanceType InstanceType
13941398
Labels map[string]string
1399+
// Tags maps TagKey resource names (e.g., "tagKeys/123") to TagValue
1400+
// resource names (e.g., "tagValues/456") to be associated with the instance.
1401+
Tags map[string]string
13951402
}
13961403

13971404
var instanceNameRegexp = regexp.MustCompile(`^projects/([^/]+)/instances/([a-z][-a-z0-9]*)$`)
@@ -1405,6 +1412,7 @@ func (iac *InstanceAdminClient) CreateInstance(ctx context.Context, conf *Instan
14051412
DisplayName: conf.DisplayName,
14061413
InstanceType: conf.InstanceType,
14071414
Labels: conf.Labels,
1415+
Tags: conf.Tags,
14081416
Clusters: []ClusterConfig{
14091417
{
14101418
InstanceID: conf.InstanceId,
@@ -1436,6 +1444,7 @@ func (iac *InstanceAdminClient) CreateInstanceWithClusters(ctx context.Context,
14361444
DisplayName: conf.DisplayName,
14371445
Type: btapb.Instance_Type(conf.InstanceType),
14381446
Labels: conf.Labels,
1447+
Tags: conf.Tags,
14391448
},
14401449
Clusters: clusters,
14411450
}

bigtable/admin_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,27 @@ func TestInstanceAdmin_CreateInstance_WithAutoscaling(t *testing.T) {
12231223
}
12241224
}
12251225

1226+
// Test that CreateInstance with a tags argument completes without error.
1227+
// We cannot verify tag creation itself, as tags are not stored in the Instance metadata
1228+
// and thus are not observable here.
1229+
func TestInstanceAdmin_CreateInstance_WithTags(t *testing.T) {
1230+
mock := &mockAdminClock{}
1231+
c := setupClient(t, mock)
1232+
1233+
err := c.CreateInstance(context.Background(), &InstanceConf{
1234+
InstanceId: "myinst",
1235+
DisplayName: "myinst",
1236+
InstanceType: PRODUCTION,
1237+
ClusterId: "mycluster",
1238+
Zone: "us-central1-a",
1239+
StorageType: SSD,
1240+
Tags: map[string]string{"tagKeys/123": "tagValues/456"},
1241+
})
1242+
if err != nil {
1243+
t.Fatalf("CreateInstance failed: %v", err)
1244+
}
1245+
}
1246+
12261247
func TestInstanceAdmin_CreateInstanceWithClusters_WithAutoscaling(t *testing.T) {
12271248
mock := &mockAdminClock{}
12281249
c := setupClient(t, mock)

bigtable/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,7 @@ func TestIntegration_AdminCreateInstance(t *testing.T) {
22692269
Zone: instanceToCreateZone,
22702270
InstanceType: DEVELOPMENT,
22712271
Labels: map[string]string{"test-label-key": "test-label-value"},
2272+
Tags: map[string]string{"tagKeys/12345": "tagValues/6789"},
22722273
}
22732274

22742275
// CreateInstance can be flaky; retry before marking as failing.
@@ -2297,6 +2298,7 @@ func TestIntegration_AdminCreateInstance(t *testing.T) {
22972298
DisplayName: "new display name",
22982299
InstanceType: PRODUCTION,
22992300
Labels: map[string]string{"new-label-key": "new-label-value"},
2301+
Tags: map[string]string{"tagKeys/12345": "tagValues/6789"},
23002302
Clusters: []ClusterConfig{
23012303
{ClusterID: clusterID, NumNodes: 5},
23022304
},

0 commit comments

Comments
 (0)