@@ -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
@@ -268,6 +286,14 @@ func CreateCluster(l *logger.Logger, opts []*ClusterCreateOpts) (*cloudcluster.C
268286 Lifetime : opts [0 ].CreateOpts .Lifetime ,
269287 }
270288
289+ apiClient := centralizedapi .GetCentralizedAPIClient ()
290+ if apiClient .IsEnabled () {
291+ // Register the new cluster with the centralized roachprod service.
292+ if err := apiClient .RegisterCluster (context .Background (), l , c ); err != nil {
293+ return nil , err
294+ }
295+ }
296+
271297 // Keep track of the total number of nodes created, as we append all cluster names
272298 // with the node count.
273299 var nodesCreated int
@@ -330,6 +356,14 @@ func CreateCluster(l *logger.Logger, opts []*ClusterCreateOpts) (*cloudcluster.C
330356 // `roachprod.Start` expects nodes/vms to be in sorted order
331357 sort .Sort (c .VMs )
332358
359+ if apiClient .IsEnabled () {
360+ // Use the centralized roachprod service to register the final state
361+ // of the cluster.
362+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
363+ return nil , err
364+ }
365+ }
366+
333367 return c , nil
334368}
335369
@@ -370,6 +404,14 @@ func GrowCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) error
370404 // `roachprod.Start` expects nodes/vms to be in sorted order
371405 sort .Sort (c .VMs )
372406
407+ apiClient := centralizedapi .GetCentralizedAPIClient ()
408+ if apiClient .IsEnabled () {
409+ // Use the centralized roachprod service to create the cluster.
410+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
411+ return err
412+ }
413+ }
414+
373415 return nil
374416}
375417
@@ -401,6 +443,15 @@ func ShrinkCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) erro
401443
402444 // Update the list of VMs in the cluster.
403445 c .VMs = c .VMs [:len (c .VMs )- numNodes ]
446+
447+ apiClient := centralizedapi .GetCentralizedAPIClient ()
448+ if apiClient .IsEnabled () {
449+ // Use the centralized roachprod service to create the cluster.
450+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
451+ return err
452+ }
453+ }
454+
404455 return nil
405456}
406457
@@ -419,7 +470,10 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
419470 publicRecords = append (publicRecords , v .PublicDNS )
420471 }
421472 dnsErr := vm .FanOutDNS (c .VMs , func (p vm.DNSProvider , vms vm.List ) error {
422- publicRecordsErr := p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
473+ var publicRecordsErr error
474+ if ! centralizedapi .GetCentralizedAPIClient ().IsEnabled () {
475+ publicRecordsErr = p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
476+ }
423477 srvRecordsErr := p .DeleteSRVRecordsBySubdomain (context .Background (), c .Name )
424478 return errors .CombineErrors (publicRecordsErr , srvRecordsErr )
425479 })
@@ -436,6 +490,15 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
436490 return p .Delete (l , vms )
437491 })
438492 stopSpinner ()
493+
494+ if clusterErr == nil {
495+ apiClient := centralizedapi .GetCentralizedAPIClient ()
496+ if apiClient .IsEnabled () {
497+ if err := apiClient .RegisterClusterDelete (context .Background (), l , c .Name ); err != nil {
498+ l .Printf ("WARNING: failed to delete cluster %s from centralized service: %s" , c .Name , err )
499+ }
500+ }
501+ }
439502 return errors .CombineErrors (dnsErr , clusterErr )
440503}
441504
@@ -450,5 +513,13 @@ func ExtendCluster(l *logger.Logger, c *cloudcluster.Cluster, extension time.Dur
450513 return err
451514 }
452515 c .Lifetime = newLifetime
516+
517+ apiClient := centralizedapi .GetCentralizedAPIClient ()
518+ if apiClient .IsEnabled () {
519+ // Use the centralized roachprod service to create the cluster.
520+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
521+ return err
522+ }
523+ }
453524 return nil
454525}
0 commit comments