Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Adds force flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshVanL committed Jun 20, 2018
1 parent dca5cb3 commit 8d34713
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
8 changes: 8 additions & 0 deletions cmd/tarmak/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/tarmak/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pkg/tarmak/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pkg/tarmak/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/tarmak/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type Config interface {
Project() string
WingDevMode() bool
SetCurrentCluster(string) error
Force() bool
}

type Packer interface {
Expand Down
48 changes: 27 additions & 21 deletions pkg/tarmak/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8d34713

Please sign in to comment.