operator-framework / enhancements

Apache License 2.0
9 stars 40 forks source link

Support for Cluster High-availability Mode API in operator-lib #62

Closed varshaprasad96 closed 3 years ago

varshaprasad96 commented 3 years ago

Enhancement on adding library to provide high availability expectations of openshift clusters to users.

Signed-off-by: varshaprasad96 varshaprasad96@gmail.com

anik120 commented 3 years ago

Should this doc be in openshift/enhancements instead?

varshaprasad96 commented 3 years ago

@anik120 Since this is going to be a part of operator-framework/operator-lib, I had created a PR here. I'm fine either way though.

jmrodri commented 3 years ago

Is HA vs. non-HA relevant to operators running on vanilla k8s, and in general any k8s distribution?

* No: this proposal should be moved to https://github.com/openshift/enhancements and the proposed library should live in https://github.com/openshift/library-go

* Yes: the proposed library can go in operator-lib but needs to expose a generic API that returns

  1. If the cluster type supports detecting HA vs. non-HA
  2. If the operator can run in HA mode.

To me, it makes sense to start small and contribute to library-go first with OpenShift-specific HA detection. If requests are made for a generic solution, then revisit an operator-lib library.

So after some investigation I've come to agree with @estroz on this matter. I don't think this needs to go into operator-lib at the moment. In order to get access to the HA information it is actually trivial and I don't see the need for a wrapper library at the moment. It's just a matter of registering the scheme then going a crClient.Get(context.Background(), nn, infraConfig)

Here is an example:

func GetInfraViaControllerRuntime(cc *restclient.Config) error {
    rm, err := apiutil.NewDynamicRESTMapper(cc)
    if err != nil {
        return err
    }

    crClient, err := crclient.New(cc, crclient.Options{
        Scheme: scheme,
        Mapper: rm,
    })
    if err != nil {
        return err
    }

    // Simple query
    nn := types.NamespacedName{
        Name: "cluster",
    }
    infraConfig := &configv1.Infrastructure{}
    err = crClient.Get(context.Background(), nn, infraConfig)
    if err != nil {
        return err
    }
    fmt.Printf("using crclient: %v\n", infraConfig.Status.ControlPlaneTopology)
    fmt.Printf("using crclient: %v\n", infraConfig.Status.InfrastructureTopology)

    return nil
}
jmrodri commented 3 years ago

Closing this enhancement for operator-lib.