55import yaml
66
77parser = argparse .ArgumentParser ()
8- parser .add_argument ("--prefix" , default = "xx" ,
9- help = "find files matching prefix" )
8+ parser .add_argument ("--prefix" , default = "xx" , help = "find files matching prefix" )
109parser .add_argument ("--folder" , required = True , help = "Output folder" )
1110args , _ = parser .parse_known_args ()
1211
3029HELM_CREATERESOURCES_RBAC_IF_START = "{{- if .Values.managerCreateResources }}\n "
3130HELM_K8S_V1_CRD_IF_START = '{{- if or (ge (int (regexFind "[0-9]+" .Capabilities.KubeVersion.Minor)) 18) (.Values.crd.forcev1) }}\n '
3231HELM_K8S_V1BETA1_CRD_IF_START = '{{- if or (lt (int (regexFind "[0-9]+" .Capabilities.KubeVersion.Minor)) 18) (.Values.crd.forcev1beta1) }}\n '
33- HELM_CRD_ANNOTATIONS_WITH_START = '{{- with .Values.crd.annotations }}\n '
34- HELM_ANNOTATIONS_TOYAML4 = '{{- toYaml . | nindent 4}}\n '
35- HELM_ANNOTATIONS_TOYAML8 = '{{- toYaml . | nindent 8}}\n '
36- HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START = '{{- with .Values.manager.annotations }}\n '
37- HELM_CONTROLER_DEP_POD_SEC_CTX_WITH_START = '{{- with .Values.manager.containerSecurityContext }}\n '
32+ HELM_CRD_ANNOTATIONS_WITH_START = "{{- with .Values.crd.annotations }}\n "
33+ HELM_ANNOTATIONS_TOYAML4 = "{{- toYaml . | nindent 4}}\n "
34+ HELM_ANNOTATIONS_TOYAML8 = "{{- toYaml . | nindent 8}}\n "
35+ HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START = "{{- with .Values.manager.annotations }}\n "
36+ HELM_CONTROLER_DEP_POD_SEC_CTX_WITH_START = (
37+ "{{- with .Values.manager.containerSecurityContext }}\n "
38+ )
3839HELM_IF_END = "{{- end }}\n "
3940
4041HELM_ENV_SUBST = {
7172 "EXECUTOR_REQUEST_LOGGER_WORK_QUEUE_SIZE" : "executor.requestLogger.workQueueSize" ,
7273 "EXECUTOR_REQUEST_LOGGER_WRITE_TIMEOUT_MS" : "executor.requestLogger.writeTimeoutMs" ,
7374 "DEPLOYMENT_NAME_AS_PREFIX" : "manager.deploymentNameAsPrefix" ,
74- "EXECUTOR_FULL_HEALTH_CHECKS" : "executor.fullHealthChecks"
75+ "EXECUTOR_FULL_HEALTH_CHECKS" : "executor.fullHealthChecks" ,
7576}
7677HELM_VALUES_IMAGE_PULL_POLICY = "{{ .Values.image.pullPolicy }}"
7778
@@ -100,8 +101,7 @@ def helm_namespace_override():
100101 webhookData
101102 + '{{- $altNames := list ( printf "seldon-webhook-service.%s" (include "seldon.namespace" .) ) ( printf "seldon-webhook-service.%s.svc" (include "seldon.namespace" .) ) -}}\n '
102103 )
103- webhookData = webhookData + \
104- '{{- $ca := genCA "custom-metrics-ca" 365 -}}\n '
104+ webhookData = webhookData + '{{- $ca := genCA "custom-metrics-ca" 365 -}}\n '
105105 webhookData = (
106106 webhookData
107107 + '{{- $cert := genSignedCert "seldon-webhook-service" nil $altNames 365 $ca -}}\n '
@@ -113,8 +113,7 @@ def helm_namespace_override():
113113 kind = res ["kind" ].lower ()
114114 name = res ["metadata" ]["name" ].lower ()
115115 version = res ["apiVersion" ]
116- filename = args .folder + "/" + \
117- (kind + "_" + name ).lower () + ".yaml"
116+ filename = args .folder + "/" + (kind + "_" + name ).lower () + ".yaml"
118117 print (filename )
119118 print (version )
120119 if (
@@ -156,9 +155,9 @@ def helm_namespace_override():
156155
157156 # controller manager
158157 if kind == "deployment" and name == "seldon-controller-manager" :
159- res ["spec" ]["template" ]["spec" ]["containers" ][0 ][
160- "imagePullPolicy"
161- ] = helm_value ( "image.pullPolicy" )
158+ res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["imagePullPolicy" ] = (
159+ helm_value ( "image.pullPolicy" )
160+ )
162161 res ["spec" ]["template" ]["spec" ]["containers" ][0 ][
163162 "image"
164163 ] = "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -168,12 +167,14 @@ def helm_namespace_override():
168167 "serviceAccount.name"
169168 )
170169 # Security Context
171- res ["spec" ]["template" ]["spec" ]["securityContext" ][
172- "runAsUser"
173- ] = helm_value ( "managerUserID" )
170+ res ["spec" ]["template" ]["spec" ]["securityContext" ]["runAsUser" ] = (
171+ helm_value ( "managerUserID" )
172+ )
174173
175174 # Priority class name
176- res ["spec" ]["template" ]["spec" ]["priorityClassName" ] = helm_value ("manager.priorityClassName" )
175+ res ["spec" ]["template" ]["spec" ]["priorityClassName" ] = helm_value (
176+ "manager.priorityClassName"
177+ )
177178
178179 # Resource requests
179180 res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["resources" ][
@@ -193,9 +194,9 @@ def helm_namespace_override():
193194 if env ["name" ] in HELM_ENV_SUBST :
194195 env ["value" ] = helm_value (HELM_ENV_SUBST [env ["name" ]])
195196 elif env ["name" ] == "EXECUTOR_CONTAINER_IMAGE_AND_VERSION" :
196- env [
197- "value "
198- ] = "{{ .Values.executor.image.registry }}/{{ .Values.executor.image.repository }}:{{ .Values.executor.image.tag }}"
197+ env ["value" ] = (
198+ "{{ .Values.executor.image.registry }}/{{ .Values.executor.image.repository }}:{{ .Values.executor.image.tag }} "
199+ )
199200 elif env ["name" ] == "CONTROLLER_ID" :
200201 env ["value" ] = "{{ .Values.controllerId }}"
201202
@@ -206,8 +207,7 @@ def helm_namespace_override():
206207 if portSpec ["name" ] == "webhook-server" :
207208 portSpec ["containerPort" ] = helm_value ("webhook.port" )
208209 for argIdx in range (
209- 0 , len (res ["spec" ]["template" ]["spec" ]
210- ["containers" ][0 ]["args" ])
210+ 0 , len (res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["args" ])
211211 ):
212212 if (
213213 res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["args" ][argIdx ]
@@ -221,16 +221,17 @@ def helm_namespace_override():
221221 )
222222
223223 # Update metrics port
224- res ["spec" ]["template" ]["metadata" ]["annotations" ]["prometheus.io/port" ] = helm_value ("metrics.port" )
224+ res ["spec" ]["template" ]["metadata" ]["annotations" ][
225+ "prometheus.io/port"
226+ ] = helm_value ("metrics.port" )
225227 for portSpec in res ["spec" ]["template" ]["spec" ]["containers" ][0 ][
226228 "ports"
227229 ]:
228230 if portSpec ["name" ] == "metrics" :
229231 portSpec ["containerPort" ] = helm_value ("metrics.port" )
230232
231233 for argIdx in range (
232- 0 , len (res ["spec" ]["template" ]["spec" ]
233- ["containers" ][0 ]["args" ])
234+ 0 , len (res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["args" ])
234235 ):
235236 if (
236237 res ["spec" ]["template" ]["spec" ]["containers" ][0 ]["args" ][argIdx ]
@@ -241,12 +242,13 @@ def helm_namespace_override():
241242 ] = "--metrics-addr=:" + helm_value ("metrics.port" )
242243
243244 # Networking
244- res ["spec" ]["template" ]["spec" ]["hostNetwork" ] = helm_value ("hostNetwork" )
245+ res ["spec" ]["template" ]["spec" ]["hostNetwork" ] = helm_value (
246+ "hostNetwork"
247+ )
245248
246249 if kind == "configmap" and name == "seldon-config" :
247250 res ["data" ]["credentials" ] = helm_value_json ("credentials" )
248- res ["data" ]["predictor_servers" ] = helm_value_json (
249- "predictor_servers" )
251+ res ["data" ]["predictor_servers" ] = helm_value_json ("predictor_servers" )
250252 res ["data" ]["storageInitializer" ] = helm_value_json (
251253 "storageInitializer"
252254 )
@@ -269,8 +271,7 @@ def helm_namespace_override():
269271 res ["roleRef" ]["name" ] + "-" + helm_namespace_override ()
270272 )
271273 if name == "seldon-manager-rolebinding" :
272- res ["subjects" ][0 ]["name" ] = helm_value (
273- "serviceAccount.name" )
274+ res ["subjects" ][0 ]["name" ] = helm_value ("serviceAccount.name" )
274275 res ["subjects" ][0 ]["namespace" ] = helm_namespace_override ()
275276 elif name != "seldon-spartakus-volunteer" :
276277 res ["subjects" ][0 ]["namespace" ] = helm_namespace_override ()
@@ -283,8 +284,7 @@ def helm_namespace_override():
283284 or name == "seldon1-manager-sas-rolebinding"
284285 or name == "seldon-leader-election-rolebinding"
285286 ):
286- res ["subjects" ][0 ]["name" ] = helm_value (
287- "serviceAccount.name" )
287+ res ["subjects" ][0 ]["name" ] = helm_value ("serviceAccount.name" )
288288 res ["subjects" ][0 ]["namespace" ] = helm_namespace_override ()
289289
290290 # Update webhook certificates
@@ -333,8 +333,7 @@ def helm_namespace_override():
333333
334334 # Update webhook service port
335335 if kind == "service" and name == "seldon-webhook-service" :
336- res ["spec" ]["ports" ][0 ]["targetPort" ] = helm_value (
337- "webhook.port" )
336+ res ["spec" ]["ports" ][0 ]["targetPort" ] = helm_value ("webhook.port" )
338337
339338 fdata = yaml .dump (res , width = 1000 )
340339
@@ -427,8 +426,10 @@ def helm_namespace_override():
427426 + HELM_K8S_V1BETA1_CRD_IF_START
428427 + re .sub (
429428 r"(.*controller-gen.kubebuilder.io/version.*\n)" ,
430- r"\1" + HELM_CRD_ANNOTATIONS_WITH_START +
431- HELM_ANNOTATIONS_TOYAML4 + HELM_IF_END ,
429+ r"\1"
430+ + HELM_CRD_ANNOTATIONS_WITH_START
431+ + HELM_ANNOTATIONS_TOYAML4
432+ + HELM_IF_END ,
432433 fdata ,
433434 re .M ,
434435 )
@@ -444,8 +445,10 @@ def helm_namespace_override():
444445 + HELM_K8S_V1_CRD_IF_START
445446 + re .sub (
446447 r"(.*controller-gen.kubebuilder.io/version.*\n)" ,
447- r"\1" + HELM_CRD_ANNOTATIONS_WITH_START +
448- HELM_ANNOTATIONS_TOYAML4 + HELM_IF_END ,
448+ r"\1"
449+ + HELM_CRD_ANNOTATIONS_WITH_START
450+ + HELM_ANNOTATIONS_TOYAML4
451+ + HELM_IF_END ,
449452 fdata ,
450453 re .M ,
451454 )
@@ -459,8 +462,10 @@ def helm_namespace_override():
459462 elif kind == "deployment" and name == "seldon-controller-manager" :
460463 fdata = re .sub (
461464 r"(.*template:\n.*metadata:\n.*annotations:\n)" ,
462- r"\1" + HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START +
463- HELM_ANNOTATIONS_TOYAML8 + HELM_IF_END ,
465+ r"\1"
466+ + HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START
467+ + HELM_ANNOTATIONS_TOYAML8
468+ + HELM_IF_END ,
464469 fdata ,
465470 re .M ,
466471 )
@@ -480,8 +485,10 @@ def helm_namespace_override():
480485
481486 fdata = re .sub (
482487 r"(.*command:\n)" ,
483- HELM_CONTROLER_DEP_POD_SEC_CTX_WITH_START +
484- HELM_ANNOTATIONS_TOYAML8 + HELM_IF_END + r"\1" ,
488+ HELM_CONTROLER_DEP_POD_SEC_CTX_WITH_START
489+ + HELM_ANNOTATIONS_TOYAML8
490+ + HELM_IF_END
491+ + r"\1" ,
485492 fdata ,
486493 re .M ,
487494 )
@@ -492,7 +499,8 @@ def helm_namespace_override():
492499 )
493500 # make sure metrics.port is not quoted as its an int
494501 fdata = fdata .replace (
495- "containerPort: '{{ .Values.metrics.port }}'" , "containerPort: {{ .Values.metrics.port }}"
502+ "containerPort: '{{ .Values.metrics.port }}'" ,
503+ "containerPort: {{ .Values.metrics.port }}" ,
496504 )
497505 # make sure webhook is not quoted as its an int
498506 fdata = fdata .replace (
@@ -538,9 +546,7 @@ def helm_namespace_override():
538546 )
539547 webhookData = re .sub (
540548 r"(.*caBundle:.*\n)" ,
541- HELM_NOT_CERTMANAGER_IF_START
542- + r"\1"
543- + HELM_IF_END ,
549+ HELM_NOT_CERTMANAGER_IF_START + r"\1" + HELM_IF_END ,
544550 webhookData ,
545551 re .M ,
546552 )
0 commit comments