Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node funder #353

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/beekeeper/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func (c *command) initCheckCmd() (err error) {
)

if metricsEnabled {
metricsPusher, cleanup = newMetricsPusher(c.globalConfig.GetString(optionNameMetricsPusherAddress), cfgCluster.GetNamespace(), c.logger)
metricsPusher, cleanup = newMetricsPusher(c.globalConfig.GetString(optionNameMetricsPusherAddress), cfgCluster.GetNamespace(), c.log)
// cleanup executes when the calling context terminates
defer cleanup()
}

// logger metrics
if l, ok := c.logger.(metrics.Reporter); ok && metricsEnabled {
if l, ok := c.log.(metrics.Reporter); ok && metricsEnabled {
metrics.RegisterCollectors(metricsPusher, l.Report()...)
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (c *command) initCheckCmd() (err error) {
}

// create check
chk := check.NewAction(c.logger)
chk := check.NewAction(c.log)
if r, ok := chk.(metrics.Reporter); ok && metricsEnabled {
metrics.RegisterCollectors(metricsPusher, r.Report()...)
}
Expand All @@ -116,7 +116,7 @@ func (c *command) initCheckCmd() (err error) {
defer cancel()
}

c.logger.Infof("running check: %s", checkName)
c.log.Infof("running check: %s", checkName)

ch := make(chan error, 1)
go func() {
Expand All @@ -135,7 +135,7 @@ func (c *command) initCheckCmd() (err error) {
if err != nil {
return fmt.Errorf("running check %s: %w", checkName, err)
}
c.logger.Infof("%s check completed successfully", checkName)
c.log.Infof("%s check completed successfully", checkName)
}
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/beekeeper/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func (c *command) deleteCluster(ctx context.Context, clusterName string, cfg *co
clusterOptions.K8SClient = c.k8sClient
clusterOptions.SwapClient = c.swapClient

cluster := orchestrationK8S.NewCluster(clusterConfig.GetName(), clusterOptions, c.logger)
cluster := orchestrationK8S.NewCluster(clusterConfig.GetName(), clusterOptions, c.log)

// delete node groups
for ng, v := range clusterConfig.GetNodeGroups() {
c.logger.Infof("deleting %s node group", ng)
c.log.Infof("deleting %s node group", ng)
ngConfig, ok := cfg.NodeGroups[v.Config]
if !ok {
return fmt.Errorf("node group profile %s not defined", v.Config)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *command) setupCluster(ctx context.Context, clusterName string, cfg *con
clusterOptions.K8SClient = c.k8sClient
clusterOptions.SwapClient = c.swapClient

cluster = orchestrationK8S.NewCluster(clusterConfig.GetName(), clusterOptions, c.logger)
cluster = orchestrationK8S.NewCluster(clusterConfig.GetName(), clusterOptions, c.log)
bootnodes := ""

errGroup := new(errgroup.Group)
Expand Down
16 changes: 8 additions & 8 deletions cmd/beekeeper/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type command struct {
k8sClient *k8s.Client
// swap client
swapClient swap.Client
// logger
logger logging.Logger
// log
log logging.Logger
}

type option func(*command)
Expand Down Expand Up @@ -194,11 +194,11 @@ func (c *command) initConfig() (err error) {
// init logger
verbosity := c.globalConfig.GetString(optionNameLogVerbosity)
lokiEndpoint := c.globalConfig.GetString(optionNameLokiEndpoint)
c.logger, err = newLogger(c.root, verbosity, lokiEndpoint)
c.log, err = newLogger(c.root, verbosity, lokiEndpoint)
if err != nil {
return fmt.Errorf("new logger: %w", err)
}
c.logger.Infof("verbosity log level: %v", c.logger.GetLevel())
c.log.Infof("verbosity log level: %v", c.log.GetLevel())

if c.globalConfig.GetString(optionNameConfigGitRepo) != "" {
// read configuration from git repo
Expand Down Expand Up @@ -241,7 +241,7 @@ func (c *command) initConfig() (err error) {
})
}

if c.config, err = config.Read(c.logger, yamlFiles); err != nil {
if c.config, err = config.Read(c.log, yamlFiles); err != nil {
return err
}
} else {
Expand All @@ -268,7 +268,7 @@ func (c *command) initConfig() (err error) {
})
}

if c.config, err = config.Read(c.logger, yamlFiles); err != nil {
if c.config, err = config.Read(c.log, yamlFiles); err != nil {
return err
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (c *command) setK8S() (err error) {
inCluster := c.globalConfig.GetBool("in-cluster")
kubeconfigPath := c.globalConfig.GetString("kubeconfig")

if c.k8sClient, err = k8s.NewClient(k8s.WithLogger(c.logger), k8s.WithInCluster(inCluster), k8s.WithKubeconfigPath(kubeconfigPath)); err != nil && err != k8s.ErrKubeconfigNotSet {
if c.k8sClient, err = k8s.NewClient(k8s.WithLogger(c.log), k8s.WithInCluster(inCluster), k8s.WithKubeconfigPath(kubeconfigPath)); err != nil && err != k8s.ErrKubeconfigNotSet {
return fmt.Errorf("creating Kubernetes client: %w", err)
}
}
Expand All @@ -328,7 +328,7 @@ func (c *command) setSwapClient() (err error) {
c.swapClient = swap.NewGethClient(gethUrl, &swap.GethClientOptions{
BzzTokenAddress: c.globalConfig.GetString("bzz-token-address"),
EthAccount: c.globalConfig.GetString("eth-account"),
}, c.logger)
}, c.log)
} else {
c.swapClient = &swap.NotSet{}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/beekeeper/cmd/create_bee_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *command) initCreateBeeCluster() *cobra.Command {
defer cancel()
start := time.Now()
_, err = c.setupCluster(ctx, c.globalConfig.GetString(optionNameClusterName), c.config, true)
c.logger.Infof("cluster setup took %s", time.Since(start))
c.log.Infof("cluster setup took %s", time.Since(start))
return err
},
PreRunE: c.preRunE,
Expand Down
2 changes: 1 addition & 1 deletion cmd/beekeeper/cmd/create_k8s_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *command) initCreateK8SNamespace() *cobra.Command {
return fmt.Errorf("create namespace %s: %w", name, err)
}

c.logger.Infof("namespace %s created", name)
c.log.Infof("namespace %s created", name)
return
},
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/beekeeper/cmd/delete_k8s_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *command) initDeleteK8SNamespace() *cobra.Command {
return fmt.Errorf("delete namespace %s: %w", name, err)
}

c.logger.Infof("namespace %s deleted", name)
c.log.Infof("namespace %s deleted", name)
return
},
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
10 changes: 5 additions & 5 deletions cmd/beekeeper/cmd/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ beekeeper fund --address-create --address-count 2 --bzz-deposit 100.0 --eth-depo
if err != nil {
return fmt.Errorf("marshaling Swarm keys: %w", err)
}
c.logger.Infof("%s", k)
c.log.Infof("%s", k)
}
} else if len(c.globalConfig.GetStringSlice(optionNameAddresses)) < 1 {
return fmt.Errorf("bee node Ethereum addresses not provided")
Expand All @@ -68,7 +68,7 @@ beekeeper fund --address-create --address-count 2 --bzz-deposit 100.0 --eth-depo

for _, a := range addresses {
if c.globalConfig.GetBool(optionNamePrintAddresses) {
c.logger.Infof("address: %s", a)
c.log.Infof("address: %s", a)
}
// ETH funding
ethDeposit := c.globalConfig.GetFloat64(optionNameEthDeposit)
Expand All @@ -77,7 +77,7 @@ beekeeper fund --address-create --address-count 2 --bzz-deposit 100.0 --eth-depo
if err != nil {
return fmt.Errorf("send eth: %w", err)
}
c.logger.Infof("%s funded with %.2f ETH, transaction: %s\n", a, ethDeposit, tx)
c.log.Infof("%s funded with %.2f ETH, transaction: %s\n", a, ethDeposit, tx)
}
// BZZ funding
bzzDeposit := c.globalConfig.GetFloat64(optionNameBzzDeposit)
Expand All @@ -86,7 +86,7 @@ beekeeper fund --address-create --address-count 2 --bzz-deposit 100.0 --eth-depo
if err != nil {
return fmt.Errorf("deposit bzz: %w", err)
}
c.logger.Infof("%s funded with %.2f BZZ, transaction: %s\n", a, bzzDeposit, tx)
c.log.Infof("%s funded with %.2f BZZ, transaction: %s\n", a, bzzDeposit, tx)
}
// gBZZ funding
gBzzDeposit := c.globalConfig.GetFloat64(optionNameGBzzDeposit)
Expand All @@ -95,7 +95,7 @@ beekeeper fund --address-create --address-count 2 --bzz-deposit 100.0 --eth-depo
if err != nil {
return fmt.Errorf("deposit gBzz: %w", err)
}
c.logger.Infof("%s funded with %.2f gBZZ, transaction: %s\n", a, gBzzDeposit, tx)
c.log.Infof("%s funded with %.2f gBZZ, transaction: %s\n", a, gBzzDeposit, tx)
}
}

