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

fix: env_file configmap name length #1743

Merged
merged 5 commits into from
Oct 27, 2023
Merged

Conversation

ThijsBroersen
Copy link
Contributor

@ThijsBroersen ThijsBroersen commented Oct 20, 2023

fix filename to configmap name transformer

What type of PR is this?

bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #1738

Special notes for your reviewer:

I was unable to run tests, could not figure out what system requirements were needed to run the tests.
Tests are adjusted to match new configmap name

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 20, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Oct 20, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @ThijsBroersen!

It looks like this is your first PR to kubernetes/kompose 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kompose has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 20, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 20, 2023
@@ -851,8 +851,15 @@ func GetContentFromFile(file string) (string, error) {
// FormatEnvName format env name
func FormatEnvName(name string) string {
envName := strings.Trim(name, "./")
// only take string after the last slash only if the string contains a slash
if strings.Contains(envName, "/") {
Copy link
Member

Choose a reason for hiding this comment

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

Thank you! This helps, does this break anything though @AhmedGrati with regards to how we use env?

This also cleans up the really long configmap names, but I'm unsure if they would have conflicts when there are multiple containers.

If you can also add a test case for this under k8sutils_test.go that'd be awesome. Otherwise, good PR 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
I think it will work as long as env_file names are unique. When different env_file's with the same name are references (from different directories) it will clash.
Could also just only cap at the last, let's say 60 chars? And not filter by last / ?

Copy link
Contributor Author

@ThijsBroersen ThijsBroersen Oct 23, 2023

Choose a reason for hiding this comment

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

Do you want anything changed? If not could it be merged soon? I could really use this in a new version of Kompose.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, I think that the names generated should be from env_file names from the last slash.. I really doubt that there will be multiple env file names in different directories for a docker compose project.

HOWEVER if there is, I think that they should be the same name, but one of them filename_1, etc. if there are more of the same file AND Kompose does a warning.

However, I don't feel comfortable merging the PR until we have these two tasks:

  • tests added to k8sutils_test.go
  • test for if there are two env file names in different directories
  • implement renaming to filename_number if there are multiple env files of the same name but in different directories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, just took a short browse. Added a new env-multiple fixture and test but now sure how to implement this. My thinking would be to check existing configmaps before inserting the new. If a configmap with the same name exists, append a 1 and try again. If that also exists a 2, and so on..
Could you give me a pointer? Or perhaps someone else wants to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't actually get it @ThijsBroersen. Can you please clarify it more?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 23, 2023
Copy link
Contributor

@AhmedGrati AhmedGrati left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ThijsBroersen. Maybe a unit test for this would make it even better 🙏.

.gitpod.yml Outdated
Comment on lines 1 to 11
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: go get && go build ./... && go test ./... && make
command: go run .


Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this should not be added.

@@ -851,8 +851,15 @@ func GetContentFromFile(file string) (string, error) {
// FormatEnvName format env name
func FormatEnvName(name string) string {
envName := strings.Trim(name, "./")
// only take string after the last slash only if the string contains a slash
if strings.Contains(envName, "/") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't actually get it @ThijsBroersen. Can you please clarify it more?

@cdrage
Copy link
Member

cdrage commented Oct 24, 2023

I'm good with this PR! LGTM! I understand about writing a golang test, I've opened up an issue here so we make sure we add a future test: #1745

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cdrage, ThijsBroersen

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2023
@cdrage
Copy link
Member

cdrage commented Oct 24, 2023

You'll have to rebase the issue to pass the new tests

@AhmedGrati
Copy link
Contributor

ping @ThijsBroersen can u please rebase?

@ThijsBroersen
Copy link
Contributor Author

I rebased as requested but the new tests will likely still fail because I did not found a way yet to take into account duplicate names. Should I comment out the new test in new_tests.sh ?

@AhmedGrati
Copy link
Contributor

Thanks for the contribution @ThijsBroersen. I'm Gonna take care of the tests.

@AhmedGrati AhmedGrati merged commit 7826534 into kubernetes:main Oct 27, 2023
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Generated ConfigMap name too long
4 participants