Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't truncate names too arbitrarily #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cl/op-node/op_node_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def get_beacon_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.CL_TYPE.op_node,
client_type=constants.CLIENT_TYPES.cl,
image=participant.cl_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.cl_image),
connected_client=el_context.client_name,
extra_labels=participant.cl_extra_labels,
),
Expand Down
3 changes: 2 additions & 1 deletion src/el/op-besu/op_besu_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ethereum_package_constants = import_module(

constants = import_module("../../package_io/constants.star")
observability = import_module("../../observability/observability.star")
util = import_module("../../util.star")

RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
Expand Down Expand Up @@ -261,7 +262,7 @@ def get_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.EL_TYPE.op_besu,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.el_image),
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels,
),
Expand Down
3 changes: 2 additions & 1 deletion src/el/op-erigon/op_erigon_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ethereum_package_constants = import_module(

constants = import_module("../../package_io/constants.star")
observability = import_module("../../observability/observability.star")
util = import_module("../../util.star")

RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
Expand Down Expand Up @@ -256,7 +257,7 @@ def get_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.EL_TYPE.op_erigon,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.el_image),
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels,
),
Expand Down
6 changes: 5 additions & 1 deletion src/el/op-geth/op_geth_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ethereum_package_constants = import_module(
constants = import_module("../../package_io/constants.star")
observability = import_module("../../observability/observability.star")
interop_constants = import_module("../../interop/constants.star")
util = import_module("../../util.star")

RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
Expand Down Expand Up @@ -268,6 +269,9 @@ def get_config(
subcommand_strs.append(" ".join(cmd))
command_str = " && ".join(subcommand_strs)

plan.print(">>>", participant.el_image)
plan.print(">>>", util.label_from_image(participant.el_image))

config_args = {
"image": participant.el_image,
"ports": ports,
Expand All @@ -279,7 +283,7 @@ def get_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.EL_TYPE.op_geth,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.el_image),
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels,
),
Expand Down
3 changes: 2 additions & 1 deletion src/el/op-nethermind/op_nethermind_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ethereum_package_constants = import_module(

constants = import_module("../../package_io/constants.star")
observability = import_module("../../observability/observability.star")
util = import_module("../../util.star")

RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
Expand Down Expand Up @@ -248,7 +249,7 @@ def get_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.EL_TYPE.op_nethermind,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.el_image),
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels,
),
Expand Down
3 changes: 2 additions & 1 deletion src/el/op-reth/op_reth_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ethereum_package_input_parser = import_module(

constants = import_module("../../package_io/constants.star")
observability = import_module("../../observability/observability.star")
util = import_module("../../util.star")

RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
Expand Down Expand Up @@ -243,7 +244,7 @@ def get_config(
"labels": ethereum_package_shared_utils.label_maker(
client=constants.EL_TYPE.op_reth,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
image=util.label_from_image(participant.el_image),
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels,
),
Expand Down
2 changes: 0 additions & 2 deletions src/package_io/constants.star
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ VOLUME_SIZE = {
"hildr_volume_size": 1000, # 1GB
},
}

MAX_LABEL_LENGTH = 63
29 changes: 29 additions & 0 deletions src/util.star
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,32 @@ def to_hex_chain_id(chain_id):
out = "%x" % int(chain_id)
pad = 64 - len(out)
return "0x" + "0" * pad + out


def label_from_image(image):
"""Generate a label from an image name.

Truncate the image label to 63 characters max to comply with k8s label length limit.
The label is expected to be in the format of <registry>/<image>:<tag>.
But it case it's too long, we take the longest meaningful suffix
(so that it's still recognizable), breaking at slashes (so that it's valid).

Args:
image: The image to label.

Returns:
The potentially truncated label.
"""
max_length = 63
if len(image) <= max_length:
return image
cpts = image.split("/")
label = cpts[-1]
for cpt in reversed(cpts[:-1]):
if len(label) + len(cpt) + 1 > max_length:
break
label = cpt + "/" + label
# just in case the last part is already too long
if len(label) > max_length:
label = label[-max_length:]
return label
Loading