SearchAPI - stolostron/search-v2-operator GitHub Wiki

In this topic you will learn how to expose the search API with a route and how to use the API to resolve search queries.

The API is a GraphQL endpoint. You can use any client like curl or Postman. In this topic we'll use GraphQL Playground which is included with the search API deployment for development purposes.

Configure API access

At this point you should have installed the Search operator or RHACM 2.7+ on your OpenShift cluster.

Create a route to access the API from outside of your cluster.

oc create route passthrough search-api --service=search-search-api -n open-cluster-management

(Optional) Enable the Playground GraphQL client

  1. a (ACM 2.7 only) Pause the search operator and enable Playground on the API deployment.
    NOTE: When the operator is paused it stops watching and updating the search configuration resources.

    oc annotate search search-v2-operator -n open-cluster-management search-pause=true
    oc set env deployment/search-api -n open-cluster-management PLAYGROUND_MODE=true 
    
  2. b (ACM 2.8 or later) Enable Playground on the Search operator spec.

    oc patch search search-v2-operator -n open-cluster-management --type json -p '[{"op": "add", "path": "/spec/deployments/queryapi/envVar", "value": [{"name":"PLAYGROUND_MODE", "value":"true"}]}]'
    
  3. Open Playground from your browser.

    PLAYGROUND_URL=https://$(oc get route search-api -o custom-columns=host:.spec.host --no-headers -n open-cluster-management)/playground
    echo "Open Playground from your browser: $PLAYGROUND_URL"
    

Authentication

The Search API is protected using Kubernetes authentication. You must obtain your OCP API token and add it to the request as the Authorization header.

  • Get your API token from the OCP CLI:
    oc whoami -t
    
  • Get your API token from the OCP web console:
    Go to https://oauth-openshift.apps.{{your-ocp-cluster-url}}/oauth/token/request
    

Add the header Authorization: "Bearer {{your-api-token}}".

Postman example: Note that this is a POST request.