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

Only converge on wing when not in infrastructure only #493

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/tarmak/cmd/cluster.go
Expand Up @@ -55,6 +55,14 @@ func clusterApplyFlags(fs *flag.FlagSet) {
consts.DefaultPlanLocationPlaceholder,
"location of stored terraform plan executable file to be used",
)

fs.BoolVarP(
simonswine marked this conversation as resolved.
Show resolved Hide resolved
&store.WaitForConvergence,
"wait-for-convergence",
"W",
true,
"wait for wing convergence on applied instances",
)
}

func clusterDestroyFlags(fs *flag.FlagSet) {
Expand Down
1 change: 1 addition & 0 deletions docs/generated/cmd/tarmak/tarmak_clusters_apply.rst
Expand Up @@ -27,6 +27,7 @@ Options
-h, --help help for apply
-I, --infrastructure-only apply changes to infrastructure only, by running only terraform
-P, --plan-file-location string location of stored terraform plan executable file to be used (default "${TARMAK_CONFIG}/${CURRENT_CLUSTER}/terraform/tarmak.plan")
-W, --wait-for-convergence wait for wing convergence on applied instances (default true)

Options inherited from parent commands
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions docs/generated/reference/output/api-docs.html
Expand Up @@ -538,6 +538,10 @@ <h2 id="clusterapplyflags-v1alpha1">ClusterApplyFlags v1alpha1</h2>
<td><code>planFileLocation</code><br /> <em>string</em></td>
<td></td>
</tr>
<tr>
<td><code>waitForConvergence</code><br /> <em>boolean</em></td>
<td>file location where plan file is to be used</td>
</tr>
</tbody>
</table>
<h2 id="clusterdestroyflags-v1alpha1">ClusterDestroyFlags v1alpha1</h2>
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/tarmak/v1alpha1/types.go
Expand Up @@ -161,7 +161,8 @@ type ClusterApplyFlags struct {
AutoApprove bool `json:"autoApprove,omitempty"` // auto approve apply queries
AutoApproveDeletingData bool `json:"autoApproveDeletingData,omitempty"` // auto approve apply queries about deleting data

PlanFileLocation string `json:"planFileLocation,omitempty"` // file location where plan file is to be used
PlanFileLocation string `json:"planFileLocation,omitempty"` // file location where plan file is to be used
WaitForConvergence bool `json:"waitForConvergence,omitempty"` // wait for wing convergence when applying
}

// Contains the cluster destroy flags
Expand Down
17 changes: 11 additions & 6 deletions pkg/tarmak/cmd.go
Expand Up @@ -48,13 +48,16 @@ func (c *CmdTarmak) Plan() (returnCode int, err error) {
}

func (c *CmdTarmak) Apply() error {
if err := c.setup(); err != nil {
err := c.setup()
if err != nil {
return err
}

// assume a change so that we wait for convergence in configuration only
hasChanged := true
// run terraform apply always, do not run it when in configuration only mode
if !c.flags.Cluster.Apply.ConfigurationOnly {
err := c.terraform.Apply(c.Cluster())
hasChanged, err = c.terraform.Apply(c.Cluster())
if err != nil {
return err
}
Expand Down Expand Up @@ -82,10 +85,12 @@ func (c *CmdTarmak) Apply() error {
default:
}

// wait for convergance in every mode
err := c.Cluster().WaitForConvergance()
if err != nil {
return err
// wait for convergance if flag enabled and has changed
if hasChanged && c.flags.Cluster.Apply.WaitForConvergence {
JoshVanL marked this conversation as resolved.
Show resolved Hide resolved
err := c.Cluster().WaitForConvergance()
if err != nil {
return err
}
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions pkg/terraform/terraform.go
Expand Up @@ -460,27 +460,27 @@ func (t *Terraform) Plan(cluster interfaces.Cluster, preApply bool) (changesNeed
return changesNeeded, nil
}

func (t *Terraform) Apply(cluster interfaces.Cluster) error {
func (t *Terraform) Apply(cluster interfaces.Cluster) (hasChanged bool, err error) {
// generate a plan
changesNeeded, err := t.Plan(cluster, true)
if err != nil || !changesNeeded {
return err
return false, err
}

// break after sigterm
select {
case <-t.ctx.Done():
return t.ctx.Err()
return changesNeeded, t.ctx.Err()
default:
}

planFilePath, err := t.planFileLocation(cluster)
if err != nil {
return err
return false, err
}

// apply necessary at this point
return t.terraformWrapper(
return changesNeeded, t.terraformWrapper(
cluster,
"apply",
[]string{planFilePath},
Expand Down