Skip to content

Commit

Permalink
fix: only require docker, kind when provisioning kind cluster (#180)
Browse files Browse the repository at this point in the history
## Issue
N/A

## Description
Fixes a bug where docker and kind were considered mandatory even when
using an existing k8s cluster.

Verify binaries and exit as early as possible if appropriate.

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson authored Aug 21, 2024
1 parent cfa39a8 commit 1bbdb0e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For more information about validator, see: https://github.com/validator-labs/val
SilenceErrors: true,
SilenceUsage: false,
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
if err := exec.CheckBinaries(exec.AllBins); err != nil {
if err := exec.CheckBinaries([]exec.Binary{exec.HelmBin, exec.KubectlBin}); err != nil {
return err
}
return validator.InitWorkspace(c, cfg.Validator, cfg.ValidatorSubdirs, true)
Expand Down Expand Up @@ -268,7 +268,7 @@ func NewUndeployValidatorCmd() *cobra.Command {
SilenceErrors: true,
SilenceUsage: false,
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
if err := exec.CheckBinaries([]exec.Binary{exec.HelmBin, exec.KindBin}); err != nil {
if err := exec.CheckBinaries([]exec.Binary{exec.HelmBin}); err != nil {
return err
}
return validator.InitWorkspace(c, cfg.Validator, cfg.ValidatorSubdirs, true)
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
log "github.com/validator-labs/validatorctl/pkg/logging"
"github.com/validator-labs/validatorctl/pkg/services/validator"
"github.com/validator-labs/validatorctl/pkg/utils/embed"
"github.com/validator-labs/validatorctl/pkg/utils/exec"
exec_utils "github.com/validator-labs/validatorctl/pkg/utils/exec"
"github.com/validator-labs/validatorctl/pkg/utils/kind"
"github.com/validator-labs/validatorctl/pkg/utils/kube"
Expand Down Expand Up @@ -90,6 +91,11 @@ func InstallValidatorCommand(c *cfg.Config, tc *cfg.TaskConfig) error {
if err != nil {
return errors.Wrap(err, "failed to load validator configuration file")
}
if vc.KindConfig.UseKindCluster {
if err := exec.CheckBinaries([]exec.Binary{exec.DockerBin, exec.KindBin}); err != nil {
return err
}
}
if tc.UpdatePasswords {
log.Header("Updating credentials in validator configuration file")
if err := validator.UpdateValidatorCredentials(vc); err != nil {
Expand Down Expand Up @@ -272,6 +278,11 @@ func UndeployValidatorCommand(tc *cfg.TaskConfig) error {
if err != nil {
return errors.Wrap(err, "failed to load validator configuration file")
}
if vc.KindConfig.UseKindCluster && tc.DeleteCluster {
if err := exec.CheckBinaries([]exec.Binary{exec.KindBin}); err != nil {
return err
}
}

log.Header("Uninstalling validator")
helmClient, err := getHelmClient(vc)
Expand Down
3 changes: 3 additions & 0 deletions pkg/services/validator/validator_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func ReadValidatorConfig(c *cfg.Config, tc *cfg.TaskConfig, vc *components.Valid
return err
}
if vc.KindConfig.UseKindCluster {
if err := exec.CheckBinaries([]exec.Binary{exec.DockerBin, exec.KindBin}); err != nil {
return err
}
if err := kind.ValidateClusters("Validator installation"); err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/utils/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ var (
Ping string
// PingBin is a Binary struct that references the ping binary.
PingBin = Binary{"ping", &Ping}

// AllBins is a list of all binaries used by the CLI.
AllBins = []Binary{DockerBin, HelmBin, KindBin, KubectlBin}
)

// CheckBinaries checks if the required binaries are installed and available on the PATH and returns an error if any are missing.
Expand Down

0 comments on commit 1bbdb0e

Please sign in to comment.