@@ -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(ctx context.Context, l *logger.Logger, options vm.List
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 g := ctxgroup .WithContext (ctx )
@@ -347,6 +365,17 @@ func CreateCluster(l *logger.Logger, opts []*ClusterCreateOpts) (*cloudcluster.C
347365 // `roachprod.Start` expects nodes/vms to be in sorted order
348366 sort .Sort (c .VMs )
349367
368+ apiClient := centralizedapi .GetCentralizedAPIClient ()
369+ if apiClient .IsEnabled () {
370+ // Use the centralized roachprod service to upsert the cluster registration
371+ // in its final state.
372+ // Upsert is used here because the cluster may already exist in the
373+ // centralized service if the cluster was picked up during a background sync.
374+ if err = apiClient .RegisterClusterUpsert (context .Background (), l , c ); err != nil {
375+ return nil , err
376+ }
377+ }
378+
350379 return c , nil
351380}
352381
@@ -387,6 +416,14 @@ func GrowCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) error
387416 // `roachprod.Start` expects nodes/vms to be in sorted order
388417 sort .Sort (c .VMs )
389418
419+ apiClient := centralizedapi .GetCentralizedAPIClient ()
420+ if apiClient .IsEnabled () {
421+ // Use the centralized roachprod service to create the cluster.
422+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
423+ return err
424+ }
425+ }
426+
390427 return nil
391428}
392429
@@ -418,6 +455,15 @@ func ShrinkCluster(l *logger.Logger, c *cloudcluster.Cluster, numNodes int) erro
418455
419456 // Update the list of VMs in the cluster.
420457 c .VMs = c .VMs [:len (c .VMs )- numNodes ]
458+
459+ apiClient := centralizedapi .GetCentralizedAPIClient ()
460+ if apiClient .IsEnabled () {
461+ // Use the centralized roachprod service to create the cluster.
462+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
463+ return err
464+ }
465+ }
466+
421467 return nil
422468}
423469
@@ -436,7 +482,10 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
436482 publicRecords = append (publicRecords , v .PublicDNS )
437483 }
438484 dnsErr := vm .FanOutDNS (c .VMs , func (p vm.DNSProvider , vms vm.List ) error {
439- publicRecordsErr := p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
485+ var publicRecordsErr error
486+ if ! centralizedapi .GetCentralizedAPIClient ().IsEnabled () {
487+ publicRecordsErr = p .DeletePublicRecordsByName (context .Background (), publicRecords ... )
488+ }
440489 srvRecordsErr := p .DeleteSRVRecordsBySubdomain (context .Background (), c .Name )
441490 return errors .CombineErrors (publicRecordsErr , srvRecordsErr )
442491 })
@@ -453,6 +502,15 @@ func DestroyCluster(l *logger.Logger, c *cloudcluster.Cluster) error {
453502 return p .Delete (l , vms )
454503 })
455504 stopSpinner ()
505+
506+ if clusterErr == nil {
507+ apiClient := centralizedapi .GetCentralizedAPIClient ()
508+ if apiClient .IsEnabled () {
509+ if err := apiClient .RegisterClusterDelete (context .Background (), l , c .Name ); err != nil {
510+ l .Printf ("WARNING: failed to delete cluster %s from centralized service: %s" , c .Name , err )
511+ }
512+ }
513+ }
456514 return errors .CombineErrors (dnsErr , clusterErr )
457515}
458516
@@ -467,5 +525,13 @@ func ExtendCluster(l *logger.Logger, c *cloudcluster.Cluster, extension time.Dur
467525 return err
468526 }
469527 c .Lifetime = newLifetime
528+
529+ apiClient := centralizedapi .GetCentralizedAPIClient ()
530+ if apiClient .IsEnabled () {
531+ // Use the centralized roachprod service to create the cluster.
532+ if err := apiClient .RegisterClusterUpdate (context .Background (), l , c ); err != nil {
533+ return err
534+ }
535+ }
470536 return nil
471537}
0 commit comments