Skip to content

Commit

Permalink
fix KubernetesClient and hostip (#312)
Browse files Browse the repository at this point in the history
* fix KubernetesClient

* fix KubernetesClient

* fix KubernetesClient

* fix KubernetesClient

* fix "nodename nor servname provided"

* delete build tag
  • Loading branch information
wayyoungboy authored Jul 9, 2024
1 parent d0783a0 commit 9a7907e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- master

env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

Expand Down
4 changes: 3 additions & 1 deletion common/ssh_client/kubernetes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def __init__(self, context=None, node=None):
self.container_name = self.node.get("container_name") or "observer"
config_file = self.node.get("kubernetes_config_file")
if config_file is None or config_file == "":
config.load_kube_config()
context.stdio.verbose("KubernetesClient load_kube_config from default config file in cluster.")
config.load_incluster_config()
else:
context.stdio.verbose("KubernetesClient load_kube_config from {0}".format(config_file))
config.kube_config.load_kube_config(config_file=config_file)
self.client = client.CoreV1Api()
except Exception as e:
Expand Down
11 changes: 7 additions & 4 deletions common/ssh_client/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def __init__(self, context=None, node=None):

def local_ip(self):
local_ip_list = []
hostname = socket.gethostname()
addresses = socket.getaddrinfo(hostname, None)
for address in addresses:
local_ip_list.append(address[4][0])
try:
hostname = socket.gethostname()
addresses = socket.getaddrinfo(hostname, None)
for address in addresses:
local_ip_list.append(address[4][0])
except Exception as e:
self.stdio.watn("get local ip warn: {} . Set local_ip is 127.0.0.1".format(e))
local_ip_list.append('127.0.0.1')
return list(set(local_ip_list))

Expand Down

0 comments on commit 9a7907e

Please sign in to comment.