diff --git a/charts/neon-storage-controller/Chart.yaml b/charts/neon-storage-controller/Chart.yaml index 60aaefa..e4c78b8 100644 --- a/charts/neon-storage-controller/Chart.yaml +++ b/charts/neon-storage-controller/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: neon-storage-controller description: Neon storage controller type: application -version: 1.0.12 +version: 1.1.0 appVersion: "0.1.0" kubeVersion: "^1.18.x-x" home: https://neon.tech diff --git a/charts/neon-storage-controller/README.md b/charts/neon-storage-controller/README.md index 7f8f8e4..615e476 100644 --- a/charts/neon-storage-controller/README.md +++ b/charts/neon-storage-controller/README.md @@ -1,6 +1,6 @@ # neon-storage-controller -![Version: 1.0.12](https://img.shields.io/badge/Version-1.0.12-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) [![Lint and Test Charts](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml/badge.svg)](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml) +![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) [![Lint and Test Charts](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml/badge.svg)](https://github.com/neondatabase/helm-charts/actions/workflows/lint-test.yaml) Neon storage controller diff --git a/charts/neon-storage-controller/scripts/register-storage-controller.py b/charts/neon-storage-controller/scripts/register-storage-controller.py index a95f520..57104db 100644 --- a/charts/neon-storage-controller/scripts/register-storage-controller.py +++ b/charts/neon-storage-controller/scripts/register-storage-controller.py @@ -14,17 +14,15 @@ HOST = os.environ["HOST"] PORT = os.getenv("PORT", 50051) -GLOBAL_CPLANE_JWT_TOKEN = os.environ["CONTROL_PLANE_JWT_TOKEN"] -LOCAL_CPLANE_JWT_TOKEN = os.environ["CONTROL_PLANE_JWT_TOKEN"] +CPLANE_JWT_TOKEN = os.environ["CONTROL_PLANE_JWT_TOKEN"] CONSOLE_API_KEY = os.environ["CONSOLE_API_KEY"] # To register new pageservers URL_PATH = "management/api/v2/pageservers" # To get pageservers -ADMIN_URL_PATH = "api/v1/admin/pageservers" +ADMIN_URL_PATH = f"regions/{REGION}/api/v1/admin/pageservers" -GLOBAL_CPLANE_URL = f"{os.environ['GLOBAL_CPLANE_URL'].strip('/')}/{URL_PATH}" -LOCAL_CPLANE_URL = f"{os.environ['LOCAL_CPLANE_URL'].strip('/')}/{URL_PATH}" +CPLANE_MANAGEMENT_URL = f"{os.environ['CPLANE_URL'].strip('/')}/{URL_PATH}" CONSOLE_URL = f"{os.environ['CONSOLE_URL']}/{ADMIN_URL_PATH}" PAYLOAD = dict( @@ -43,7 +41,7 @@ ) -def get_data(url, token, host=None): +def get_data(url, token, host=None, method="GET", data=None, raise_on_error=True): if host is not None: url = f"{url}/{host}" headers = { @@ -52,7 +50,7 @@ def get_data(url, token, host=None): "Content-Type": "application/json", } # Check if the server is already registered - req = urllib.request.Request(url=url, headers=headers, method="GET") + req = urllib.request.Request(url=url, headers=headers, method=method, data=data) try: with urllib.request.urlopen(req) as response: code = response.getcode() @@ -64,11 +62,14 @@ def get_data(url, token, host=None): if code == 200: return json.loads(response_body) - raise Exception(f'GET {url} returned unexpected response: {code} {response_body}') + if raise_on_error: + raise Exception(f'{method} {url} returned unexpected response: {code} {response_body}') + + return {} def get_pageserver_id(url, token): - data = get_data(url, token, HOST) + data = get_data(url, token, HOST, raise_on_error=False) if "node_id" in data: return int(data["node_id"]) @@ -85,21 +86,8 @@ def get_pageserver_version(): def register(url, token, payload): - headers = { - "Authorization": f"Bearer {token}", - "Accept": "application/json", - "Content-Type": "application/json", - "User-Agent": "Python script 1.0", - } data = str(json.dumps(payload)).encode() - req = urllib.request.Request( - url=url, - data=data, - headers=headers, - method="POST", - ) - with urllib.request.urlopen(req) as resp: - response = json.loads(resp.read()) + response = get_data(url, token, data=data, method="POST") log.info(response) if "node_id" in response: return int(response["node_id"]) @@ -117,8 +105,7 @@ def register(url, token, payload): log.info( json.dumps( dict( - GLOBAL_CPLANE_URL=GLOBAL_CPLANE_URL, - LOCAL_CPLANE_URL=LOCAL_CPLANE_URL, + CPLANE_MANAGEMENT_URL=CPLANE_MANAGEMENT_URL, CONSOLE_URL=CONSOLE_URL, **PAYLOAD, ), @@ -136,43 +123,20 @@ def register(url, token, payload): log.info(f"found latest version={version} for region={REGION}") PAYLOAD.update(dict(version=version)) - log.info("check if pageserver already registered or not in console") - node_id_in_console = get_pageserver_id( - GLOBAL_CPLANE_URL, GLOBAL_CPLANE_JWT_TOKEN - ) - - if node_id_in_console is None: - log.info("Registering storage controller in console") - node_id_in_console = register( - GLOBAL_CPLANE_URL, GLOBAL_CPLANE_JWT_TOKEN, PAYLOAD - ) - log.info( - f"Storage controller registered in console with node_id \ - {node_id_in_console}" - ) - else: - log.info( - f"Storage controller already registered in console with node_id \ - {node_id_in_console}" - ) - - log.info("check if pageserver already registered or not in cplane") - node_id_in_cplane = get_pageserver_id( - LOCAL_CPLANE_URL, LOCAL_CPLANE_JWT_TOKEN + log.info("check if pageserver already registered") + node_id = get_pageserver_id( + CPLANE_MANAGEMENT_URL, CPLANE_JWT_TOKEN ) - if node_id_in_cplane is None and node_id_in_console is not None: - PAYLOAD.update(dict(node_id=node_id_in_console)) - log.info("Registering storage controller in cplane") - node_id_in_cplane = register( - LOCAL_CPLANE_URL, LOCAL_CPLANE_JWT_TOKEN, PAYLOAD + if node_id is None: + log.info("Registering storage controller") + node_id = register( + CPLANE_MANAGEMENT_URL, CPLANE_JWT_TOKEN, PAYLOAD ) log.info( - f"Storage controller registered in cplane with node_id \ - {node_id_in_cplane}" + f"Storage controller registered with node_id {node_id}" ) else: log.info( - f"Storage controller already registered in cplane with node_id \ - {node_id_in_cplane}" + f"Storage controller already registered with node_id {node_id}" ) diff --git a/charts/neon-storage-controller/templates/post-install-job.yaml b/charts/neon-storage-controller/templates/post-install-job.yaml index bf8e22d..4a75886 100644 --- a/charts/neon-storage-controller/templates/post-install-job.yaml +++ b/charts/neon-storage-controller/templates/post-install-job.yaml @@ -2,11 +2,8 @@ {{ if (empty .Values.registerControlPlane.region_id ) }} {{- fail (printf "Value for .Values.registerControlPlane.region_id is empty") }} {{- end }} -{{ if (empty .Values.registerControlPlane.global_cplane_url) }} - {{- fail (printf "Value for .Values.registerControlPlane.global_cplane_url is empty") }} -{{- end }} -{{ if (empty .Values.registerControlPlane.local_cplane_url) }} - {{- fail (printf "Value for .Values.registerControlPlane.local_cplane_url is empty") }} +{{ if (empty .Values.registerControlPlane.cplane_url) }} + {{- fail (printf "Value for .Values.registerControlPlane.cplane_url is empty") }} {{- end }} apiVersion: batch/v1 kind: Job @@ -61,10 +58,8 @@ spec: value: {{ index .Values.service.annotations "external-dns.alpha.kubernetes.io/hostname" | quote }} - name: PORT value: {{ .Values.service.port | quote }} - - name: GLOBAL_CPLANE_URL - value: {{ .Values.registerControlPlane.global_cplane_url | quote }} - - name: LOCAL_CPLANE_URL - value: {{ .Values.registerControlPlane.local_cplane_url | quote }} + - name: CPLANE_URL + value: {{ .Values.registerControlPlane.cplane_url | quote }} - name: CONSOLE_URL value: {{ .Values.registerControlPlane.console_url | quote }} - name: REGION_ID diff --git a/charts/neon-storage-controller/values.yaml b/charts/neon-storage-controller/values.yaml index 3c88ebf..fd7f457 100644 --- a/charts/neon-storage-controller/values.yaml +++ b/charts/neon-storage-controller/values.yaml @@ -41,18 +41,11 @@ settings: # This will run postinstall job registerControlPlane: enable: false - # region_id: "aws-us-east-2" - # generate using - # curl https://console.stage.neon.tech/regions/console/api/v1/admin/issue_token \ - # -H "Accept: application/json" \ - # -H "Content-Type: application/json" \ - # -H "Authorization: Bearer $NEON_API_KEY" \ - # -X POST -d '{"ttl_seconds": 31536000, "scope": "infra"}' + # region_id: "" controlPlaneJwtToken: "" # Console API key to list existing pageserver to get version apiKey: "" - # global_cplane_url: "http://neon-internal-api.aws.neon.build" - # local_cplane_url: "https://control-plane.zeta.us-east-2.internal.aws.neon.build" + # cplane_url: "" # console_url: "" resources: limits: