@@ -437,23 +437,7 @@ def get_statefulset_crate_command(
437437 settings = {
438438 "-Cstats.enabled" : "true" ,
439439 "-Ccluster.name" : cluster_name ,
440- # This is a clever way of doing string split in SH and picking the last
441- # item. Here's how it works:
442- #
443- # `hostname` is e.g. `crate-data-hot-11111111-1111-1111-1111-111111111111-12`
444- # for a StatefulSet that has at least 13 replicas (hence the 12 a the
445- # end). What we want now is to get the `12` from the end. In Bash, one
446- # would do `${$(hostname)##*-}` to do a greedy prefix removal. However,
447- # such string manipulations don't exist in SH.
448- # We can, however, make use of the `cut` command that allows splitting
449- # a string at an arbitrary delimiter and allows picking a field.
450- # However, fields can only be picked from the beginning; there's no
451- # negative indexing to get the last field.
452- # Now, by reversing the hostname, then taking the first field, we get
453- # `21`. We can again reverse that to get what we want.
454- #
455- # https://stackoverflow.com/a/9125818
456- "-Cnode.name" : f"{ crate_node_name_prefix } $(hostname | rev | cut -d- -f1 | rev)" ,
440+ "-Cnode.name" : f"{ crate_node_name_prefix } $(hostname | awk -F- '{{print $NF}}')" ,
457441 "-Ccluster.initial_master_nodes" : "," .join (master_nodes ),
458442 "-Cdiscovery.seed_providers" : "srv" ,
459443 "-Cdiscovery.srv.query" : f"_cluster._tcp.crate-discovery-{ name } .{ namespace } .svc.cluster.local" , # noqa
@@ -520,7 +504,7 @@ def get_statefulset_crate_command(
520504 # projects/<account-id>/zones/us-central1-a
521505 settings [
522506 "-Cnode.attr.zone"
523- ] = f"$(curl -s '{ url } ' -H 'Metadata-Flavor: Google' | rev | cut -d '/' -f 1 | rev )" # noqa
507+ ] = f"$(curl -s '{ url } ' -H 'Metadata-Flavor: Google' | awk -F '/' '{{print $NF}}' )" # noqa
524508
525509 if cluster_settings :
526510 for k , v in cluster_settings .items ():
0 commit comments