Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nodename to response #27

Merged
merged 9 commits into from
Apr 10, 2024
Merged

Add nodename to response #27

merged 9 commits into from
Apr 10, 2024

Conversation

vlerkin
Copy link
Contributor

@vlerkin vlerkin commented Mar 6, 2024

No description provided.

@vlerkin vlerkin changed the title Add codename to response Add nodename to response Mar 6, 2024
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, great! Some small comments, otherwise good to go 👍

scrapyd_k8s/api.py Show resolved Hide resolved
scrapyd_k8s/launcher/docker.py Show resolved Hide resolved
scrapyd_k8s/launcher/k8s.py Show resolved Hide resolved
test_api.py Show resolved Hide resolved
test_api.py Show resolved Hide resolved
scrapyd_k8s/api.py Outdated Show resolved Hide resolved
@@ -21,7 +21,11 @@ def __init__(self, config):
self._docker = docker.from_env()

def get_node_name(self):
return os.getenv('HOSTNAME')
hostname = os.getenv('HOSTNAME')
if hostname in [None, "", "null"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can HOSTNAME be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most often HOSTNAME exists in linux based systems but it's not part of posix family standard so there can be cases when it's null, this is the source my thoughts are based on:
https://superuser.com/questions/132489/hostname-environment-variable-on-linux#comment1214603_132500

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What brings HOSTNAME that gethostname() doesn't bring? (Perhaps the ability to override the node name from the environment, but then I'd like it across launcher backends, and not provide that ability here.) So I would just use gethostname(). You can already override the node name in the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true, os.getenv is just a call to "third-party" program while gethostame is part of core if I understand correctly so better just use gethostname and in case it's null then use "default"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, both are from the core Python library, but os.getenv() looks in the environment, and gethostname() does a syscall to request the system hostname. The Superuser question shows that HOSTNAME may not be a proper environment variable (and if it is may depend on the Linux distribution or other *nix system flavour, in any case it is not part of the POSIX spec), so that you cannot really rely on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base on
https://pythontic.com/modules/socket/gethostname
and https://man7.org/linux/man-pages/man2/sethostname.2.html
I will delete if statement that checks if hostname value is None/null or empty

scrapyd_k8s/launcher/docker.py Outdated Show resolved Hide resolved
scrapyd_k8s/launcher/k8s.py Outdated Show resolved Hide resolved
scrapyd_k8s/launcher/k8s.py Outdated Show resolved Hide resolved
test_api.py Show resolved Hide resolved
@wvengen
Copy link
Member

wvengen commented Mar 27, 2024

After a CI rerun also the Kubernetes test is fine again 😅

…le, rewrite function to retrieve deployment name and pod namespace, use socket.gethostname instead of sys popopen
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One pending thing, otherwise good to go!

@@ -21,7 +21,11 @@ def __init__(self, config):
self._docker = docker.from_env()

def get_node_name(self):
return os.getenv('HOSTNAME')
hostname = os.getenv('HOSTNAME')
if hostname in [None, "", "null"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What brings HOSTNAME that gethostname() doesn't bring? (Perhaps the ability to override the node name from the environment, but then I'd like it across launcher backends, and not provide that ability here.) So I would just use gethostname(). You can already override the node name in the config file.

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
It's good to always review your own PR. Doing a review of all changes, shows me that there are still unrelated whitespace changes with meaning (e.g. the newlines in the tests do convey something about the grouping - e.g. a comment of a missing test does not belong to the following method, so you can't just remove the empty newline. Linters and autoformatters don't have the final word!)

Could you still review and change this? When the whitespace is correct, the PR can be merged.

hostname = os.getenv('HOSTNAME')
if hostname in [None, "", "null"]:
hostname = socket.gethostname()
hostname = socket.gethostname()
return hostname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, also just return socket.gethostname() here, for brevity.

@vlerkin
Copy link
Contributor Author

vlerkin commented Apr 10, 2024

Thanks! It's good to always review your own PR. Doing a review of all changes, shows me that there are still unrelated whitespace changes with meaning (e.g. the newlines in the tests do convey something about the grouping - e.g. a comment of a missing test does not belong to the following method, so you can't just remove the empty newline. Linters and autoformatters don't have the final word!)

Could you still review and change this? When the whitespace is correct, the PR can be merged.

I deleted whitespace added by code formatter, if you notice there is still some whitespace that you think should be different - let me know. I am now having my Mac wiped out so I won't be able to access it for some time.

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough, thank you for all the changes! 🚀

@wvengen wvengen merged commit e6107be into q-m:main Apr 10, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants