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

Support the containers.conf container_name_as_hostname option #5943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nalind
Copy link
Member

@nalind nalind commented Jan 24, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

When containers.conf has the "container_name_as_hostname" option set, use that value, with values that don't fit [A-Za-z0-9][A-Za-z0-9._-]+ stripped out.

How to verify it

New integration test!

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 24, 2025
Copy link
Contributor

openshift-ci bot commented Jan 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nalind

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@nalind nalind force-pushed the container_name_as_hostname branch 3 times, most recently from a433090 to 1991aae Compare January 24, 2025 22:19
run_common.go Outdated
// mapContainerNameToHostname returns the passed-in string with characters that
// don't match the pattern "[A-Za-z0-9][A-Za-z0-9._-]+" stripped out.
func mapContainerNameToHostname(containerName string) string {
const initialAllowedChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"
Copy link
Collaborator

@flouthoc flouthoc Jan 24, 2025

Choose a reason for hiding this comment

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

Would regex such as ^[A-Za-z0-9] and [A-Za-z0-9._-] be easier to maintain ? or could it be slow here ? I mean directly using regexp instead of string matching.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's potentially a lot of calls to FindStringIndex(), but it's worth a shot if the result is more readable.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

I think there needs to be a length limit like in podman or does buildah restrict a name length already earlier?

run_common.go Outdated
// don't match the pattern "[A-Za-z0-9][A-Za-z0-9._-]+" stripped out.
func mapContainerNameToHostname(containerName string) string {
const initialAllowedChars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"
const allowedChars = initialAllowedChars + "._-"
Copy link
Member

Choose a reason for hiding this comment

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

_ is not a valid hostname char and must be stripped, the same is done in podman containers/podman@6fa234a

@nalind nalind force-pushed the container_name_as_hostname branch from 1991aae to 455f9d0 Compare February 18, 2025 22:21
@nalind
Copy link
Member Author

nalind commented Feb 18, 2025

I think there needs to be a length limit like in podman or does buildah restrict a name length already earlier?

Nothing between setting one in the spec and handing it off to the runtime. Added one when we base it on the container name.

When containers.conf has the "container_name_as_hostname" option set,
use that value, with values that don't fit `[A-Za-z0-9][A-Za-z0-9.-]+`
stripped out.

Signed-off-by: Nalin Dahyabhai <[email protected]>
@nalind nalind force-pushed the container_name_as_hostname branch from 455f9d0 to 72e2bf4 Compare February 18, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants