Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fund nodes using node-operator as they are deployed (#371)
* wip(k8s): add pod events watcher and operator cmd * wip: create working demo * wip: update event log for demo * refactor(operator): extract operator to separate pkg and add label to config * feat(operator): set infinite timout as default * fix(operator): check funder.Fund error * chore: update readme.md file and bump version to v0.14.3
- Loading branch information
1 parent
7c87f18
commit 2ad80e3
Showing
12 changed files
with
439 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/ethersphere/beekeeper/pkg/config" | ||
"github.com/ethersphere/beekeeper/pkg/operator" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *command) initOperatorCmd() (err error) { | ||
const ( | ||
optionNameNamespace = "namespace" | ||
optionNameChainNodeEndpoint = "geth-url" | ||
optionNameWalletKey = "wallet-key" | ||
optionNameMinNative = "min-native" | ||
optionNameMinSwarm = "min-swarm" | ||
optionNameTimeout = "timeout" | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "node-operator", | ||
Short: "scans for scheduled pods and funds them", | ||
Long: `Node operator scans for scheduled pods and funds them using node-funder. beekeeper node-operator`, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
cfg := config.NodeFunder{} | ||
namespace := c.globalConfig.GetString(optionNameNamespace) | ||
|
||
// chain node endpoint check | ||
if cfg.ChainNodeEndpoint = c.globalConfig.GetString(optionNameChainNodeEndpoint); cfg.ChainNodeEndpoint == "" { | ||
return errors.New("chain node endpoint (geth-url) not provided") | ||
} | ||
|
||
// wallet key check | ||
if cfg.WalletKey = c.globalConfig.GetString(optionNameWalletKey); cfg.WalletKey == "" { | ||
return errors.New("wallet key not provided") | ||
} | ||
|
||
cfg.MinAmounts.NativeCoin = c.globalConfig.GetFloat64(optionNameMinNative) | ||
cfg.MinAmounts.SwarmToken = c.globalConfig.GetFloat64(optionNameMinSwarm) | ||
|
||
// add timeout to operator | ||
// if timeout is not set, operator will run infinitely | ||
var ctxNew context.Context | ||
var cancel context.CancelFunc | ||
timeout := c.globalConfig.GetDuration(optionNameTimeout) | ||
if timeout > 0 { | ||
ctxNew, cancel = context.WithTimeout(cmd.Context(), timeout) | ||
} else { | ||
ctxNew = context.Background() | ||
} | ||
if cancel != nil { | ||
defer cancel() | ||
} | ||
|
||
return operator.NewClient(&operator.ClientConfig{ | ||
Log: c.log, | ||
Namespace: namespace, | ||
WalletKey: cfg.WalletKey, | ||
ChainNodeEndpoint: cfg.ChainNodeEndpoint, | ||
MinAmounts: cfg.MinAmounts, | ||
K8sClient: c.k8sClient, | ||
}).Run(ctxNew) | ||
}, | ||
PreRunE: c.preRunE, | ||
} | ||
|
||
cmd.Flags().StringP(optionNameNamespace, "n", "", "Kubernetes namespace to scan for scheduled pods.") | ||
cmd.Flags().String(optionNameChainNodeEndpoint, "", "Endpoint to chain node. Required.") | ||
cmd.Flags().String(optionNameWalletKey, "", "Hex-encoded private key for the Bee node wallet. Required.") | ||
cmd.Flags().Float64(optionNameMinNative, 0, "Minimum amount of chain native coins (xDAI) nodes should have.") | ||
cmd.Flags().Float64(optionNameMinSwarm, 0, "Minimum amount of swarm tokens (xBZZ) nodes should have.") | ||
cmd.Flags().Duration(optionNameTimeout, 0*time.Minute, "Timeout. Default is infinite.") | ||
|
||
c.root.AddCommand(cmd) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.