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 use of scope and middle layer Spec types in services #627

Closed
CecileRobertMichon opened this issue May 15, 2020 · 9 comments
Assignees
Labels
kind/proposal Issues or PRs related to proposals.

Comments

@CecileRobertMichon
Copy link
Contributor

⚠️ Cluster API Azure maintainers can ask to turn an issue-proposal into a CAEP when necessary. This is to be expected for large changes that impact multiple components, breaking changes, or new large features.

Currently, each service in https://github.com/kubernetes-sigs/cluster-api-provider-azure/tree/master/cloud/services has its own spec type defined that is used as input to create the Azure resource. For example, subnets have Spec: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/cloud/services/subnets/subnets.go#L33

// Spec input specification for Get/CreateOrUpdate/Delete calls
type Spec struct {
	Name                string
	CIDR                string
	VnetName            string
	RouteTableName      string
	SecurityGroupName   string
	Role                infrav1.SubnetRole
	InternalLBIPAddress string
}

The values in this spec get populated by the azuremachine or azurecluster _reconciler (in this case azureclustet since subnets are part of AzureCluster) like so: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/controllers/azurecluster_reconciler.go#L154

However, the Reconcile(), Get()andDelete()` functions already have access to the everything inside the spec from the service subnetSvc which contains the cluster scope: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/controllers/azurecluster_reconciler.go#L43.

To simplify the code and remove the need for extra types and translation layers (api -> spec -> azure), we should remove the superfluous spec objects and instead rely on the information that is already available in scope.AzureCluster.Spec., like we already do in some instances: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/cloud/services/subnets/subnets.go#L49

In addition, some of the values in "Spec" are set by default in azure_reconcile.go at the moment, eg: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/controllers/azurecluster_reconciler.go

We should move those to defaulting webhooks (see #427) so that the source of truth is the AzureCluster and AzureMachine spec.

/kind proposal

@k8s-ci-robot k8s-ci-robot added the kind/proposal Issues or PRs related to proposals. label May 15, 2020
@CecileRobertMichon
Copy link
Contributor Author

cc @jsturtevant

@CecileRobertMichon
Copy link
Contributor Author

/assign

@CecileRobertMichon
Copy link
Contributor Author

@alexeldeib
Copy link
Contributor

Doing everything through scope makes sharing for e.g. machine/machinepool and cluster/managedcluster more painful 🙁 Can we try to pass necessary values from the reconcile loop to the services?

The services shouldn't care about what type they're reconciling against; just the Azure stuff involved.

@CecileRobertMichon
Copy link
Contributor Author

CecileRobertMichon commented May 26, 2020

@alexeldeib that's a very fair point. To be honest, I'm still experimenting right now and not set on a specific design because there are still some unanswered questions, the one you bring up is one of them. I think the main issue is that right now the services don't just do "reconcile an Azure resource", they also have some CAPZ specific logic in there. And they're not doing all of the CAPZ logic either (like CAPA does) because the azuremachine_reconciler and azurecluster_reconciler files have some too. One thing I was looking into doing is changing the use of scope to have an interface that explicitly defines what information is required for each service. For example, the virtualnetworks service needs to be able to get Vnet() but it shouldn't care about the rest of the stuff in ClusterScope, and it shouldn't assume that ClusterScope has ClusterScope.AzureCluster.Spec.Vnet.

I'll definitely consider "Doing everything through scope makes sharing for e.g. machine/machinepool and cluster/managedcluster more painful" as a criteria as I'm thinking about this more, thanks for bringing it up.

@alexeldeib
Copy link
Contributor

Extracting the middle spec type from the scope as part of e.g. reconcile seems interesting. I think mostly it's painful right now because the services use scope liberally to grab bits and pieces of what they need. The dependencies aren't very explicit.

@CecileRobertMichon CecileRobertMichon changed the title Refactor: remove the use of middle layer Spec types in services Refactor: improve use of scope and middle layer Spec types in services May 29, 2020
@CecileRobertMichon CecileRobertMichon added this to the next milestone Jun 4, 2020
@CecileRobertMichon
Copy link
Contributor Author

/close in favor of #757

@CecileRobertMichon
Copy link
Contributor Author

/close

@k8s-ci-robot
Copy link
Contributor

@CecileRobertMichon: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@CecileRobertMichon CecileRobertMichon removed this from the next milestone May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/proposal Issues or PRs related to proposals.
Projects
None yet
Development

No branches or pull requests

3 participants