From 943d3e3583b067e4179d03e83653c4dfb7993375 Mon Sep 17 00:00:00 2001 From: Nahshon Unna Tsameret Date: Wed, 24 Jun 2026 12:57:50 +0300 Subject: [PATCH] Fix issue in the downloads server: archives are not compressed The download server creates zip and tar archives on boot. However, when downloading these archives, their size is the same as the original non-compressed file. This PR fixes this isssue. It also changes the tar file extension to "tar.gz". Few more improvements: embed the configuration file, instead of handling the file: copy it to the image and write code around open and close it with error handling. embed the file makes it all much more simple. deprecate the config-path as it is no longer required. move the port parameter out of the download config as it's not belong there. don't create archives for broken symlinks, to avoid let the user download them. Avoid keeping the handler waiting forever, creating handler leaks. Signed-off-by: Nahshon Unna Tsameret --- Dockerfile.downloads | 3 +- cmd/downloads/config/downloads_config.go | 112 +++++------ cmd/downloads/config/downloads_config_test.go | 175 ++++++++++++++---- cmd/downloads/main.go | 25 ++- 4 files changed, 213 insertions(+), 102 deletions(-) diff --git a/Dockerfile.downloads b/Dockerfile.downloads index 2929de86560..288447fd395 100644 --- a/Dockerfile.downloads +++ b/Dockerfile.downloads @@ -18,14 +18,13 @@ FROM registry.access.redhat.com/ubi9/ubi-minimal:latest RUN mkdir -p /opt/downloads COPY --from=gobuilder /go/src/github.com/openshift/console/bin/downloads /opt/downloads -COPY --from=gobuilder /go/src/github.com/openshift/console/cmd/downloads/config/defaultArtifactsConfig.yaml /opt/downloads COPY --from=origincli /usr/share/openshift /usr/share/openshift WORKDIR / # doesn't require a root user. USER 1001 -CMD ["/opt/downloads/downloads", "--config-path=/opt/downloads/defaultArtifactsConfig.yaml"] +CMD ["/opt/downloads/downloads"] LABEL \ io.k8s.display-name="CLI Artifacts Downloads Server" \ diff --git a/cmd/downloads/config/downloads_config.go b/cmd/downloads/config/downloads_config.go index eaa38233321..e975afd69c9 100644 --- a/cmd/downloads/config/downloads_config.go +++ b/cmd/downloads/config/downloads_config.go @@ -3,8 +3,10 @@ package config import ( "archive/tar" "archive/zip" + "compress/gzip" "fmt" "io" + "io/fs" "net/http" "os" "path/filepath" @@ -13,8 +15,7 @@ import ( "text/template" "gopkg.in/yaml.v3" - - klog "k8s.io/klog/v2" + "k8s.io/klog/v2" ) // HtmlPageData holds data passed to the HTML template @@ -54,7 +55,6 @@ type ArtifactSpec struct { // ArtifactsConfig holds the configuration for the artifacts server type DownloadsServerConfig struct { - Port string Spec []ArtifactSpec TempDir string TemplateHTML *template.Template @@ -80,7 +80,7 @@ const templateStringHTML = `