From 4ef17f6ee6a4d27841bfc3a76a5fd914f3d40718 Mon Sep 17 00:00:00 2001 From: Balamurali Pandranki Date: Mon, 13 Nov 2023 15:22:59 +0200 Subject: [PATCH] Fixes --- control-plane-server.py | 8 +++--- resources/autoscaler_agent.py | 47 +++++++++++++++++++++-------------- resources/common.py | 2 +- resources/pageserver.py | 21 ++++++++++++++++ 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/control-plane-server.py b/control-plane-server.py index dbdfd7b..ae73e60 100644 --- a/control-plane-server.py +++ b/control-plane-server.py @@ -139,17 +139,17 @@ def read_root(): @app.post("/re-attach") -def re_attach(request: ReAttachRequest): +def re_attach(re_attach_request: ReAttachRequest): tenants = [] - tenants.append(ReAttachResponseTenant(id=request.node_id, gen=1)) + tenants.append(ReAttachResponseTenant(id=re_attach_request.node_id, gen=1)) response = ReAttachResponse(tenants=tenants) return response @app.post("/validate") -def validate(request: ValidateRequest): +def validate(validate_request: ValidateRequest): tenants = [] - for tenant in request.tenants: + for tenant in validate_request.tenants: # TODO: get tenant from k8s resources k8s_tenant = None valid = tenant.gen == k8s_tenant.gen diff --git a/resources/autoscaler_agent.py b/resources/autoscaler_agent.py index 2256535..85316de 100644 --- a/resources/autoscaler_agent.py +++ b/resources/autoscaler_agent.py @@ -9,6 +9,14 @@ def deploy_autoscaler_agent( image: str = "neondatabase/neon:latest", replicas: int = 1, ): + """ + Deploy the autoscaler agent to the cluster + :param kube_client: The kubernetes client to use + :param namespace: The namespace to deploy to + :param image: The image to use for the deployment + :param replicas: The number of replicas to deploy + :return: + """ deployment = autoscaler_agent_deployment(replicas, image) kopf.adopt(deployment) apps_client = kubernetes.client.AppsV1Api(kube_client) @@ -49,8 +57,27 @@ def delete_autoscaler_agent( def autoscaler_agent_deployment( replicas: int, image: str, -): # -> kubernetes.client.V1Deployment: - template = kubernetes.client.V1PodTemplateSpec( +) -> kubernetes.client.V1Deployment: + """ + Generate a deployment for the autoscaler agent + :param replicas: The number of replicas to deploy + :param image: The image to use for the deployment + :return: A kubernetes deployment object + """ + + deployment = kubernetes.client.V1Deployment( + api_version="apps/v1", + kind="Deployment", + metadata=kubernetes.client.V1ObjectMeta( + name="autoscaler-agent", + labels={"app": "autoscaler-agent"}, + ), + spec=kubernetes.client.V1DeploymentSpec( + replicas=1, + selector=kubernetes.client.V1LabelSelector( + match_labels={"app": "autoscaler-agent"}, + ), + template=kubernetes.client.V1PodTemplateSpec( metadata=kubernetes.client.V1ObjectMeta( labels={"app": "autoscaler-agent"}, ), @@ -69,23 +96,7 @@ def autoscaler_agent_deployment( ], ), ) - - spec = kubernetes.client.V1DeploymentSpec( - replicas=1, - selector=kubernetes.client.V1LabelSelector( - match_labels={"app": "autoscaler-agent"}, - ), - template=template, ) - - deployment = kubernetes.client.V1Deployment( - api_version="apps/v1", - kind="Deployment", - metadata=kubernetes.client.V1ObjectMeta( - name="autoscaler-agent", - labels={"app": "autoscaler-agent"}, - ), - spec=spec, ) return deployment diff --git a/resources/common.py b/resources/common.py index 4e471a5..44c386e 100644 --- a/resources/common.py +++ b/resources/common.py @@ -56,7 +56,7 @@ def generate_jwt(private_key: Ed25519PrivateKey, claims: Optional[dict] = None) :param private_key: The private key to sign the JWT with :return: """ - jwt_token = jwt.encode(claims, key=private_key.encode(), algorithm="ED25519") + jwt_token = jwt.encode(claims, key=private_key, algorithm="ED25519") return jwt_token diff --git a/resources/pageserver.py b/resources/pageserver.py index c10515a..2286be9 100644 --- a/resources/pageserver.py +++ b/resources/pageserver.py @@ -21,6 +21,10 @@ def deploy_pageserver( :param resources: resource requirements for the pageserver :param image_pull_policy: image pull policy for the pageserver container image (default: IfNotPresent) :param image: pageserver container image (default: neondatabase/neon) + :param remote_storage_endpoint: endpoint for the remote storage + :param remote_storage_bucket_name: name of the remote storage bucket + :param remote_storage_bucket_region: region of the remote storage bucket + :param remote_storage_prefix_in_bucket: prefix in the remote storage bucket :return: if successful, returns None, otherwise returns an ApiException """ deployment = pageserver_statefulset(namespace, resources, image_pull_policy, image) @@ -55,6 +59,7 @@ def update_pageserver( :param resources: resource requirements for the pageserver :param image_pull_policy: image pull policy for the pageserver container image (default: IfNotPresent) :param image: pageserver container image (default: neondatabase/neon) + :param replicas: number of replicas to update to (default: 3) :return: if successful, returns None, otherwise returns an ApiException """ deployment = pageserver_statefulset(namespace, resources, image_pull_policy, image) @@ -106,6 +111,8 @@ def pageserver_statefulset(namespace: str, :param resources: resource requirements for the pageserver :param image_pull_policy: image pull policy for the pageserver container image (default: IfNotPresent) :param image: default pageserver container image (default: neondatabase/neon) + :param replicas: number of replicas to deploy (default: 1) + :param storage_capacity: storage capacity for the pageserver (default: 1Gi) :return: returns a kubernetes statefulset object """ @@ -257,6 +264,11 @@ def pageserver_statefulset(namespace: str, def pageserver_service( namespace: str, ) -> kubernetes.client.V1Service: + """ + Creates a kubernetes service for the pageserver + :param namespace: namespace to deploy to + :return: returns a kubernetes service object + """ spec = kubernetes.client.V1ServiceSpec( selector={"app": "pageserver"}, ports=[ @@ -287,6 +299,15 @@ def pageserver_configmap( remote_storage_bucket_region: str = "eu-north-1", remote_storage_prefix_in_bucket: str = "/pageserver/", ) -> kubernetes.client.V1ConfigMap: + """ + Creates a kubernetes configmap for the pageserver + :param namespace: namespace to deploy to + :param remote_storage_endpoint: endpoint for the remote storage + :param remote_storage_bucket_name: name of the remote storage bucket + :param remote_storage_bucket_region: region of the remote storage bucket + :param remote_storage_prefix_in_bucket: prefix in the remote storage bucket + :return: returns a kubernetes configmap object + """ configmap = kubernetes.client.V1ConfigMap( api_version="v1", kind="ConfigMap",