Skip to content

Interpret KUBERNETES_SERVICE_HOST as hostname if not parsed as IP address #2285

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

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

LordGaav
Copy link
Contributor

This allows correctly connecting to the Kubernetes API when the service host is set as a hostname. This is at least the case on gardener.cloud . I'm running the patched version in production.

Related to #2047 which describes the same problem I had.

…ress

This allows correctly connecting to the Kubernetes API when the service host
is set as a hostname. This is at least the case on gardener.cloud . I'm
running the patched version in production.

Related to zalando#2047 which describes the same problem I had.
else
echo "Unrecognized IP format '$KUBERNETES_SERVICE_HOST'"
echo "KUBERNETES_SERVICE_HOST was not set"
fi
Copy link
Member

Choose a reason for hiding this comment

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

can you align the indentation? If I look at the rest of the file it seems 4 spaces are used more :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll reindent the entire file, because it's 2, 4 or 6 spaces, and that bothers me now that you mentioned it ;).

if [ "$KUBERNETES_SERVICE_HOST" != "${KUBERNETES_SERVICE_HOST#*[0-9].[0-9]}" ]; then
echo "IPv4"
K8S_API_URL=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1
elif [ "$KUBERNETES_SERVICE_HOST" != "${KUBERNETES_SERVICE_HOST#*:[0-9a-fA-F]}" ]; then
echo "IPv6"
K8S_API_URL=https://[$KUBERNETES_SERVICE_HOST]:$KUBERNETES_SERVICE_PORT/api/v1
elif [ -n "$KUBERNETES_SERVICE_HOST" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

-n is null check, right? Isn't -z better because it's checks null and not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because that arm checks if there is any value in KUBERNETES_SERVICE_HOST, and uses it as a hostname. I wanted to print a message when KUBERNETES_SERVICE_HOST was not set, for instance when someone want to set K8S_API_URL directly.

@FxKu FxKu added this to the 1.9.1 milestone Apr 13, 2023
@jopadi
Copy link
Member

jopadi commented Apr 19, 2023

👍

1 similar comment
@FxKu
Copy link
Member

FxKu commented Apr 19, 2023

👍

@FxKu FxKu merged commit 3f4e44d into zalando:master Apr 19, 2023
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.

3 participants