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

Refactor/improve testability #243

Closed
wants to merge 27 commits into from
Closed

Conversation

vsupalov
Copy link
Contributor

@vsupalov vsupalov commented Feb 22, 2023

Description

Fixes #242

Splitting up the two controllers within this operator into fetch/build/apply each.

For anyone who would like to review this heap of changes: you will have a better time going through each commit. Also, I'm sorry.

There is a version bump of the dev dependency serde_yaml happening in the first part of the PR, which made it necessary to adjust existing ldap unit tests. The bump went under in a bigger commit and is easy to miss.

Review Checklist

  • Code contains useful comments
  • CRD change approved (or not applicable)
  • (Integration-)Test cases added (or not applicable)
  • Documentation added (or not applicable)
  • Changelog updated (or not applicable)
  • Cargo.toml only contains references to git tags (not specific commits or branches)
  • Helm chart can be installed and deployed operator works (or not applicable)

Once the review is done, comment bors r+ (or bors merge) to merge. Further information

@vsupalov vsupalov marked this pull request as ready for review February 27, 2023 10:54
Vladislav Supalov added 3 commits February 27, 2023 12:01
@vsupalov
Copy link
Contributor Author

Copy link
Member

@adwk67 adwk67 left a comment

Choose a reason for hiding this comment

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

I like this paradigm! Just a general comment: I would prefer to have conditional logic in just one place and not in both fetch and build (my preference would be to have it as "early" as possible, so in fetch or even in reconcile) to make the code a little easier to follow e.g. in the original code the patch for e.g. the airflow_db job was applied in each reconcile - delegating that to k8s to see if there had been any change or not - rather than checking in the code to see if the job exists.


let (rbac_sa, _) = rbac::build_rbac_resources(airflow_db.as_ref(), "airflow");

built_cluster_resources.push(BuiltClusterResource::PatchRBAC);
Copy link
Member

Choose a reason for hiding this comment

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

if we note the output of build_rbac_resources (in the previous line) with the PatchRBAC resource type we don't the need the second callout to build_rbac_resources in apply.rs (same applies to airflow_controller).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we could. I was okay with calling the function twice, because it is pure and computes quickly.

init_job: ObjectRef::<Job>::new(&job_name).within(&ns),
});

let job = match job_result {
Copy link
Member

Choose a reason for hiding this comment

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

I think this checking if the job exists could be avoided if the case check against airflow_db.status is moved into the reconcile function: then the status is known and the job can be created explicitly (same applies to airflow_controller). I'm not sure but I don't think this would affect the fetch-build-apply template.

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 could imagine transforming the FetchedAdditionalData into an enum. If the job is missing, the only thing we care about is creating the job. If it exists, all other fields start to matter.

This is still duplicated logic. I'm not sure we can avoid 'knowing' about what's going on in the build step entirely here.

@vsupalov
Copy link
Contributor Author

vsupalov commented Feb 28, 2023

Good points Andrew, thanks for taking a look! I see what you mean. I like keeping PRs as focused as possible, so I opted towards making this one about getting the big restructuring done. I think we can improve the clarity of the code (although I must admit, I don't have a clear idea what the rough edges are at the moment).

I would have opted for a follow-up PR, but if it is important to be certain that we can put in more work in this PR.

My biggest wish is to try this structure with a real-life issue, and see how it feels like to write useful tests while developing new features for the operator as soon as possible.

@stackable-bot
Copy link
Contributor

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@vsupalov vsupalov closed this Apr 29, 2024
@razvan razvan deleted the refactor/improve-testability branch December 15, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor operator reconcile function towards fetch/build/apply split
3 participants