Hi, is there a way to use the same block for k8s b...
# prefect-community
a
Hi, is there a way to use the same block for k8s based deployment while passing customisations separately for memory and cpu requests/limits?
r
Yes there is, see

https://prefect-community.slack.com/files/U03LH98F8S2/F04J85P3HEZ/673963ce-798f-4df1-b099-d0b9496dc1b7.jpeg

a
Thanks @redsquare saw the thread. When you mentioned that you pass it through the code, how do you do that exactly? Like as what variable should I pass it and should it be done in the flow code or somewhere else?
What I am looking at is basically that I have a base kubernetes config block without any customisation. I want to be able to use that with different memory/cpu customisations for different flows
r
So if you load the block then augment it by adding customisations array to it loaded_block.customizations=[ { "op": "add", "path": "/spec/template/spec/resources", "value": {"limits": {"memory": "8Gi", "cpu": "4000m"}}, } ]
then use that in your deploy
a
okay which means I will have to use python object for deployment which I have not been able to figure out and hence doing it via CLI 😐 I wanted to create a flow which basically deploys other flows by passing path, flowname and memory/cpu requirements but the python object keeps giving this error
r
The apply is a property of build from flow
e.g
a
Damn! I tried it just once and that too by looking at the documentation on the page 😞 Thanks a lot
r
the code I pasted above is wrong, I'll edit when I'm on my laptop
a
Sure, will wait for that. Thanks a lot!
r
infra_overrides['customizations']=[ { "op": "add", "path": "/spec/template/spec/resources", "value": {"limits": {"memory": "8Gi", "cpu": "4000m"}}, } ]
infra_overrides is on the deployment
a
So I first create create_query_log_deployments and then add infra_overrides on that. Correct?
hey @redsquare do you have any document which can help? I can't figure out what to do with after creating create_query_log_deployments
r
You pass it in to the Deployment.build_from_flow
a
okay, I think I got confused because a part of that screenshot you shared is not visible (right side cropped). If possible, can you share that please?
r
image.png
sorry - did it on my phone whilst walking
a
Thanks mate. This check_query_log_deployment object I created with added infra_overrides. What next should I do?
I think I got this now, documentation looks misleading. Thanks a lot for your help.
r
No worries, cool you got it sorted
a
Hey @redsquare, sorry for bothering you again. I followed the steps you mentioned. I passed this as infra_override in build_from_flow but memory requests/limits doesn't seem to work. I checked the details of the pod created but memory limits/requests were not there. Do you maybe know what I am doing wrong?
Copy code
infra_overrides = {
		  "customizations": [
		    {
		      "op": "add",
		      "path": "/spec/template/spec/resources",
		      "value": {
		        "limits": {
		          "memory": memory_limit,
		          "cpu": cpu_limit
		        },
		        "requests": {
		          "memory": memory_request,
		          "cpu": cpu_request
		        }
		      }
		    }
		  ]
		}
r
show me exactly how you are doing it
and adding it to the deployment
a
this is the complete code
Copy code
deployment = Deployment.build_from_flow(
	flow = eval(flow_name),
	description = "Flow in the location - {}:{}".format(script_path, flow_name),
	name = deployment_name,
	infrastructure = KubernetesJob.load("kubejob-base"),
	infra_overrides = {
	  "customizations": [
	    {
	      "op": "add",
	      "path": "/spec/template/spec/resources",
	      "value": {
	        "limits": {
	          "memory": memory_limit,
	          "cpu": cpu_limit
	        },
	        "requests": {
	          "memory": memory_request,
	          "cpu": cpu_request
	        }
	      }
	    }
	  ]
	},
    work_queue_name = work_queue_name,
    path = folder.replace('.','/'),
    apply = True
	)
this creates the deployment and runs the flow but the pod doesn't have the requests and limits
r
infra_overrides takes an array
97767efe-397b-4a53-816a-bbd225d6b8fb.jpeg
a
passing anything but dictionary gives the error -
value is not a valid dict (type=type_error.dict)
I am doing it like this which creates the deployment successfully but doesn't show the customizations applied on pod
r
see in my code on the deploy we just say infra_overrides = infra_overrides
a
and in infra_overrides you are passing something similar to what I have wrote if I understood it correctly from the resourcePatch append you are doing to the list