Expand Down
20 changes: 8 additions & 12 deletions cmd/beekeeper/cmd/node_funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ethersphere/beekeeper/pkg/config"
"github.com/ethersphere/beekeeper/pkg/k8s"
"github.com/ethersphere/beekeeper/pkg/logging"
"github.com/ethersphere/node-funder/pkg/funder"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -69,8 +70,8 @@ func (c *command) initNodeFunderCmd() (err error) {
ctx, cancel := context.WithTimeout(cmd.Context(), c.globalConfig.GetDuration(optionNameTimeout))
defer cancel()

c.logger.Infof("node-funder started")
defer c.logger.Infof("node-funder done")
c.log.Infof("node-funder started")
defer c.log.Infof("node-funder done")

// TODO: Note that the swarm key address is the same as the nodeEndpoint/wallet walletAddress.

Expand All @@ -81,7 +82,7 @@ func (c *command) initNodeFunderCmd() (err error) {
var nodeLister funder.NodeLister
// if addresses are provided, use them, not k8s client to list nodes
if cfg.Namespace != "" {
nodeLister = newNodeLister(c.k8sClient)
nodeLister = newNodeLister(c.k8sClient, c.log)
}

return funder.Fund(ctx, funder.Config{
Expand Down Expand Up @@ -114,11 +115,13 @@ func (c *command) initNodeFunderCmd() (err error) {

type nodeLister struct {
k8sClient *k8s.Client
log logging.Logger
}

func newNodeLister(k8sClient *k8s.Client) *nodeLister {
func newNodeLister(k8sClient *k8s.Client, l logging.Logger) *nodeLister {
return &nodeLister{
k8sClient: k8sClient,
log: l,
}
}

Expand All @@ -141,16 +144,9 @@ func (nf *nodeLister) List(ctx context.Context, namespace string) (nodes []funde
return nil, fmt.Errorf("list ingress route debug nodes hosts: %s", err.Error())
}

nodes = make([]funder.NodeInfo, 0, len(ingressHosts)+len(ingressRouteHosts))
ingressHosts = append(ingressHosts, ingressRouteHosts...)

for _, node := range ingressHosts {
nodes = append(nodes, funder.NodeInfo{
Name: node.Name,
Address: node.Host,
})
}

for _, node := range ingressRouteHosts {
nodes = append(nodes, funder.NodeInfo{
Name: node.Name,
Address: fmt.Sprintf("http://%s", node.Host),
Expand Down
6 changes: 3 additions & 3 deletions cmd/beekeeper/cmd/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func (c *command) initSimulateCmd() (err error) {
)

if metricsEnabled {
metricsPusher, cleanup = newMetricsPusher(c.globalConfig.GetString(optionNameMetricsPusherAddress), cfgCluster.GetNamespace(), c.logger)
metricsPusher, cleanup = newMetricsPusher(c.globalConfig.GetString(optionNameMetricsPusherAddress), cfgCluster.GetNamespace(), c.log)
// cleanup executes when the calling context terminates
defer cleanup()
}

// logger metrics
if l, ok := c.logger.(metrics.Reporter); ok && metricsEnabled {
if l, ok := c.log.(metrics.Reporter); ok && metricsEnabled {
metrics.RegisterCollectors(metricsPusher, l.Report()...)
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *command) initSimulateCmd() (err error) {
}

// create simulation
sim := simulation.NewAction(c.logger)
sim := simulation.NewAction(c.log)
if s, ok := sim.(metrics.Reporter); ok && metricsEnabled {
metrics.RegisterCollectors(metricsPusher, s.Report()...)
}
Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ replace github.com/codahale/hdrhistogram => github.com/HdrHistogram/hdrhistogram

require (
github.com/ethereum/go-ethereum v1.12.1
github.com/ethersphere/bee v1.13.0
github.com/ethersphere/bee v1.17.3
github.com/ethersphere/bmt v0.1.4
github.com/ethersphere/ethproxy v0.0.5
github.com/ethersphere/node-funder v0.0.1
github.com/ethersphere/node-funder v0.0.2
github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.5.2
github.com/google/uuid v1.3.0
Expand All @@ -18,10 +18,10 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.40.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
golang.org/x/crypto v0.9.0
golang.org/x/crypto v0.13.0
golang.org/x/sync v0.3.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.22.16
Expand Down Expand Up @@ -56,10 +56,12 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-cid v0.3.2 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down Expand Up @@ -107,9 +109,9 @@ require (
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading