IBM / ibm-mongodb-operator

ibm-mongodb-operator
Apache License 2.0
10 stars 17 forks source link

update fuction for MongoDB custom resource #59

Open horis233 opened 4 years ago

horis233 commented 4 years ago

@kgcarr

Currently, MongoDB operator only supports create and delete function. We need to support update function when users edit MongoDB custom resource.

horis233 commented 4 years ago

@kgcarr I can provide an idea about how to implement the update function.

  1. In the 1Q release, we ignore all the IsAlreadyExists error when creating the resources.
    err = r.client.Create(context.TODO(), obj)
    if err != nil && !errors.IsAlreadyExists(err) {
        return fmt.Errorf("could not Create resource: %v", err)
    }
  2. In the 2Q, we and another check for the IsAlreadyExists, if the resource is already exist, you can choose to update the resource.
    err = r.client.Create(context.TODO(), obj)
    if err != nil && !errors.IsAlreadyExists(err) {
        return fmt.Errorf("could not Create resource: %v", err)
    }
        if errors.IsAlreadyExists(err) {
                    err = r.client.Update(context.TODO(), obj)
                     if err != nil {
                         return fmt.Errorf("could not Update resource: %v", err)
                     }
        }

I am sure if all the MongoDB resources are permitted to be updated in the day2 option. You may need to take a look at this.