@@ -116,9 +116,10 @@ def destroy_cluster(self) -> None:
116116
117117 def create_spak_service_account (self ) -> None :
118118 """Create service account for launching spark application in k8s"""
119- execute_command (f "kubectl create serviceaccount spark --namespace=default" )
119+ execute_command ("kubectl create serviceaccount spark --namespace=default" )
120120 execute_command (
121- f"kubectl create clusterrolebinding spark-role --clusterrole=edit --serviceaccount=default:spark --namespace=default"
121+ "kubectl create clusterrolebinding spark-role --clusterrole=edit "
122+ "--serviceaccount=default:spark --namespace=default"
122123 )
123124 if PrivateRegistryConfig .is_configured ():
124125 execute_command (
@@ -161,7 +162,8 @@ def _create_secret_to_access_to_internal_registry(self):
161162
162163 # Patch the default service account to use the secret
163164 execute_command (
164- 'kubectl patch serviceaccount default -p \' {"imagePullSecrets": [{"name": "private-registry-secret"}]}\' '
165+ "kubectl patch serviceaccount default "
166+ '-p \' {"imagePullSecrets": [{"name": "private-registry-secret"}]}\' '
165167 "--namespace=default"
166168 )
167169 logger .info ("Successfully patched default service account" )
@@ -271,7 +273,8 @@ def configure_cluster_api_connection(self) -> None:
271273 """Configure the k8s cluster api connection"""
272274 try :
273275 # Update context name
274- # Current context name is like: "arn:aws:eks:us-east-1:601427279990:cluster/lib-injection-testing-eks-sandbox"
276+ # Current context name is like:
277+ # "arn:aws:eks:us-east-1:601427279990:cluster/lib-injection-testing-eks-sandbox"
275278 # I only take "lib-injection-testing-eks-sandbox"
276279 arn , cluster_context = execute_command ("kubectl config current-context" ).split ("/" )
277280 current_context_name = cluster_context .strip ()
@@ -290,7 +293,8 @@ def configure_cluster_api_connection(self) -> None:
290293 ).strip ()
291294 logger .info ("Configuring k8s cluster api connection, for cluster: " + self ._cluster_info .cluster_name )
292295
293- # We need to external IP to access to the test agent and the weblog (You should open manually the ports 8126 and 18080 in the aws security group before)
296+ # We need to external IP to access to the test agent and the weblog
297+ # (You should open manually the ports 8126 and 18080 in the aws security group before)
294298 self ._cluster_info .cluster_host_name = execute_command (
295299 "kubectl get nodes --output jsonpath=\" {.items[0].status.addresses[?(@.type=='ExternalIP')].address}\" "
296300 )
@@ -315,7 +319,7 @@ def configure_cluster_api_connection(self) -> None:
315319 configuration .assert_hostname = True
316320 configuration .verify_ssl = False
317321 client .Configuration .set_default (configuration )
318- logger .info (f "kube config loaded" )
322+ logger .info ("kube config loaded" )
319323
320324 except Exception as e :
321325 logger .error (f"Error loading kube config: { e } " )
@@ -328,7 +332,8 @@ def execute_piped_command(self, command: str) -> str:
328332 return res .decode ("utf-8" ).strip ()
329333
330334 def get_token (self , cluster_name : str ) -> str :
331- # From cluster name like: "lib-injection-testing-eks-sandbox.us-east-1.eksctl.io" I only take "lib-injection-testing-eks-sandbox"
335+ # From cluster name like: "lib-injection-testing-eks-sandbox.us-east-1.eksctl.io"
336+ # I only take "lib-injection-testing-eks-sandbox"
332337 cluster_min_name = cluster_name .split ("." )[0 ]
333338 token = execute_command (f"aws-iam-authenticator token -i { cluster_min_name } --token-only" )
334339 return token .strip ()
@@ -362,7 +367,13 @@ def configure_networking(self) -> None:
362367
363368 def ensure_cluster (self ) -> None :
364369 logger .info ("Ensuring kind cluster" )
365- kind_command = f"kind create cluster --image=kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1 --name { self .get_cluster_info ().cluster_name } --config { self .get_cluster_info ().cluster_template } --wait 1m"
370+ kind_command = (
371+ "kind create cluster "
372+ "--image=kindest/node:v1.25.3"
373+ "@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1 "
374+ f"--name { self .get_cluster_info ().cluster_name } "
375+ f"--config { self .get_cluster_info ().cluster_template } --wait 1m"
376+ )
366377
367378 if "GITLAB_CI" in os .environ :
368379 # Kind needs to run in bridge network to communicate with the internet: https://github.com/DataDog/buildenv/blob/master/cookbooks/dd_firewall/templates/rules.erb#L96
@@ -393,26 +404,33 @@ def _setup_kind_in_gitlab(self) -> None:
393404 # - Docker commands are forwarded to the host.
394405 # - The kind container is a sibling to the build container
395406 # Three things need to happen
396- # 1) The kind container needs to be in the bridge network to communicate with the internet: done in _ensure_cluster()
407+ # 1) The kind container needs to be in the bridge network to communicate with the internet:
408+ # done in _ensure_cluster()
397409 # 2) Kube config needs to be altered to use the correct IP of the control plane server
398- # 3) The internal ports needs to be used rather than external ports: handled in get_agent_port() and get_weblog_port()
410+ # 3) The internal ports needs to be used rather than external ports:
411+ # handled in get_agent_port() and get_weblog_port()
412+ control_plane_container = f"{ self .get_cluster_info ().cluster_name } -control-plane"
399413 correct_control_plane_ip = execute_command (
400- f"docker container inspect { self .get_cluster_info ().cluster_name } -control-plane --format '{{{{.NetworkSettings.Networks.bridge.IPAddress}}}}'"
414+ f"docker container inspect { control_plane_container } "
415+ "--format '{{.NetworkSettings.Networks.bridge.IPAddress}}'"
401416 ).strip ()
402417 if not correct_control_plane_ip :
403418 raise Exception ("Unable to find correct control plane IP" )
404419 logger .debug (f"[setup_kind_in_gitlab] correct_control_plane_ip: { correct_control_plane_ip } " )
405420
406421 control_plane_address_in_config = execute_command (
407- f'docker container inspect { self .get_cluster_info ().cluster_name } -control-plane --format \' {{{{index .NetworkSettings.Ports "6443/tcp" 0 "HostIp"}}}}:{{{{index .NetworkSettings.Ports "6443/tcp" 0 "HostPort"}}}}\' '
422+ f"docker container inspect { control_plane_container } "
423+ '--format \' {{index .NetworkSettings.Ports "6443/tcp" 0 "HostIp"}}'
424+ ':{{index .NetworkSettings.Ports "6443/tcp" 0 "HostPort"}}\' '
408425 ).strip ()
409426 if not control_plane_address_in_config :
410427 raise Exception ("Unable to find control plane address from config" )
411428 logger .debug (f"[setup_kind_in_gitlab] control_plane_address_in_config: { control_plane_address_in_config } " )
412429
413430 # Replace server config with dns name + internal port
431+ kube_config_path = f"{ os .environ ['HOME' ]} /.kube/config"
414432 execute_command (
415- f"sed -i -e 's/{ control_plane_address_in_config } /{ correct_control_plane_ip } :6443/g' { os . environ [ 'HOME' ] } /.kube/config "
433+ f"sed -i -e 's/{ control_plane_address_in_config } /{ correct_control_plane_ip } :6443/g' { kube_config_path } "
416434 )
417435
418436 self .get_cluster_info ().cluster_host_name = correct_control_plane_ip
0 commit comments