kubernetes-sigs / cluster-api-provider-aws

Kubernetes Cluster API Provider AWS provides consistent deployment and day 2 operations of "self-managed" and EKS Kubernetes clusters on AWS.
http://cluster-api-aws.sigs.k8s.io/
Apache License 2.0
643 stars 568 forks source link

Refactor reconciler function signatures in controllers #3316

Open Ankitasw opened 2 years ago

Ankitasw commented 2 years ago

/kind refactor

Describe the solution you'd like SInce we have got a lot of input scope parameters to reconcile functions in controllers, it would be good to add an input struct for these functions with all the scopes we are passing in.

Example Current code

func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope, clusterScope cloud.ClusterScoper, ec2Scope scope.EC2Scope, elbScope scope.ELBScope, objectStoreScope scope.S3Scope) (ctrl.Result, error) {

Expectation

type ReconcilerScopes struct {
  machineScope *scope.MachineScope
  clusterScope cloud.ClusterScoper
  ec2Scope scope.EC2Scope
  elbScope scope.ELBScope
  objectStoreScope scope.S3Scope
}
func (r *AWSMachineReconciler) reconcileDelete(rs ReconcilerScopes) (ctrl.Result, error) {

We should take care of all such instances in controllers. Originally posted by @richardcase in https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/2271#r805753482

richardcase commented 2 years ago

/triage accepted /priority backlog /help

k8s-ci-robot commented 2 years ago

@richardcase: This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to [this](https://github.com/kubernetes-sigs/cluster-api-provider-aws/issues/3316): >/triage accepted >/priority backlog >/help Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
LucaLanziani commented 2 years ago

/assign

richardcase commented 2 years ago

@LucaLanziani - it's probably worth synching with @Ankitasw as she is doing some refactoring in a similar area with #3345

Ankitasw commented 2 years ago

@richardcase I think this refactor should not collide with what I am doing in #3345, is it correct? Yeah but since we will have two PRs raised, we might get merge conflicts.

LucaLanziani commented 2 years ago

I was looking yesterday at the code and I've seen that in the tests the reconcideDelete method is called using multiple cluster scopes instead of passing the different scopes.

I didn't have time to go into details on why that is but I was thinking that it might look confusing when passing in a struct if the struct looks something like this:

type ReconcilerScopes struct {
  machineScope *scope.MachineScope
  clusterScope cloud.ClusterScoper
  ec2Scope scope.EC2Scope
  elbScope scope.ELBScope
  objectStoreScope scope.S3Scope
}

rs := ReconcilerScopes{
  machineScope: ms,
  clusterScope: cs,
  ec2Scope: cs,
  elbScope: cs,
  objectStoreScope: cs,
}
LucaLanziani commented 2 years ago

@richardcase I think this refactor should not collide with what I am doing in #3345, is it correct? Yeah but since we will have two PRs raised, we might get merge conflicts.

What you are telling me is that I should move faster and try to get my PR in before yours ;P

richardcase commented 2 years ago

@richardcase I think this refactor should not collide with what I am doing in #3345, is it correct? Yeah but since we will have two PRs raised, we might get merge conflicts.

What you are telling me is that I should move faster and try to get my PR in before yours ;P

:rofl: I only mentioned it for awareness because you are working on the same controllers.

richardcase commented 2 years ago

I didn't have time to go into details on why that is but I was thinking that it might look confusing when passing in a struct if the struct looks something like this:

Personally i think we are getting to the point where passing a struct is preferable to the large number of arguments, it would be a bit cleaner. We could call it something like:

type reconcileDeleteInput struct {
}

Or something like that.

LucaLanziani commented 2 years ago

Personally i think we are getting to the point where passing a struct is preferable to the large number of arguments, it would be a bit cleaner. We could call it something like:

type reconcileDeleteInput struct {
}

Or something like that.

I just realized that I linked the wrong line on the test, I'm ok to change the name of the structure, I was more referring to the fact that we are assigning the same cs to ec2Scope, elbScope, objectStoreScope

LucaLanziani commented 2 years ago

/lifecycle active

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

richardcase commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

Skarlso commented 2 years ago

/remove-lifecycle stale

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 8 months ago

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted