Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid drift detection when using manual mode #1076

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 4 additions & 0 deletions api/v1alpha2/terraform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ func (in *TerraformSpec) GetAlwaysCleanupRunnerPod() bool {
return *in.AlwaysCleanupRunnerPod
}

func (in TerraformSpec) IsManualMode() bool {
return in.ApprovePlan == "" || (in.ApprovePlan != ApprovePlanDisableValue && in.ApprovePlan != ApprovePlanAutoValue)
}

func (c *CloudSpec) IsValid() bool {
if c.Organization == "" {
return false
Expand Down

This file was deleted.

12 changes: 6 additions & 6 deletions controllers/tc000180_should_detect_drift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func Test_000180_should_detect_drift_test(t *testing.T) {

tf3 := infrav1.Terraform{
Spec: infrav1.TerraformSpec{
Destroy: false,
Destroy: false,
ApprovePlan: infrav1.ApprovePlanAutoValue,
},
Status: infrav1.TerraformStatus{
LastAttemptedRevision: "main/1234",
Expand All @@ -48,7 +49,8 @@ func Test_000180_should_detect_drift_test(t *testing.T) {

tf4 := infrav1.Terraform{
Spec: infrav1.TerraformSpec{
Destroy: false,
Destroy: false,
ApprovePlan: infrav1.ApprovePlanAutoValue,
},
Status: infrav1.TerraformStatus{
LastAttemptedRevision: "main/2345",
Expand All @@ -64,7 +66,8 @@ func Test_000180_should_detect_drift_test(t *testing.T) {

tf5 := infrav1.Terraform{
Spec: infrav1.TerraformSpec{
Destroy: false,
Destroy: false,
ApprovePlan: infrav1.ApprovePlanAutoValue,
},
Status: infrav1.TerraformStatus{
LastAttemptedRevision: "main/2345",
Expand Down Expand Up @@ -96,9 +99,6 @@ func Test_000180_should_detect_drift_test(t *testing.T) {
It("should be false for an object with the pending plan.")
g.Expect(reconciler.shouldDetectDrift(tf5_1, "main/2345")).Should(BeFalse())

It("should be true for a normally applied object.")
g.Expect(reconciler.shouldDetectDrift(tf3, "main/1234")).Should(BeTrue())

It("should be true for when ApprovePlan is disable")
tf6 := infrav1.Terraform{
Spec: infrav1.TerraformSpec{
Expand Down
1 change: 1 addition & 0 deletions controllers/tc000200_disable_drift_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Test_000200_disable_drift_detection(t *testing.T) {
tf2 := infrav1.Terraform{
Spec: infrav1.TerraformSpec{
DisableDriftDetection: false,
ApprovePlan: infrav1.ApprovePlanAutoValue,
},
Status: infrav1.TerraformStatus{
LastAttemptedRevision: "main/2345",
Expand Down
5 changes: 5 additions & 0 deletions controllers/tf_controller_drift_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (r *TerraformReconciler) shouldDetectDrift(terraform infrav1.Terraform, rev
return false
}

// whenever we are in manual mode, we do not do drift detection
if terraform.Spec.IsManualMode() {
return false
}

// new object
if terraform.Status.LastAppliedRevision == "" &&
terraform.Status.LastPlannedRevision == "" &&
Expand Down