diff --git a/pkg/roachprod/install/cockroach.go b/pkg/roachprod/install/cockroach.go index 089dd8ca6b35..ab6ea0e65794 100644 --- a/pkg/roachprod/install/cockroach.go +++ b/pkg/roachprod/install/cockroach.go @@ -13,7 +13,7 @@ package install import ( "context" _ "embed" // required for go:embed - "encoding/json" + "encoding/csv" "fmt" "net/url" "os" @@ -1255,7 +1255,7 @@ func (c *SyncedCluster) upsertVirtualClusterMetadata( ) (int, error) { runSQL := func(stmt string) (string, error) { results, err := startOpts.KVCluster.ExecSQL(ctx, l, startOpts.KVCluster.Nodes[:1], "", 0, []string{ - "--format", "json", "-e", stmt, + "--format", "csv", "-e", stmt, }) if err != nil { return "", err @@ -1268,10 +1268,6 @@ func (c *SyncedCluster) upsertVirtualClusterMetadata( } virtualClusterIDByName := func(name string) (int, error) { - type tenantRow struct { - ID string `json:"id"` - } - query := fmt.Sprintf( "SELECT id FROM system.tenants WHERE name = '%s'", startOpts.VirtualClusterName, ) @@ -1281,16 +1277,17 @@ func (c *SyncedCluster) upsertVirtualClusterMetadata( return -1, err } - var tenants []tenantRow - if err := json.Unmarshal([]byte(existsOut), &tenants); err != nil { - return -1, fmt.Errorf("failed to unmarshal system.tenants output: %w\n%s", err, existsOut) + rows, err := csv.NewReader(strings.NewReader(existsOut)).ReadAll() + if err != nil { + return -1, fmt.Errorf("failed to parse system.tenants output: %w\n%s", err, existsOut) } - if len(tenants) == 0 { + records := rows[1:] // skip header + if len(records) == 0 { return -1, nil } - n, err := strconv.Atoi(tenants[0].ID) + n, err := strconv.Atoi(records[0][0]) if err != nil { return -1, fmt.Errorf("failed to parse virtual cluster ID: %w", err) }