From 72da37fed63b51d41bc98648a6f230b7ee467a5b Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 19 Nov 2024 09:29:31 +0100 Subject: [PATCH] Apply fix for release notes index JSON Signed-off-by: Sascha Grunert --- pkg/release/publish.go | 21 +++++++++------------ pkg/release/publish_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/pkg/release/publish.go b/pkg/release/publish.go index c034d12e651..88b8945e745 100644 --- a/pkg/release/publish.go +++ b/pkg/release/publish.go @@ -402,13 +402,14 @@ func (p *Publisher) PublishToGcs( return nil } -func gcsPathToPublisURL(gcsPath string) (string, error) { - const pathSep = "/" - split := strings.Split(strings.TrimPrefix(gcsPath, object.GcsPrefix), pathSep) - if len(split) < 2 { - return "", fmt.Errorf("invalid GCS path: %s", gcsPath) - } - return URLPrefixForBucket(split[0]) + pathSep + strings.Join(split[1:], pathSep), nil +// TODO: remove this function once https://cdn.dl.k8s.io/release/release-notes-index.json +// is fixed. +func FixPublicReleaseNotesURL(gcsPath string) string { + const prefix = "https://storage.googleapis.com/" + for strings.HasPrefix(gcsPath, prefix) { + gcsPath = strings.TrimPrefix(gcsPath, prefix) + } + return gcsPath } // PublishReleaseNotesIndex updates or creates the release notes index JSON at @@ -467,11 +468,7 @@ func (p *Publisher) PublishReleaseNotesIndex( // Fixup the index to only use public URLS for v, releaseNotesPath := range versions { - releaseNotesPublicURL, err := gcsPathToPublisURL(releaseNotesPath) - if err != nil { - return fmt.Errorf("get publish URL from release notes GCS path: %w", err) - } - versions[v] = releaseNotesPublicURL + versions[v] = FixPublicReleaseNotesURL(releaseNotesPath) } versionJSON, err := p.client.Marshal(versions) diff --git a/pkg/release/publish_test.go b/pkg/release/publish_test.go index b75fee2b2b3..26073e6dd71 100644 --- a/pkg/release/publish_test.go +++ b/pkg/release/publish_test.go @@ -372,3 +372,31 @@ func TestIsUpToDate(t *testing.T) { }) } } + +func TestFixPublicReleaseNotesURL(t *testing.T) { + t.Parallel() + + for name, tc := range map[string]struct { + input, expected string + }{ + "should not affect correct URL": { + input: "https://dl.k8s.io/release/v1.32.0-beta.0/release-notes.json", + expected: "https://dl.k8s.io/release/v1.32.0-beta.0/release-notes.json", + }, + "should fix wrong URL with 1 prefix": { + input: "https://storage.googleapis.com/https://dl.k8s.io/release/v1.32.0-alpha.3/release-notes.json", + expected: "https://dl.k8s.io/release/v1.32.0-alpha.3/release-notes.json", + }, + "should fix wrong URL with multiple prefixes": { + input: "https://storage.googleapis.com/https://storage.googleapis.com/https://dl.k8s.io/release/v1.28.1/release-notes.json", + expected: "https://dl.k8s.io/release/v1.28.1/release-notes.json", + }, + } { + t.Run(name, func(t *testing.T) { + t.Parallel() + + res := release.FixPublicReleaseNotesURL(tc.input) + require.Equal(t, tc.expected, res) + }) + } +}