@@ -332,12 +332,13 @@ def cluster_distribution_version(hosts, client_options, client_factory=EsClientF
332332 :param client_options: The client options to customize the Elasticsearch client.
333333 :param client_factory: Factory class that creates the Elasticsearch client.
334334 :return: The cluster's build flavor, version number, and build hash. For Serverless Elasticsearch these may all be
335- the build flavor value.
335+ the build flavor value. Also returns the operator status (always False for stateful).
336336 """
337337 # no way for us to know whether we're talking to a serverless elasticsearch or not, so we default to the sync client
338338 es = client_factory (hosts , client_options ).create ()
339- # unconditionally wait for the REST layer - if it's not up by then, we'll intentionally raise the original error
340- wait_for_rest_layer (es )
339+
340+ # wait_for_rest_layer calls the Cluster Health API, which is not available for unprivileged users on Serverless
341+ # As a result, we need to call the info API first to know if we can call wait_for_rest_layer().
341342 version = es .info ()["version" ]
342343
343344 version_build_flavor = version .get ("build_flavor" , "oss" )
@@ -346,7 +347,16 @@ def cluster_distribution_version(hosts, client_options, client_factory=EsClientF
346347 # version number does not exist for serverless
347348 version_number = version .get ("number" , version_build_flavor )
348349
349- return version_build_flavor , version_number , version_build_hash
350+ serverless_operator = False
351+ if versions .is_serverless (version_build_flavor ):
352+ authentication_info = es .perform_request (method = "GET" , path = "/_security/_authenticate" )
353+ serverless_operator = authentication_info .body .get ("operator" , False )
354+
355+ if not versions .is_serverless (version_build_flavor ) or serverless_operator is True :
356+ # if available, unconditionally wait for the REST layer - if it's not up, we'll intentionally raise the original error
357+ wait_for_rest_layer (es )
358+
359+ return version_build_flavor , version_number , version_build_hash , serverless_operator
350360
351361
352362def create_api_key (es , client_id , max_attempts = 5 ):
0 commit comments