hashicorp / hcp-terraform-operator

Kubernetes Operator allows managing HCP Terraform resources via Kubernetes Custom Resources.
https://developer.hashicorp.com/terraform/cloud-docs
Mozilla Public License 2.0
122 stars 29 forks source link

🐛 Fix CR Status update in Workspace controller #457

Closed arybolovlev closed 1 month ago

arybolovlev commented 1 month ago

Description

This PR aims to update the way the workspace controller updates CR Status. It now uses the patch method instead of update. This primarily helps with the edge case when the CR gets updated during initial reconciliation. In this situation, the controller fails to perform an update operation, leading to a scenario where the Workspace is created in HCP Terraform, but the CR status does not have information about the Workspace ID. Consequently, it attempts to create it again once it recovers from the failure. The controller will continue to fail because the name is already taken.

This PR mainly fixes the Workspace controller, however, the same issue can happen with other controllers. We need to revise all controllers' logic along with predicate logic(described in this PR) to make it more flexible, straightforward, and clean.

Tests

Usage Example

N/A.

References

Community Note