Add configuration drift detection and optional reconciliation to ComputeEngineInsertInstanceOperator#61830
Merged
shahar1 merged 1 commit intoapache:mainfrom Mar 9, 2026
Conversation
7359542 to
4cca068
Compare
shahar1
reviewed
Feb 16, 2026
providers/google/src/airflow/providers/google/cloud/operators/compute.py
Outdated
Show resolved
Hide resolved
providers/google/src/airflow/providers/google/cloud/operators/compute.py
Outdated
Show resolved
Hide resolved
Contributor
|
thank you for raising PR |
4cca068 to
b0cdbf4
Compare
Contributor
Author
…tanceOperator Detect and log machine type configuration differences when an instance already exists instead of relying solely on presence-based idempotence. Introduce `recreate_if_machine_type_different` flag to optionally delete and recreate instances when drift is detected. Refactor execute logic to support drift comparison and shared instance creation helper. Add unit and system tests for drift logging and recreation behavior.
b0cdbf4 to
6dd6f40
Compare
Contributor
Author
|
Requesting review for this. |
shahar1
approved these changes
Mar 9, 2026
jason810496
pushed a commit
to jason810496/airflow
that referenced
this pull request
Mar 10, 2026
81 tasks
thejoeejoee
pushed a commit
to thejoeejoee/airflow
that referenced
this pull request
Mar 10, 2026
dominikhei
pushed a commit
to dominikhei/airflow
that referenced
this pull request
Mar 11, 2026
Pyasma
pushed a commit
to Pyasma/airflow
that referenced
this pull request
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
This change enhances
ComputeEngineInsertInstanceOperatorto detect configuration differences when an instance already exists.Previously, the operator treated instance presence as success and returned without validating that the existing resource matched the requested configuration. As a result, changes to fields such as
machine_typewere not detected on subsequent DAG runs.This update introduces configuration (
machine_type) comparison logic when an instance is found. Detected differences are logged. An optionalrecreate_if_differentflag allows users to explicitly request deletion and recreation of the instance when configuration drift is detected.To support this behavior, two helper methods were introduced:
_detect_instance_drift, which compares the existing instance with the requested body, and_create_instance, which encapsulates instance creation logic used by both the initial and recreation paths.Rationale
The previous behavior relied solely on presence-based idempotence and did not validate configuration consistency across DAG runs. This change surfaces configuration differences and provides an opt-in mechanism for reconciliation, while preserving default behavior.
Drift detection is intentionally limited to
machine_typefor now. Machine type changes are deterministic, high-impact, and straightforward to compare, whereas other fields (e.g. disks or networking) introduce normalization and defaulting complexity. The implementation is structured to allow incremental expansion of drift detection in future updates.Notes
executemethod has been refactored to accommodate configuration drift logging and the newrecreate_if_differentflag while preserving default behavior. The refactor extracts instance creation into a helper and introduces structured comparison logic without altering presence-based idempotence unless the new flag is explicitly enabled._extract_machine_typehas been introduced to extract themachine_typefrom the full strings.Tests
recreate_if_different=True.Documentation
recreate_if_differentparameter in the operator docstring.executemethod docstring to clarify presence-based idempotence and drift handling behavior.Backwards Compatibility
There is a behavioral difference in that configuration drift is now logged by default when detected. Additionally, users may opt into reconciliation behavior via
recreate_if_different=True, which will delete and recreate the instance when differences are found. Existing DAGs will otherwise continue to behave as before unless the new flag is explicitly enabled.Closes: #61829