kubernetes-sigs / cluster-api-provider-ibmcloud

Cluster API Provider for IBM Cloud
https://cluster-api-ibmcloud.sigs.k8s.io
Apache License 2.0
62 stars 77 forks source link

Refactor Power VS reconcile helpers for better readbility and better code grouping #1907

Open Karthik-K-N opened 1 month ago

Karthik-K-N commented 1 month ago

/kind feature /area provider/ibmcloud

Describe the solution you'd like [A clear and concise description of what you want to happen.]

Currently in any Power VS service reconcilation are broadly classified into 3 different functionalities

  1. Fetch service instance id from either spec or status Ref: https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/01e1771ca8cbf8b9969bb64b6956b3d470219313/cloud/scope/powervs_cluster.go#L703-L722

  2. Check for existing resources in cloud Ref: https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/01e1771ca8cbf8b9969bb64b6956b3d470219313/cloud/scope/powervs_cluster.go#L725-L733

  3. Create the service Ref: https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/01e1771ca8cbf8b9969bb64b6956b3d470219313/cloud/scope/powervs_cluster.go#L736-L747

Though its working as expected, since we are adding more complex logic as the feature requests, it would be better to refactor to have particular function names rather than generic in most of the cases.

Anything else you would like to add: [Miscellaneous information that will assist in solving the issue.]

Since we are relaying more on controllerCreated variable to decide upon user passed vs controller created resources, Eventually we are moving agaist K8s generic princile of level triggered events. IT has its own drawbacks against advantages, We also need to think of better way to avoid this.

Karthik-K-N commented 1 month ago

/cc @dharaneeshvrd @Amulyam24

Amulyam24 commented 1 month ago

/assign

Karthik-K-N commented 1 week ago

@Amulyam24 since you are refactoring, Do you mind checking for this flow across various resource reconciles and making sure its uniform across all?

  1. If spec.ID is set by user and there is not exist resource in cloud with that id, Fail the reconcilation
  2. If spec.Name is set by user and there is not exist resource with that name, Log the message properly that resource not exist and we are proceeding with creating the resource.