From 34e657da77e528ac42e4a7a0b4733e922c48d08f Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Sat, 18 Nov 2023 11:05:22 -0800 Subject: [PATCH 1/5] when snapshots can't be found for version, just pick the most recent (#611) * when snapshots can't be found for version, pick a random version Right now there are no v18 snapshots on xtz-shots, so it's not possible to kickstart a node. This PR will pick the v17 snapshot instead. * fix black --- mkchain/tqchain/mkchain.py | 4 +++- utils/config-generator.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mkchain/tqchain/mkchain.py b/mkchain/tqchain/mkchain.py index f54b19ffe..bceb52efd 100644 --- a/mkchain/tqchain/mkchain.py +++ b/mkchain/tqchain/mkchain.py @@ -250,7 +250,9 @@ def main(): for key_type in keys: accounts[key_type][account] = { "key": keys[key_type], - "is_bootstrap_baker_account": False if account == "authorized-key-0" else True, + "is_bootstrap_baker_account": False + if account == "authorized-key-0" + else True, "bootstrap_balance": "4000000000000", } diff --git a/utils/config-generator.py b/utils/config-generator.py index 46f403c5a..81e6424af 100755 --- a/utils/config-generator.py +++ b/utils/config-generator.py @@ -762,11 +762,14 @@ def create_node_snapshot_config_json(history_mode): and s.get("chain_name") == network_name ] if octez_version: - matching_snapshots = [ + version_matching_snapshots = [ s for s in matching_snapshots if int(octez_version) == s.get("tezos_version").get("version").get("major") ] + if len(version_matching_snapshots): + # If we can't find snapshots of the right octez version, we just pick the most recent available. + matching_snapshots = version_matching_snapshots matching_snapshots = sorted(matching_snapshots, key=lambda s: s.get("block_height")) return matching_snapshots[-1] if len(matching_snapshots) else None From 69240ecaaa667f4bbffb52c3951544467b176db9 Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Tue, 28 Nov 2023 19:59:48 -0800 Subject: [PATCH 2/5] handle metadata website down or returning invalid json (#612) * handle metadata website down or returning invalid json * catch json exception explicitly --- utils/config-generator.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/config-generator.py b/utils/config-generator.py index 81e6424af..4d9fb2c1c 100755 --- a/utils/config-generator.py +++ b/utils/config-generator.py @@ -734,7 +734,13 @@ def create_node_snapshot_config_json(history_mode): octez_container_version = os.environ.get("OCTEZ_VERSION") snapshot_source = os.environ.get("SNAPSHOT_SOURCE") if snapshot_source: - all_snapshots = requests.get(snapshot_source).json() + try: + response = requests.get(snapshot_source) + response.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code + all_snapshots = response.json() + except (requests.exceptions.RequestException, requests.exceptions.JSONDecodeError): # Catches exceptions related to requests and invalid JSON + print(f"Error: unable to retrieve snapshot metadata from {snapshot_source}") + return else: return try: From 03923a2927569704b7707b78e33d350966451715 Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Tue, 28 Nov 2023 21:59:32 -0800 Subject: [PATCH 3/5] add an option to override the network name for snapshot metadata (#614) * add an option to override the network name for snapshot metadata * fix tests * fix other test --- charts/tezos/templates/configs.yaml | 1 + charts/tezos/values.yaml | 6 +++++- test/charts/mainnet.expect.yaml | 1 + test/charts/mainnet2.expect.yaml | 1 + test/charts/private-chain.expect.yaml | 1 + utils/config-generator.py | 5 ++++- 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/charts/tezos/templates/configs.yaml b/charts/tezos/templates/configs.yaml index aeb9f9589..84cd1f07f 100644 --- a/charts/tezos/templates/configs.yaml +++ b/charts/tezos/templates/configs.yaml @@ -21,6 +21,7 @@ data: ROLLING_TARBALL_URL: "{{ .Values.rolling_tarball_url }}" ARCHIVE_TARBALL_URL: "{{ .Values.archive_tarball_url }}" PREFER_TARBALLS: "{{ .Values.prefer_tarballs }}" + SNAPSHOT_METADATA_NETWORK_NAME: "{{ .Values.snapshot_metadata_network_name }}" SNAPSHOT_SOURCE: "{{ .Values.snapshot_source }}" OCTEZ_VERSION: "{{ .Values.images.octez }}" NODE_GLOBALS: | diff --git a/charts/tezos/values.yaml b/charts/tezos/values.yaml index f8f5b0f94..55e3da0bc 100644 --- a/charts/tezos/values.yaml +++ b/charts/tezos/values.yaml @@ -360,6 +360,10 @@ snapshot_source: https://xtz-shots.io/tezos-snapshots.json # If you prefer tarballs, set to "true" below. prefer_tarballs: false +# In case the network name in the snapshot metadata does not correspond to the +# network_name configured in `node_config_network`, hardcode the value here. +# snapshot_metadata_network_name: "weeklynet" + # By default, tezos-k8s will attempt to download the right artifact from # `snapshot_source` set above. You can override and hard-code a snapshot URL # source below. When any of the below variables are set, `snapshot_source` above @@ -397,7 +401,7 @@ expected_proof_of_work: 26 ## - Specify the name of the network which must be recognized by the ## octez-node binary of the Octez image being used. ## - Pass a url that returns the config.json of the network. Example: -## "https://teztnets.xyz/mondaynet". It is helpful for running +## "https://teztnets.xyz/weeklynet". It is helpful for running ## testnets and shouldn't be needed in general. node_config_network: chain_name: mainnet diff --git a/test/charts/mainnet.expect.yaml b/test/charts/mainnet.expect.yaml index 6fc41d610..eeb830773 100644 --- a/test/charts/mainnet.expect.yaml +++ b/test/charts/mainnet.expect.yaml @@ -37,6 +37,7 @@ data: ROLLING_TARBALL_URL: "" ARCHIVE_TARBALL_URL: "" PREFER_TARBALLS: "false" + SNAPSHOT_METADATA_NETWORK_NAME: "" SNAPSHOT_SOURCE: "https://xtz-shots.io/tezos-snapshots.json" OCTEZ_VERSION: "tezos/tezos:v17.3" NODE_GLOBALS: | diff --git a/test/charts/mainnet2.expect.yaml b/test/charts/mainnet2.expect.yaml index ccc8c09b3..e3c380752 100644 --- a/test/charts/mainnet2.expect.yaml +++ b/test/charts/mainnet2.expect.yaml @@ -37,6 +37,7 @@ data: ROLLING_TARBALL_URL: "" ARCHIVE_TARBALL_URL: "" PREFER_TARBALLS: "false" + SNAPSHOT_METADATA_NETWORK_NAME: "" SNAPSHOT_SOURCE: "https://xtz-shots.io/tezos-snapshots.json" OCTEZ_VERSION: "tezos/tezos:v17.3" NODE_GLOBALS: | diff --git a/test/charts/private-chain.expect.yaml b/test/charts/private-chain.expect.yaml index 3d3b8fe1b..3c36edc32 100644 --- a/test/charts/private-chain.expect.yaml +++ b/test/charts/private-chain.expect.yaml @@ -130,6 +130,7 @@ data: ROLLING_TARBALL_URL: "" ARCHIVE_TARBALL_URL: "" PREFER_TARBALLS: "false" + SNAPSHOT_METADATA_NETWORK_NAME: "" SNAPSHOT_SOURCE: "" OCTEZ_VERSION: "tezos/tezos:v15-release" NODE_GLOBALS: | diff --git a/utils/config-generator.py b/utils/config-generator.py index 4d9fb2c1c..2c493162f 100755 --- a/utils/config-generator.py +++ b/utils/config-generator.py @@ -684,7 +684,10 @@ def create_node_config_json( def create_node_snapshot_config_json(history_mode): """Create this node's snapshot config""" - network_name = NETWORK_CONFIG.get("chain_name") + if os.environ.get("SNAPSHOT_METADATA_NETWORK_NAME"): + network_name = os.environ.get("SNAPSHOT_METADATA_NETWORK_NAME") + else: + network_name = NETWORK_CONFIG.get("chain_name") prefer_tarballs = os.environ.get("PREFER_TARBALLS", "").lower() in ( "true", "1", From b463e43b504a6914b3e5cf667fd2b6b4a74aa549 Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Sat, 2 Dec 2023 21:53:27 -0800 Subject: [PATCH 4/5] set pyrometer deployment strategy to "Recreate" to prevent issues in teztnets where pyrometer conflicts and does not restart. --- charts/pyrometer/templates/deployment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts/pyrometer/templates/deployment.yaml b/charts/pyrometer/templates/deployment.yaml index 40b2e8914..c54076b1c 100644 --- a/charts/pyrometer/templates/deployment.yaml +++ b/charts/pyrometer/templates/deployment.yaml @@ -16,6 +16,8 @@ spec: # https://helm.sh/docs/howto/charts_tips_and_tricks/#automatically-roll-deployments checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} spec: + strategy: + type: Recreate securityContext: fsGroup: 1000 containers: From c1fb087af1e4c7d5bf4c367a83dc2ffcda8cc1e2 Mon Sep 17 00:00:00 2001 From: Nicolas Ochem Date: Mon, 4 Dec 2023 18:25:23 -0800 Subject: [PATCH 5/5] make pyrometer a statefulset instead of deployment to prevent conflicts when updating daily --- charts/pyrometer/templates/deployment.yaml | 35 +++++++++++++--------- charts/pyrometer/templates/volume.yaml | 12 -------- 2 files changed, 21 insertions(+), 26 deletions(-) delete mode 100644 charts/pyrometer/templates/volume.yaml diff --git a/charts/pyrometer/templates/deployment.yaml b/charts/pyrometer/templates/deployment.yaml index c54076b1c..f83bee0f2 100644 --- a/charts/pyrometer/templates/deployment.yaml +++ b/charts/pyrometer/templates/deployment.yaml @@ -1,9 +1,10 @@ apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: pyrometer namespace: {{ .Release.Namespace }} spec: + serviceName: pyrometer selector: matchLabels: app: pyrometer @@ -30,9 +31,9 @@ spec: - -d - '/data' ports: - - name: http - containerPort: 8080 - protocol: TCP + - name: http + containerPort: 8080 + protocol: TCP volumeMounts: - name: config-volume mountPath: /config/ @@ -41,20 +42,26 @@ spec: - name: prom-exporter image: {{ .Values.tezos_k8s_images.utils }} ports: - - name: metrics - containerPort: 31732 - protocol: TCP + - name: metrics + containerPort: 31732 + protocol: TCP command: - - /usr/local/bin/python + - /usr/local/bin/python args: - - "-c" - - | + - "-c" + - | {{ tpl ($.Files.Get (print "scripts/pyrometer_exporter.py")) $ | indent 12 }} volumes: - name: config-volume configMap: name: pyrometer-config - - name: pyrometer-volume - # Stores pyrometer's state (like pending queue items) - persistentVolumeClaim: - claimName: pyrometer-volume + volumeClaimTemplates: + - metadata: + name: pyrometer-volume + spec: + storageClassName: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/charts/pyrometer/templates/volume.yaml b/charts/pyrometer/templates/volume.yaml deleted file mode 100644 index fe895e2ce..000000000 --- a/charts/pyrometer/templates/volume.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: "v1" -kind: PersistentVolumeClaim -metadata: - name: pyrometer-volume - namespace: {{ .Release.Namespace }} -spec: - storageClassName: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi