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

Base ISO cache file name on the full ISO URL #18723

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

Conversation

albertofaria
Copy link
Contributor

Currently, only the basename of the URL path is used, which can be the same for different URLs.

Base the cache file name on the full URL instead, encoding it using Go's base64.URLEncoding so it can be used as a file name on all platforms.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: albertofaria
Once this PR has been reviewed and has the lgtm label, please assign afbjorklund for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Contributor

Hi @albertofaria. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 22, 2024
@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@medyagh
Copy link
Member

medyagh commented Apr 22, 2024

@albertofaria do you mind elaborating with an example what you are trying to improve ? maybe share with a output example

@albertofaria
Copy link
Contributor Author

A colleague reported that a stale cached ISO was being used after changing the value of the --iso-url option. This is because both the previous and new URLs given with --iso-url referenced GitLab package artifacts, which always end in a /download component.

They worked around this by manually deleting ~/.minikube/cache/iso/amd64/download.

@albertofaria
Copy link
Contributor Author

@medyagh I added more details to the commit message.

@spowelljr
Copy link
Member

Hi @albertofaria, I understand the point of the fix, but fully changing the name will make it hard to know the contents of the ISO cache dir for the average user.

ie. What version is aHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL21pbmlrdWJlLWJ1aWxkcy9pc28vMTg3MDYvbWluaWt1YmUtdjEuMzMuMC0xNzEzNzM2MjcxLTE4NzA2LWFybTY0Lmlzbw==?

Could we maybe append it to the existing version so we can still identify the version for the default ISO file names
minikube-v1.33.0-arm64.iso-<encoding>

@albertofaria
Copy link
Contributor Author

That's a good point. How about minikube-v1.33.0-arm64.iso-<sha1_of_full_url_as_40_hex_chars>?

@spowelljr
Copy link
Member

That seems good, the 137 chars is a bit extreme, 40 sounds a lot better

Currently, only the final component of the URL path is used. This means
that minikube may use the wrong cached image after the user changes the
ISO URL to another with the same final component.

Fix this by suffixing the cache file name with a hash of the entire URL.

Signed-off-by: Alberto Faria <[email protected]>
@@ -77,7 +78,10 @@ func localISOPath(u *url.URL) string {
return u.String()
}

return filepath.Join(detect.ISOCacheDir(), path.Base(u.Path))
urlHash := sha1.Sum([]byte(u.String()))
fileName := fmt.Sprintf("%s-%040x", path.Base(u.Path), urlHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes the iso file name a little bit ugly to support questionable API of a single application. The common way to publish downloads is to provide a URL ending with the filename, so the current behavior makes sense.

Since the image name always end with .iso or .ISO, and the file name is likely to be in the URL even in gitlab, can be search back the URL components and take the first component ending with .(iso|ISO) as the file name?

Or, maybe apply this behavior only if the URL does not end with .(iso|ISO)? This way this change helps gitlab users, without affecting other users.

Also did you open a bug for gitlab to provide a better URL? This /download URL will cause trouble for other tools, for example what do you get with curl -O?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to solve this, add --iso-filename option. When set, using --iso-url will store the iso using the filename specified in --iso-filename. With this if you download the iso from a system that does not provide the common url with meaningful file name at the end, you can control the stored file name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants