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 Power VS reconcile helpers for better readbility and better code grouping #1907

Open
Karthik-K-N opened this issue Aug 5, 2024 · 3 comments · May be fixed by #1937
Open

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

Karthik-K-N opened this issue Aug 5, 2024 · 3 comments · May be fixed by #1937
Assignees
Labels
area/provider/ibmcloud Issues or PRs related to ibmcloud provider kind/feature Categorizes issue or PR as related to a new feature.
Milestone

Comments

@Karthik-K-N
Copy link
Contributor

/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:

    serviceInstanceID := s.GetServiceInstanceID()
    if serviceInstanceID != "" {
    s.V(3).Info("PowerVS service instance ID is set, fetching details", "id", serviceInstanceID)
    // if serviceInstanceID is set, verify that it exist and in active state.
    serviceInstance, _, err := s.ResourceClient.GetResourceInstance(&resourcecontrollerv2.GetResourceInstanceOptions{
    ID: &serviceInstanceID,
    })
    if err != nil {
    return false, err
    }
    if serviceInstance == nil {
    return false, fmt.Errorf("failed to get PowerVS service instance with ID %s", serviceInstanceID)
    }
    requeue, err := s.checkServiceInstanceState(*serviceInstance)
    if err != nil {
    return false, err
    }
    return requeue, nil
    }

  2. Check for existing resources in cloud
    Ref:

    serviceInstanceID, requeue, err := s.isServiceInstanceExists()
    if err != nil {
    return false, err
    }
    // Set the status of IBMPowerVSCluster object with serviceInstanceID and ControllerCreated to false as PowerVS service instance is already exist in cloud.
    if serviceInstanceID != "" {
    s.SetStatus(infrav1beta2.ResourceTypeServiceInstance, infrav1beta2.ResourceReference{ID: &serviceInstanceID, ControllerCreated: ptr.To(false)})
    return requeue, nil
    }

  3. Create the service
    Ref:

    serviceInstance, err := s.createServiceInstance()
    if err != nil {
    return false, fmt.Errorf("failed to create PowerVS service instance: %w", err)
    }
    if serviceInstance == nil {
    return false, fmt.Errorf("created PowerVS service instance is nil")
    }
    s.Info("Created PowerVS service instance", "id", serviceInstance.GUID)
    // Set the status of IBMPowerVSCluster object with serviceInstanceID and ControllerCreated to true as new PowerVS service instance is created.
    s.SetStatus(infrav1beta2.ResourceTypeServiceInstance, infrav1beta2.ResourceReference{ID: serviceInstance.GUID, ControllerCreated: ptr.To(true)})
    return true, nil

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.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. area/provider/ibmcloud Issues or PRs related to ibmcloud provider labels Aug 5, 2024
@Karthik-K-N
Copy link
Contributor Author

/cc @dharaneeshvrd @Amulyam24

@mkumatag mkumatag added this to the v0.9.0 milestone Aug 6, 2024
@Amulyam24
Copy link
Contributor

/assign

@Karthik-K-N
Copy link
Contributor Author

@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.

@Amulyam24 Amulyam24 linked a pull request Sep 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/provider/ibmcloud Issues or PRs related to ibmcloud provider kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants