Skip to content

Commit

Permalink
Merge pull request scaling-lightning#30 from Jhoyola/configurable-kub…
Browse files Browse the repository at this point in the history
…e-namespace

Configurable kube namespace
  • Loading branch information
ohenrik authored Apr 16, 2024
2 parents 461cdbc + 84fd721 commit e07a553
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
go-version: ">=1.21.0"
- name: Run E2E Tests
run: go test -run ^TestMain$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
run: go test -run ^TestMainExample$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
# setup ssh access if e2e job fails
# - name: Setup upterm session
# if: always() && (steps.e2e.outcome == 'failure')
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,28 @@ To destroy the network run:
# have bitcoind generate some blocks and pay itself the block reward
./scaling-lightning generate -n bitcoind

#### Using different Kubernetes namespaces

By default, `sl` namespace is used. If you want to use a different namespace, you can specify it in the helmfile.

If you use multiple namespaces, make sure that the endpoints that are used are not overlapping!

# Download example helmfile that has a custom namespace
wget https://raw.githubusercontent.com/scaling-lightning/scaling-lightning/main/examples/helmfiles/local-custom-namespace.yaml

# Create the nework normally, the namespace is read from the helmfile
./scaling-lightning create -f local-custom-namespace.yaml

# In the following commands use the --namespace flag to interact with the created namespace (otherwise it will default to sl)
./scaling-lightning --namespace my-other-sl list

### Run the above from code instead of CLI

See [examples/go/example_test.go](examples/go/example_test.go). This test takes around 3 minutes to pass on an M1 Macbook Pro so you may need to adjust your test runner's default timeout.

Example go test command with extra timeout:

go test -run ^TestMain$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
go test -run ^TestMainExample$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m

### Helpful Kubernetes commands

Expand Down Expand Up @@ -144,7 +159,7 @@ Example go test command with extra timeout:
# view loadbalancer public ip from traefik
kubectl -n sl-traefik get services

# destroy all scaling lightning nodes
# destroy all scaling lightning nodes in the default namespace
kubectl delete namespace sl

# uninstall traefik
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/channelbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
nodeName := cmd.Flag("node").Value.String()
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/connectiondetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/connectpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
processDebugFlag(cmd)
connectpeerFromName := cmd.Flag("from").Value.String()
connectpeerToName := cmd.Flag("to").Value.String()
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
16 changes: 14 additions & 2 deletions cmd/scalinglightning/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
helmfile := cmd.Flag("helmfile").Value.String()

// Namespace flag should not be used with create, since namespace is read from the helmfile
if rootCmd.Flag("namespace").Changed {
fmt.Println("Cannot create. Do not use namespace flag with create. Instead specify the namespace in the helmfile.")
return
}

fmt.Println("Creating and starting the network")
slnetwork := sl.NewSLNetwork(helmfile, kubeConfigPath, sl.Regtest)
err := slnetwork.CreateAndStart()
slnetwork, err := sl.NewSLNetworkWithoutNamespace(helmfile, kubeConfigPath, sl.Regtest)
if err != nil {
fmt.Println(err.Error())
return
}

