Skip to content

Conversation

@syedahsn
Copy link
Contributor

@syedahsn syedahsn commented Jul 4, 2023

This PR adds deferrable mode to the EksCreateClusterOperator and EksDeleteClusterOperator. The associated unit tests are also included.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@potiuk
Copy link
Member

potiuk commented Jul 5, 2023

We just merged #31712 we should likely follow the way it is implemented.

@Lee-W : I think we might want to add a pre-commit with some AST parsing likely - to add a check for providers that if they are using defferable in operator's init, the default should be as implemented in #31712. I think this is the only way to avoid someone accidentally not using the deferrable configuration default. We cannot rely on reviewers remembering about it. But it should be relatively easy ot write a pre-commit that would verify that and fail the build in case someone does not use it.

We have a few pre-commits that use AST to inspect parsed code so you could take it as an example.

Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change required, and a few questions and nitpicks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

Suggested change
def execute_failed(self, context, event=None):
def execute_failed(self, context: Context, event: dict[str, Any] | None=None) -> None:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using the function definition of the execute_* method from the official docs, which do it like this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Not sure whether we should update the doc there 🤔 Let me send a PR to see how others thinkg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that your PR got merged. I added the change here, but I was having issues with mypy which didn't like the fact that event could be None:

airflow/providers/amazon/aws/operators/eks.py:766: error: Value of type
"Optional[Dict[str, Any]]" is not indexable  [index]
            if event["status"] == "success":

This can be solved by checking to make sure event is not None everytime:

if event and event["status"] == "success":

or remove None as an option and set the default to {}.
The last option is to simply ignore mypy, which is something I would rather avoid if possible.
I'm going with removing None as an option, but let me know if you think another option is more reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't notice this reply, but I think we agree to use the solution on #32355 (comment)

@syedahsn syedahsn force-pushed the syedahsn/deferrable-eks-cluster branch from c042ee6 to a79c229 Compare July 11, 2023 18:41
@syedahsn syedahsn requested a review from Lee-W July 11, 2023 19:45
subnets=cast(List[str], self.resources_vpc_config.get("subnetIds")),
)

def deferrable_create_cluster_next(self, context: Context, event: dict[str, Any] = {}) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether we should use {} as the default value. I believe it's generally not a good idea to use mutable object as default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that's a good point. I guess I can set it to None and do a check for None before indexing it i.e.

if event and event["status"]

Its going to be tedious to do it everywhere, but I don't see a better option

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think this is the best option we have as of now.

)
self.log.info(SUCCESS_MSG.format(compute=FARGATE_FULL_NAME))

def execute_complete(self, context: Context, event: dict[str, Any] = {}) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subnets=cast(List[str], self.resources_vpc_config.get("subnetIds")),
)

def deferrable_create_cluster_next(self, context: Context, event: dict[str, Any] = {}) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think this is the best option we have as of now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't notice this reply, but I think we agree to use the solution on #32355 (comment)

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just left one minor nitpick.

@o-nikolas o-nikolas merged commit 113018e into apache:main Jul 17, 2023
o-nikolas added a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants