Skip to content

Commit

Permalink
handle if no nodes found for v4 deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 21, 2024
1 parent 08be7c3 commit 8fe9acb
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions grid-cli/cmd/deploy_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
command "github.com/threefoldtech/tfgrid-sdk-go/grid-cli/internal/cmd"
Expand Down Expand Up @@ -141,8 +142,14 @@ var deployVMCmd = &cobra.Command{
Entrypoint: entrypoint,
MyceliumIPSeed: seed,
}
executeVMLight(cmd.Context(), t, vm, node, farm, disk, volume)
return nil
err = executeVMLight(cmd.Context(), t, vm, node, farm, disk, volume)
if err == nil {
return nil
}

if !errors.Is(err, deployer.ErrNoNodesMatchesResources) {
log.Fatal().Err(err).Send()
}
}

vm := workloads.VM{
Expand All @@ -159,7 +166,11 @@ var deployVMCmd = &cobra.Command{
MyceliumIPSeed: seed,
Planetary: ygg,
}
executeVM(cmd.Context(), t, vm, node, farm, disk, volume)
err = executeVM(cmd.Context(), t, vm, node, farm, disk, volume)
if err != nil {
log.Fatal().Err(err).Send()
}

return nil
},
}
Expand Down Expand Up @@ -207,7 +218,7 @@ func executeVM(
vm workloads.VM,
node uint32,
farm, disk, volume uint64,
) {
) error {
var diskMount workloads.Disk
if disk != 0 {
diskName := fmt.Sprintf("%sdisk", vm.Name)
Expand All @@ -233,7 +244,7 @@ func executeVM(
rootfss,
)
if err != nil {
log.Fatal().Err(err).Send()
return err
}

node = uint32(nodes[0].NodeID)
Expand All @@ -242,7 +253,7 @@ func executeVM(
vm.NodeID = node
resVM, err := command.DeployVM(ctx, t, vm, diskMount, volumeMount)
if err != nil {
log.Fatal().Err(err).Send()
return err
}

if vm.PublicIP {
Expand All @@ -257,14 +268,16 @@ func executeVM(
if len(resVM.MyceliumIP) != 0 {
log.Info().Msgf("vm mycelium ip: %s", resVM.MyceliumIP)
}

return nil
}

func executeVMLight(
ctx context.Context, t deployer.TFPluginClient,
vm workloads.VMLight,
node uint32,
farm, disk, volume uint64,
) {
) error {
var diskMount workloads.Disk
if disk != 0 {
diskName := fmt.Sprintf("%sdisk", vm.Name)
Expand All @@ -290,7 +303,7 @@ func executeVMLight(
rootfss,
)
if err != nil {
log.Fatal().Err(err).Send()
return err
}

node = uint32(nodes[0].NodeID)
Expand All @@ -299,10 +312,12 @@ func executeVMLight(
vm.NodeID = node
resVM, err := command.DeployVMLight(ctx, t, vm, diskMount, volumeMount)
if err != nil {
log.Fatal().Err(err).Send()
return err
}

if len(resVM.MyceliumIP) != 0 {
log.Info().Msgf("vm mycelium ip: %s", resVM.MyceliumIP)
}

return nil
}

0 comments on commit 8fe9acb

Please # to comment.