diff --git a/cmd/tarmak/cmd/root.go b/cmd/tarmak/cmd/root.go index 53f3b0be75..185ce611b2 100644 --- a/cmd/tarmak/cmd/root.go +++ b/cmd/tarmak/cmd/root.go @@ -105,6 +105,14 @@ func init() { "override the current cluster set in the config", ) + RootCmd.PersistentFlags().BoolVarP( + &globalFlags.Force, + "force", + "f", + false, + "skip all validation and verification checks", + ) + if version == "dev" { RootCmd.PersistentFlags().BoolVar( &globalFlags.WingDevMode, diff --git a/pkg/apis/tarmak/v1alpha1/types.go b/pkg/apis/tarmak/v1alpha1/types.go index a235ed67d0..07f626df7d 100644 --- a/pkg/apis/tarmak/v1alpha1/types.go +++ b/pkg/apis/tarmak/v1alpha1/types.go @@ -127,6 +127,8 @@ type Flags struct { Version string // expose tarmak's build time version WingDevMode bool // use a bundled wing version rather than a tagged release from GitHub + + Force bool // skip all validations and verification } // This contains the cluster specifc operation flags diff --git a/pkg/tarmak/cluster/cluster.go b/pkg/tarmak/cluster/cluster.go index 13de3b5058..82c8502a12 100644 --- a/pkg/tarmak/cluster/cluster.go +++ b/pkg/tarmak/cluster/cluster.go @@ -54,8 +54,10 @@ func NewFromConfig(environment interfaces.Environment, conf *clusterv1alpha1.Clu log: environment.Log().WithField("cluster", conf.Name), } - if err := cluster.Validate(); err != nil { - return nil, err + if !environment.Tarmak().Config().Force() { + if err := cluster.Validate(); err != nil { + return nil, err + } } cluster.roles = make(map[string]*role.Role) diff --git a/pkg/tarmak/config/config.go b/pkg/tarmak/config/config.go index 2b8eaee973..7eb8e18873 100644 --- a/pkg/tarmak/config/config.go +++ b/pkg/tarmak/config/config.go @@ -351,3 +351,7 @@ func (c *Config) Project() string { func (c *Config) WingDevMode() bool { return c.flags.WingDevMode } + +func (c *Config) Force() bool { + return c.flags.Force +} diff --git a/pkg/tarmak/interfaces/interfaces.go b/pkg/tarmak/interfaces/interfaces.go index 98356d6d79..3ff722f79b 100644 --- a/pkg/tarmak/interfaces/interfaces.go +++ b/pkg/tarmak/interfaces/interfaces.go @@ -185,6 +185,7 @@ type Config interface { Project() string WingDevMode() bool SetCurrentCluster(string) error + Force() bool } type Packer interface { diff --git a/pkg/tarmak/terraform.go b/pkg/tarmak/terraform.go index 7d2b68376c..eaf65dc5b3 100644 --- a/pkg/tarmak/terraform.go +++ b/pkg/tarmak/terraform.go @@ -18,16 +18,18 @@ func (t *Tarmak) CmdTerraformPlan(args []string, ctx context.Context) error { return err } - if err := t.verifyImageExists(); err != nil { - return err - } + if !t.Config().Force() { + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if err := t.verifyImageExists(); err != nil { + return err + } - if err := t.Cluster().Verify(); err != nil { - return fmt.Errorf("failed to validate tarmak cluster: %s", err) + if err := t.Cluster().Verify(); err != nil { + return fmt.Errorf("failed to validate tarmak cluster: %s", err) + } } t.cluster.Log().Info("running plan") @@ -44,16 +46,18 @@ func (t *Tarmak) CmdTerraformApply(args []string, ctx context.Context) error { return err } - if err := t.verifyImageExists(); err != nil { - return err - } + if !t.Config().Force() { + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if err := t.verifyImageExists(); err != nil { + return err + } - if err := t.Cluster().Verify(); err != nil { - return fmt.Errorf("failed to validate tarmak cluster: %s", err) + if err := t.Cluster().Verify(); err != nil { + return fmt.Errorf("failed to validate tarmak cluster: %s", err) + } } t.cluster.Log().Info("running apply") @@ -95,12 +99,14 @@ func (t *Tarmak) CmdTerraformDestroy(args []string, ctx context.Context) error { return err } - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if !t.Config().Force() { + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - if err := t.Cluster().Verify(); err != nil { - return fmt.Errorf("failed to validate tarmak cluster: %s", err) + if err := t.Cluster().Verify(); err != nil { + return fmt.Errorf("failed to validate tarmak cluster: %s", err) + } } t.cluster.Log().Info("running destroy")