err = slnetwork.CreateAndStart()
if err != nil {
fmt.Println(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/createinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
fmt.Println("Amount must be a valid number")
return
}
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
12 changes: 9 additions & 3 deletions cmd/scalinglightning/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ func init() {
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
fmt.Println("Destroying the network")
slnetwork := sl.NewSLNetwork("", kubeConfigPath, sl.Regtest)
err := slnetwork.Destroy()

fmt.Printf("Destroying the network '%v'\n", namespace)
slnetwork, err := sl.NewSLNetwork("", kubeConfigPath, sl.Regtest, namespace)
if err != nil {
fmt.Println(err.Error())
return
}

err = slnetwork.Destroy()
if err != nil {
fmt.Println(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/openchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/payinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
processDebugFlag(cmd)
nodeName := cmd.Flag("node").Value.String()
invoice := cmd.Flag("invoice").Value.String()
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
pubkeyNodeName := cmd.Flag("node").Value.String()
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
4 changes: 4 additions & 0 deletions cmd/scalinglightning/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalinglightning

import (
"github.com/scaling-lightning/scaling-lightning/pkg/network"
"os"
"os/user"
"path"
Expand All @@ -13,6 +14,7 @@ import (
var kubeConfigPath string //nolint:gochecknoglobals
var apiHost string //nolint:gochecknoglobals
var apiPort uint16 //nolint:gochecknoglobals
var namespace string //nolint:gochecknoglobals

var rootCmd = &cobra.Command{ //nolint:gochecknoglobals
Use: "sl",
Expand Down Expand Up @@ -55,6 +57,8 @@ func init() {
StringVarP(&apiHost, "host", "H", "", "Host of the scaling-lightning API")
rootCmd.PersistentFlags().
Uint16VarP(&apiPort, "port", "p", 0, "Port of the scaling-lightning API")
rootCmd.PersistentFlags().
StringVarP(&namespace, "namespace", "N", network.DefaultNamespace, "Kubernetes namespace for the network")

rootCmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug logging")
}
4 changes: 2 additions & 2 deletions cmd/scalinglightning/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func init() {
var sendCmd = &cobra.Command{
Use: "send",
Short: "Send on chain funds betwen nodes",
Short: "Send on chain funds between nodes",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
Expand All @@ -23,7 +23,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/walletbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
processDebugFlag(cmd)
balanceNodeName := cmd.Flag("node").Value.String()
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/scalinglightning/writeauthfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
return
}

slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort)
slnetwork, err := sl.DiscoverRunningNetwork(kubeConfigPath, apiHost, apiPort, namespace)
if err != nil {
fmt.Printf(
"Problem with network discovery, is there a network running? Error: %v\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

// will need a longish (few mins) timeout
func TestMain(t *testing.T) {
func TestMainExample(t *testing.T) {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
assert := assert.New(t)
network := sl.NewSLNetwork("../helmfiles/public.yaml", "", sl.Regtest)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ releases:
- image:
tag: v23.05.1 # Version of CLN docker image to use
- clientImage:
repository: cln-client # Use a specific image for sidecar container (usually used when developing the scaling lightning project itself)
repository: scalingln/cln-client # Use a specific image for sidecar container (usually used when developing the scaling lightning project itself)
pullPolicy: IfNotPresent # K8s Pull Policy for sidecar image. IfNotPresent helps locate updated local images.
- volume: # Optional: if specified will create a volume and data will be persisted between restarts and upgrades
size: "1Gi" # Size of volume in kubernetes notation. Here 1 Gibibyte (1,073,741,824 bytes) is specified.
Expand Down
17 changes: 16 additions & 1 deletion docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,28 @@ To destroy the network run:
# have bitcoind generate some blocks and pay itself the block reward
./scaling-lightning generate -n bitcoind

#### Using different Kubernetes namespaces

By default, `sl` namespace is used. If you want to use a different namespace, you can specify it in the helmfile.

If you use multiple namespaces, make sure that the endpoints that are used are not overlapping!

# Download example helmfile that has a custom namespace
wget https://raw.githubusercontent.com/scaling-lightning/scaling-lightning/main/examples/helmfiles/local-custom-namespace.yaml

# Create the nework normally, the namespace is read from the helmfile
./scaling-lightning create -f local-custom-namespace.yaml

# In the following commands use the --namespace flag to interact with the created namespace (otherwise it will default to sl)
./scaling-lightning --namespace my-other-sl list

## Run the above from code instead of CLI

See [examples/go/example_test.go](https://github.com/scaling-lightning/scaling-lightning/blob/main/examples/go/example_test.go). This test takes around 3 minutes to pass on an M1 Macbook Pro so you may need to adjust your test runner's default timeout.

Example go test command with extra timeout:

go test -run ^TestMain$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
go test -run ^TestMainExample$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m

## Helpful Kubernetes commands

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/how-to/run-on-github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
go-version: ">=1.21.0"
- name: Run example test
run: go test -run ^TestMain$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
run: go test -run ^TestMainExample$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
```
The [example test](https://github.com/scaling-lightning/scaling-lightning/blob/main/examples/go/example_test.go) can be found in our repo under examples/go.
2 changes: 1 addition & 1 deletion examples/githubactions/runwithminikube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
with:
go-version: ">=1.21.0"
- name: Run example test
run: go test -run ^TestMain$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
run: go test -run ^TestMainExample$ github.com/scaling-lightning/scaling-lightning/examples/go -count=1 -v -timeout=15m
8 changes: 5 additions & 3 deletions examples/go/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
)

// will need a longish (few mins) timeout
func TestMain(t *testing.T) {
func TestMainExapmle(t *testing.T) {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
assert := assert.New(t)
network := sl.NewSLNetwork("../helmfiles/public.yaml", "", sl.Regtest)
err := network.CreateAndStart()
network, err := sl.NewSLNetwork("../helmfiles/public.yaml", "", sl.Regtest, sl.DefaultNamespace)
assert.NoError(err)

err = network.CreateAndStart()
if err != nil {
log.Fatal().Err(err).Msg("Problem starting network")
}
Expand Down
10 changes: 5 additions & 5 deletions examples/helmfiles/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ releases:
chart: ../../charts/bitcoind
values:
- clientImage:
repository: bitcoind-client
repository: scalingln/bitcoind-client
pullPolicy: IfNotPresent
- autoGen: true
- rpcEntryPoint: endpoint37
Expand All @@ -17,29 +17,29 @@ releases:
values:
- gRPCEntryPoint: endpoint1
- clientImage:
repository: cln-client
repository: scalingln/cln-client
pullPolicy: IfNotPresent
- name: cln2
namespace: sl
chart: ../../charts/cln
values:
- clientImage:
repository: cln-client
repository: scalingln/cln-client
pullPolicy: IfNotPresent
- gRPCEntryPoint: endpoint2
- name: lnd1
namespace: sl
chart: ../../charts/lnd
values:
- clientImage:
repository: lnd-client
repository: scalingln/lnd-client
pullPolicy: IfNotPresent
- gRPCEntryPoint: endpoint3
- name: lnd2
namespace: sl
chart: ../../charts/lnd
values:
- clientImage:
repository: lnd-client
repository: scalingln/lnd-client
pullPolicy: IfNotPresent
- gRPCEntryPoint: endpoint4
Loading

0 comments on commit e07a553

Please sign in to comment.