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

Force flag #332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/tarmak/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -184,6 +184,7 @@ type Config interface {
Project() string
WingDevMode() bool
SetCurrentCluster(string) error
Force() bool
}

type Packer interface {
Expand Down
6 changes: 4 additions & 2 deletions pkg/tarmak/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions pkg/tarmak/tarmak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -294,7 +293,7 @@ func (t *Tarmak) Validate() error {
result = multierror.Append(result, err)
}

return result
return result.ErrorOrNil()
}

func (t *Tarmak) Verify() error {
Expand Down
1 change: 1 addition & 0 deletions pkg/tarmak/tarmak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
48 changes: 27 additions & 21 deletions pkg/tarmak/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down