@@ -11,6 +11,8 @@ import (
1111 "sort"
1212 "time"
1313
14+ roachprodcentralized "github.com/cockroachdb/cockroach/pkg/cmd/roachprod-centralized/client"
15+ "github.com/cockroachdb/cockroach/pkg/roachprod/centralizedapi"
1416 cloudcluster "github.com/cockroachdb/cockroach/pkg/roachprod/cloud/types"
1517 "github.com/cockroachdb/cockroach/pkg/roachprod/logger"
1618 "github.com/cockroachdb/cockroach/pkg/roachprod/ui"
@@ -140,6 +142,22 @@ func (c *Cloud) ListCloud(l *logger.Logger, options vm.ListOptions) error {
140142
141143 providers := append (c .providers , c .localProviders ... )
142144
145+ apiClient := centralizedapi .GetCentralizedAPIClient ()
146+ if apiClient .IsEnabled () {
147+ // Use the centralized roachprod service to list clusters.
148+ response , err := apiClient .ListClusters (context .Background (), l , roachprodcentralized.ListClustersOptions {})
149+ if err != nil {
150+ l .Errorf ("Error listing clusters using the centralized API: %s" , err )
151+ } else {
152+ c .Clusters = response .Clusters
153+ c .BadInstances = response .BadInstances
154+
155+ // Remote providers are already listed by the centralized service,
156+ // so only use local providers in the local listing.
157+ providers = c .localProviders
158+ }
159+ }
160+
143161 // List all VMs across all providers in parallel.
144162 providerVMs := make (map [string ]vm.List )
145163 var g errgroup.Group
@@ -276,6 +294,14 @@ func CreateCluster(l *logger.Logger, opts []*ClusterCreateOpts) (*cloudcluster.C
276294 Lifetime : opts [0 ].CreateOpts .Lifetime ,
277295 }
278296
297+ apiClient := centralizedapi .GetCentralizedAPIClient ()
298+ if apiClient .IsEnabled () {
299+ // Register the new cluster with the centralized roachprod service.
300+ if err := apiClient .RegisterCluster (context .Background (), l , c ); err != nil {
301+ return nil , err
302+ }
303+ }
304+
279305 // Keep track of the total number of nodes created, as we append all cluster names
280306 // with the node count.
281307 var nodesCreated int
@@ -338,6 +364,14 @@ func CreateCluster(l *logger.Logger, opts []*ClusterCreateOpts) (*cloudcluster.C
338364 // `roachprod.Start` expects nodes/vms to be in sorted order
339365 sort .Sort (c .VMs )
340366
367+ if apiClient .IsEnabled () {
368+ // Use the centralized roachprod service to register the final state
369+ // of the cluster.
370+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
371+ return nil , err
372+ }
373+ }
374+
341375 return c , nil
342376}
343377
@@ -378,6 +412,14 @@ func GrowCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) error
378412 // `roachprod.Start` expects nodes/vms to be in sorted order
379413 sort .Sort (c .VMs )
380414
415+ apiClient := centralizedapi .GetCentralizedAPIClient ()
416+ if apiClient .IsEnabled () {
417+ // Use the centralized roachprod service to create the cluster.
418+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
419+ return err
420+ }
421+ }
422+
381423 return nil
382424}
383425
@@ -409,6 +451,15 @@ func ShrinkCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) erro
409451
410452 // Update the list of VMs in the cluster.
411453 c .VMs = c .VMs [:len (c .VMs )- numNodes ]
454+
455+ apiClient := centralizedapi .GetCentralizedAPIClient ()
456+ if apiClient .IsEnabled () {
457+ // Use the centralized roachprod service to create the cluster.
458+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
459+ return err
460+ }
461+ }
462+
412463 return nil
413464}
414465
@@ -427,7 +478,10 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
427478 publicRecords = append (publicRecords , v .PublicDNS )
428479 }
429480 dnsErr := vm .FanOutDNS (c .VMs , func (p vm.DNSProvider , vms vm.List ) error {
430- publicRecordsErr := p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
481+ var publicRecordsErr error
482+ if ! centralizedapi .GetCentralizedAPIClient ().IsEnabled () {
483+ publicRecordsErr = p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
484+ }
431485 srvRecordsErr := p .DeleteSRVRecordsBySubdomain (context .Background (), c .Name )
432486 return errors .CombineErrors (publicRecordsErr , srvRecordsErr )
433487 })
@@ -444,6 +498,15 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
444498 return p .Delete (l , vms )
445499 })
446500 stopSpinner ()
501+
502+ if clusterErr == nil {
503+ apiClient := centralizedapi .GetCentralizedAPIClient ()
504+ if apiClient .IsEnabled () {
505+ if err := apiClient .RegisterClusterDelete (context .Background (), l , c .Name ); err != nil {
506+ l .Printf ("WARNING: failed to delete cluster %s from centralized service: %s" , c .Name , err )
507+ }
508+ }
509+ }
447510 return errors .CombineErrors (dnsErr , clusterErr )
448511}
449512
@@ -458,5 +521,13 @@ func ExtendCluster(l *logger.Logger, c *cloudcluster.Cluster, extension time.Dur
458521 return err
459522 }
460523 c .Lifetime = newLifetime
524+
525+ apiClient := centralizedapi .GetCentralizedAPIClient ()
526+ if apiClient .IsEnabled () {
527+ // Use the centralized roachprod service to create the cluster.
528+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
529+ return err
530+ }
531+ }
461532 return nil
462533}
0 commit comments