From 884043eb3bba041bd2b746175b1f1c065cb837da Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Wed, 9 Oct 2024 11:08:07 -0700 Subject: [PATCH] more local cluster --- cmd/nodecmd/destroy.go | 3 +++ cmd/nodecmd/list.go | 2 ++ cmd/nodecmd/local.go | 34 ++++++++++++++++++---------------- go.mod | 2 +- go.sum | 4 ++-- pkg/models/clusters_config.go | 7 +++++-- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cmd/nodecmd/destroy.go b/cmd/nodecmd/destroy.go index 9153dc0f3..f62f11fa3 100644 --- a/cmd/nodecmd/destroy.go +++ b/cmd/nodecmd/destroy.go @@ -355,6 +355,9 @@ func getClusterNodes(clusterName string) ([]string, error) { if err != nil { return nil, err } + if clustersConfig.Clusters[clusterName].Local { + return []string{fmt.Sprintf("local: %s", clusterName)}, nil + } clusterNodes := clustersConfig.Clusters[clusterName].Nodes if len(clusterNodes) == 0 { return nil, fmt.Errorf("no nodes found in cluster %s", clusterName) diff --git a/cmd/nodecmd/list.go b/cmd/nodecmd/list.go index 16588681d..130f70edf 100644 --- a/cmd/nodecmd/list.go +++ b/cmd/nodecmd/list.go @@ -61,6 +61,8 @@ func list(_ *cobra.Command, _ []string) error { } if clusterConf.External { ux.Logger.PrintToUser("cluster %q (%s) EXTERNAL", clusterName, clusterConf.Network.Kind.String()) + } else if clusterConf.Local { + ux.Logger.PrintToUser("cluster %q (%s) LOCAL", clusterName, clusterConf.Network.Kind.String()) } else { ux.Logger.PrintToUser("Cluster %q (%s)", clusterName, clusterConf.Network.Kind.String()) } diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index e57cc26e7..75213fc44 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -165,15 +165,8 @@ func localStartNode(_ *cobra.Command, args []string) error { rootDir := app.GetLocalDir(clusterName) logDir := filepath.Join(rootDir, "logs") pluginDir := app.GetPluginsDir() - - cli, err := binutils.NewGRPCClient() - if err != nil { - return err - } - ctx, cancel := utils.GetANRContext() defer cancel() - if localClusterDataExists(clusterName) { ux.Logger.GreenCheckmarkToUser("Local cluster %s found. Booting up...", clusterName) } else { @@ -243,16 +236,13 @@ func localStartNode(_ *cobra.Command, args []string) error { } sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") - if err := sd.StartServer(); err != nil { return err } - _, avalancheGoBinPath, err := sd.SetupLocalEnv() if err != nil { return err } - // make sure rootDir exists if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) @@ -292,12 +282,19 @@ func localStartNode(_ *cobra.Command, args []string) error { if bootstrapIPs != nil { anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - - ux.Logger.PrintToUser("Booting Network. Wait until healthy...") + spinSession := ux.NewUserSpinner() + spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") + cli, err := binutils.NewGRPCClient() + if err != nil { + ux.SpinFailWithError(spinner, "", err) + return err + } if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { + ux.SpinFailWithError(spinner, "", err) return fmt.Errorf("failed to start local avalanchego: %w", err) } + ux.SpinComplete(spinner) // save snapshot after successful start if _, err := cli.SaveSnapshot( ctx, @@ -311,6 +308,10 @@ func localStartNode(_ *cobra.Command, args []string) error { return err } } + cli, err := binutils.NewGRPCClient() + if err != nil { + return err + } loadSnapshotOpts := []client.OpOption{ client.WithRootDataDir(rootDir), @@ -338,9 +339,10 @@ func localStartNode(_ *cobra.Command, args []string) error { } func localStopNode(_ *cobra.Command, args []string) error { + // todo: support only one local node and detect what cluster to stop clusterName := args[0] if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { - return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) + return fmt.Errorf("local node %q is not found", clusterName) } cli, err := binutils.NewGRPCClient( binutils.WithAvoidRPCVersionCheck(true), @@ -373,20 +375,20 @@ func localStopNode(_ *cobra.Command, args []string) error { if _, err = cli.Stop(ctx); err != nil { return fmt.Errorf("failed to stop avalanchego: %w", err) } - + ux.Logger.GreenCheckmarkToUser("avalanchego stopped. State saved for %s", clusterName) return nil } func localDestroyNode(_ *cobra.Command, args []string) error { clusterName := args[0] if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { - return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) + return fmt.Errorf("local cluster %q not found", clusterName) } if err := cleanupLocalNode(clusterName); err != nil { return fmt.Errorf("failed to cleanup local node: %w", err) } - ux.Logger.PrintToUser("Local node cleaned up.") + ux.Logger.GreenCheckmarkToUser("Local node %s cleaned up.", clusterName) return nil } diff --git a/go.mod b/go.mod index f07dfa284..72318018a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 8124f430c..8c65a59dc 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 h1:wD/rBr+QKztcKtRtBNqPjzMhwcxnVcuJ3GT62DdgS2Q= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a h1:xd2RUTW9w34+V6yI7zWfByHZ8y5CeXhvHK+nAJ9FCbI= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= diff --git a/pkg/models/clusters_config.go b/pkg/models/clusters_config.go index a789d4771..02d5b11b2 100644 --- a/pkg/models/clusters_config.go +++ b/pkg/models/clusters_config.go @@ -54,14 +54,17 @@ func (cc *ClusterConfig) GetValidatorHosts(hosts []*Host) []*Host { } func (cc *ClusterConfig) IsAPIHost(hostCloudID string) bool { - return slices.Contains(cc.APINodes, hostCloudID) + return cc.Local || slices.Contains(cc.APINodes, hostCloudID) } func (cc *ClusterConfig) IsAvalancheGoHost(hostCloudID string) bool { - return slices.Contains(cc.Nodes, hostCloudID) + return cc.Local || slices.Contains(cc.Nodes, hostCloudID) } func (cc *ClusterConfig) GetCloudIDs() []string { + if cc.Local { + return nil + } r := cc.Nodes if cc.MonitoringInstance != "" { r = append(r, cc.MonitoringInstance)