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 df9be74405..8bc642e926 100644 --- a/pkg/tarmak/cluster/cluster.go +++ b/pkg/tarmak/cluster/cluster.go @@ -55,8 +55,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/cluster/cluster_test.go b/pkg/tarmak/cluster/cluster_test.go index 1ec5910433..c17e081dd7 100644 --- a/pkg/tarmak/cluster/cluster_test.go +++ b/pkg/tarmak/cluster/cluster_test.go @@ -60,6 +60,8 @@ func newFakeCluster(t *testing.T, cluster *clusterv1alpha1.Cluster) *fakeCluster c.fakeProvider.EXPECT().Cloud().Return("provider").AnyTimes() c.fakeProvider.EXPECT().Name().Return("provider-name").AnyTimes() + c.fakeConfig.EXPECT().Force().Return(false).AnyTimes() + c.fakeTarmak.EXPECT().Config().AnyTimes().Return(c.fakeConfig) return c 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 d5c0893851..f0358f1e55 100644 --- a/pkg/tarmak/interfaces/interfaces.go +++ b/pkg/tarmak/interfaces/interfaces.go @@ -184,6 +184,7 @@ type Config interface { Project() string WingDevMode() bool SetCurrentCluster(string) error + Force() bool } type Packer interface { diff --git a/pkg/tarmak/kubectl/kubectl.go b/pkg/tarmak/kubectl/kubectl.go index 9c0a920fd1..53bcd94c90 100644 --- a/pkg/tarmak/kubectl/kubectl.go +++ b/pkg/tarmak/kubectl/kubectl.go @@ -49,8 +49,10 @@ func (k *Kubectl) requestNewAdminCert(cluster *api.Cluster, authInfo *api.AuthIn k.log.Infof("request new certificate from vault (%s)", path) - if err := k.tarmak.Cluster().Environment().Validate(); err != nil { - k.log.Fatal("could not validate config: ", err) + if !k.tarmak.Config().Force() { + if err := k.tarmak.Cluster().Environment().Validate(); err != nil { + k.log.Fatal("could not validate config: ", err) + } } vault := k.tarmak.Environment().Vault() diff --git a/pkg/tarmak/tarmak.go b/pkg/tarmak/tarmak.go index 4ef1a0abb4..76056c4ba2 100644 --- a/pkg/tarmak/tarmak.go +++ b/pkg/tarmak/tarmak.go @@ -281,10 +281,9 @@ func (t *Tarmak) Version() string { } func (t *Tarmak) Validate() error { - var err error - var result error + var result *multierror.Error - err = t.Cluster().Validate() + err := t.Cluster().Validate() if err != nil { result = multierror.Append(result, err) } @@ -294,7 +293,7 @@ func (t *Tarmak) Validate() error { result = multierror.Append(result, err) } - return result + return result.ErrorOrNil() } func (t *Tarmak) Verify() error { diff --git a/pkg/tarmak/tarmak_test.go b/pkg/tarmak/tarmak_test.go index 8c4ba2a5db..382d2d140b 100644 --- a/pkg/tarmak/tarmak_test.go +++ b/pkg/tarmak/tarmak_test.go @@ -64,6 +64,7 @@ func (tt *testTarmak) fakeAWSProvider(name string) { } tt.fakeConfig.EXPECT().Provider(name).AnyTimes().Return(&tarmakv1alpha1.Provider{}, nil) + tt.fakeConfig.EXPECT().Force().Return(false).AnyTimes() } func (tt *testTarmak) addEnvironment(env *tarmakv1alpha1.Environment) { diff --git a/pkg/tarmak/terraform.go b/pkg/tarmak/terraform.go index 84bb39119d..9291cd4c00 100644 --- a/pkg/tarmak/terraform.go +++ b/pkg/tarmak/terraform.go @@ -14,14 +14,16 @@ func (t *Tarmak) Terraform() interfaces.Terraform { } func (t *Tarmak) CmdTerraformPlan(args []string, ctx context.Context) error { - t.cluster.Log().Info("validate steps") - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if !t.Config().Force() { + t.cluster.Log().Info("validate steps") + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - t.cluster.Log().Info("verify steps") - if err := t.Verify(); err != nil { - return err + t.cluster.Log().Info("verify steps") + if err := t.Verify(); err != nil { + return err + } } t.cluster.Log().Info("write SSH config") @@ -39,14 +41,16 @@ func (t *Tarmak) CmdTerraformPlan(args []string, ctx context.Context) error { } func (t *Tarmak) CmdTerraformApply(args []string, ctx context.Context) error { - t.cluster.Log().Info("validate steps") - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if !t.Config().Force() { + t.cluster.Log().Info("validate steps") + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - t.cluster.Log().Info("verify steps") - if err := t.Verify(); err != nil { - return err + t.cluster.Log().Info("verify steps") + if err := t.Verify(); err != nil { + return err + } } t.cluster.Log().Info("write SSH config") @@ -89,14 +93,16 @@ func (t *Tarmak) CmdTerraformApply(args []string, ctx context.Context) error { } func (t *Tarmak) CmdTerraformDestroy(args []string, ctx context.Context) error { - t.cluster.Log().Info("validate steps") - if err := t.Validate(); err != nil { - return fmt.Errorf("failed to validate tarmak: %s", err) - } + if !t.Config().Force() { + t.cluster.Log().Info("validate steps") + if err := t.Validate(); err != nil { + return fmt.Errorf("failed to validate tarmak: %s", err) + } - t.cluster.Log().Info("verify steps") - if err := t.Verify(); err != nil { - return err + t.cluster.Log().Info("verify steps") + if err := t.Verify(); err != nil { + return err + } } t.cluster.Log().Info("write SSH config")