-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACM:8774: Implement federated global search (#189)
* Initial federated search implementation Signed-off-by: Jorge Padilla <[email protected]> * Save progress Signed-off-by: Jorge Padilla <[email protected]> * Save progress Signed-off-by: Jorge Padilla <[email protected]> * Update make Signed-off-by: Jorge Padilla <[email protected]> * Cleanup implementation Signed-off-by: Jorge Padilla <[email protected]> * Update make Signed-off-by: Jorge Padilla <[email protected]> * Support GraphQL __schema Signed-off-by: Jorge Padilla <[email protected]> * Fix searchSchema Signed-off-by: Jorge Padilla <[email protected]> * Fix searchSchema empty state Signed-off-by: Jorge Padilla <[email protected]> * Simplify Make Signed-off-by: Jorge Padilla <[email protected]> * Lint and fedConfig updates Signed-off-by: Jorge Padilla <[email protected]> * Hack for alias issue Signed-off-by: Jorge Padilla <[email protected]> * Update managedhub prop to match console Signed-off-by: Jorge Padilla <[email protected]> * Remove duplicates; initial TLS validation Signed-off-by: Jorge Padilla <[email protected]> * Add getFederatedResponse function (#193) * getFederatedResponse function Signed-off-by: Sherin Varughese <[email protected]> * add comments Signed-off-by: Sherin Varughese <[email protected]> --------- Signed-off-by: Sherin Varughese <[email protected]> * add mockClient (#194) Signed-off-by: Sherin Varughese <[email protected]> * Read federation configuration from kubeapi Signed-off-by: Jorge Padilla <[email protected]> * update Tests (#195) Signed-off-by: Sherin Varughese <[email protected]> * Configure local secret Signed-off-by: Jorge Padilla <[email protected]> * fix lint (#196) Signed-off-by: Sherin Varughese <[email protected]> * Simplify setup and update http client pool (#198) * Simplify setup; disable client pool Signed-off-by: Jorge Padilla <[email protected]> * Simplify setup; disable client pool Signed-off-by: Jorge Padilla <[email protected]> * Refactor Http client code Signed-off-by: Jorge Padilla <[email protected]> * Use HTTPClient interface Signed-off-by: Jorge Padilla <[email protected]> * Update mock client pool Signed-off-by: Jorge Padilla <[email protected]> * cleanup Signed-off-by: Jorge Padilla <[email protected]> * Refactor Signed-off-by: Jorge Padilla <[email protected]> * Simplify ManagedServiceAccount enablement Signed-off-by: Jorge Padilla <[email protected]> * Remove old setup script Signed-off-by: Jorge Padilla <[email protected]> --------- Signed-off-by: Jorge Padilla <[email protected]> * Add debug Signed-off-by: Jorge Padilla <[email protected]> * change GraphQLPayload errors struct (#197) * change GraphQLPayload errors struct Signed-off-by: Sherin Varughese <[email protected]> * remove client Signed-off-by: Sherin Varughese <[email protected]> --------- Signed-off-by: Sherin Varughese <[email protected]> * Fix client pool (#201) Signed-off-by: Jorge Padilla <[email protected]> * mock GetHttpClient fn (#200) Signed-off-by: Sherin Varughese <[email protected]> * Change managedHub property to camelCase Signed-off-by: Jorge Padilla <[email protected]> * [Federation side branch] Use a feature flag to enable federated search (#202) * Use a feature flag to enable federated search Signed-off-by: Jorge Padilla <[email protected]> * Update fedConfig (cache and async); remove global sa Signed-off-by: Jorge Padilla <[email protected]> * Improve setup.sh Signed-off-by: Jorge Padilla <[email protected]> * Cleanup Signed-off-by: Jorge Padilla <[email protected]> * Update setup secript; add related WIP Signed-off-by: Jorge Padilla <[email protected]> --------- Signed-off-by: Jorge Padilla <[email protected]> * Review comments; disable related Signed-off-by: Jorge Padilla <[email protected]> * Review comments Signed-off-by: Jorge Padilla <[email protected]> --------- Signed-off-by: Jorge Padilla <[email protected]> Signed-off-by: Sherin Varughese <[email protected]> Co-authored-by: Sherin Varughese <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,261 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Contributors to the Open Cluster Management project | ||
|
||
//go:build development | ||
// +build development | ||
|
||
// This file is excluded from compilation unless the build flag -tags development is used. | ||
// Use `make run` to run with the development flag. | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
func init() { | ||
klog.Warning("!!! Running in development mode. !!!") | ||
os.Setenv("FEATURE_FEDERATED_SEARCH", "true") | ||
Cfg = new() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Federated Search | ||
|
||
Use federated search to query and combine results from multiple Red Hat Advanced Cluster Management. | ||
|
||
## Pre-requisites | ||
1. Multicluster Global Hub Operator 1.0.0 or later. | ||
2. Red Hat Advanced Cluster Management 2.10.0 or later. | ||
- Managed Hub clusters mu have RHACM 2.9.0 or later | ||
|
||
## Setup | ||
Execute the script at `./setup.sh` to configure Global Search on the Global Hub cluster. | ||
|
||
The script automates the following steps: | ||
1. Enable the Managed Service Account add-on in the MulticlusterEngine CR. | ||
2. Create a service account and secret to access resources managed from the Global Hub cluster. | ||
3. Create a route and managed service acount on each managed hub to access resources managed by each managed hub. | ||
4. Configure the Console to use the Global Search API. | ||
|
||
> NOTES: | ||
> Must run using an account with role `open-cluster-management:admin-aggregate` or higher. | ||
> You must re-run this script when a Managed Hub is added. | ||
> This setup is required for Development Preview, it will be fully automated for GA. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# !/bin/bash | ||
# Copyright Contributors to the Open Cluster Management project | ||
|
||
# Delete resources created by setup.sh | ||
MANAGED_HUBS=($(oc get managedcluster -o json | jq -r '.items[] | select(.status.clusterClaims[] | .name == "hub.open-cluster-management.io" and .value != "NotInstalled") | .metadata.name')) | ||
|
||
for MANAGED_HUB in "${MANAGED_HUBS[@]}"; do | ||
oc delete -n ${MANAGED_HUB} -f ./federation-managed-hub-config.yaml | ||
done | ||
|
||
# Disable global search feature in the console. | ||
oc patch configmap console-mce-config -n multicluster-engine -p '{"data": {"globalSearchFeatureFlag": "disabled"}}' | ||
oc patch configmap console-config -n open-cluster-management -p '{"data": {"globalSearchFeatureFlag": "disabled"}}' | ||
|
||
# Disable federated search feature in the search-api. | ||
oc patch search search-v2-operator -n open-cluster-management --type='merge' -p '{"spec":{"deployments":{"queryapi":{"envVar":[{"name":"FEATURE_FEDERATED_SEARCH", "value":"false"}]}}}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright Contributors to the Open Cluster Management project | ||
package federated | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
"sync" | ||
"time" | ||
|
||
config "github.com/stolostron/search-v2-api/pkg/config" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
// Returns a client to process the federated request. | ||
func GetHttpClient(remoteService RemoteSearchService) HTTPClient { | ||
// Get http client from pool. | ||
client := httpClientPool.Get().(*RealHTTPClient) | ||
|
||
tlsConfig := tls.Config{ | ||
MinVersion: tls.VersionTLS13, // TODO: Verify if 1.3 is ok now. It caused issues in the past. | ||
} | ||
if remoteService.TLSCert != "" && remoteService.TLSKey != "" { | ||
tlsConfig.Certificates = []tls.Certificate{ | ||
{ | ||
// RootCAs: nil, | ||
Certificate: [][]byte{[]byte(remoteService.TLSCert)}, | ||
PrivateKey: []byte(remoteService.TLSKey), | ||
}, | ||
} | ||
} else { | ||
klog.Warningf("TLS cert and key not provided for %s. Skipping TLS verification.", remoteService.Name) | ||
tlsConfig.InsecureSkipVerify = true // #nosec G402 - FIXME: Add TLS verification. | ||
} | ||
|
||
client.SetTLSClientConfig(&tlsConfig) | ||
|
||
return client | ||
} | ||
|
||
// shared HTTP transport and client for efficient connection reuse as per | ||
// godoc: https://cs.opensource.google/go/go/+/go1.21.5:src/net/http/transport.go;l=95 and | ||
// https://stuartleeks.com/posts/connection-re-use-in-golang-with-http-client/ | ||
var tr = &http.Transport{ | ||
MaxIdleConns: config.Cfg.Federation.HttpPool.MaxIdleConns, | ||
IdleConnTimeout: time.Duration(config.Cfg.Federation.HttpPool.MaxIdleConnTimeout) * time.Millisecond, | ||
ResponseHeaderTimeout: time.Duration(config.Cfg.Federation.HttpPool.ResponseHeaderTimeout) * time.Millisecond, | ||
DisableKeepAlives: false, | ||
TLSClientConfig: &tls.Config{ | ||
MinVersion: tls.VersionTLS13, // TODO: Verify if 1.3 is ok now. It caused issues in the past. | ||
}, | ||
MaxConnsPerHost: config.Cfg.Federation.HttpPool.MaxConnsPerHost, | ||
MaxIdleConnsPerHost: config.Cfg.Federation.HttpPool.MaxIdleConnPerHost, | ||
} | ||
|
||
var httpClientPool = sync.Pool{ | ||
New: func() interface{} { | ||
klog.V(6).Infof("Creating new RealHTTPClient from pool.") | ||
return &RealHTTPClient{ | ||
&http.Client{ | ||
Transport: tr, | ||
Timeout: time.Duration(config.Cfg.Federation.HttpPool.RequestTimeout) * time.Millisecond, | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
// HTTPClient is an interface for an HTTP client. | ||
type HTTPClient interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
SetTLSClientConfig(*tls.Config) | ||
} | ||
|
||
// RealHTTPClient is a real implementation of the HTTPClient interface. | ||
type RealHTTPClient struct { | ||
*http.Client | ||
} | ||
|
||
// Do implements the HTTPClient interface for RealHTTPClient. | ||
func (c RealHTTPClient) Do(req *http.Request) (*http.Response, error) { | ||
return c.Client.Do(req) | ||
} | ||
|
||
// SetTLSClientConfig sets the TLS client configuration for the HTTP client. | ||
func (c RealHTTPClient) SetTLSClientConfig(config *tls.Config) { | ||
c.Transport.(*http.Transport).TLSClientConfig = config | ||
} |
Oops, something went wrong.