github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/lib/proxy/available.go (about)

     1  package proxy
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  
     7  	"k8s.io/apimachinery/pkg/runtime/schema"
     8  	apidiscovery "k8s.io/client-go/discovery"
     9  )
    10  
    11  const (
    12  	// This is the error message thrown by ServerSupportsVersion function
    13  	// when an API version is not supported by the server.
    14  	notSupportedErrorMessage = "server does not support API version"
    15  )
    16  
    17  // IsAPIAvailable return true if OpenShift config API is present on the cluster.
    18  // Otherwise, supported is set to false.
    19  func IsAPIAvailable(discovery apidiscovery.DiscoveryInterface) (supported bool, err error) {
    20  	if discovery == nil {
    21  		err = errors.New("discovery interface can not be <nil>")
    22  		return
    23  	}
    24  
    25  	opStatusGV := schema.GroupVersion{
    26  		Group:   "config.openshift.io",
    27  		Version: "v1",
    28  	}
    29  	if discoveryErr := apidiscovery.ServerSupportsVersion(discovery, opStatusGV); discoveryErr != nil {
    30  		if strings.Contains(discoveryErr.Error(), notSupportedErrorMessage) {
    31  			return
    32  		}
    33  
    34  		err = discoveryErr
    35  		return
    36  	}
    37  
    38  	supported = true
    39  	return
    40  }