Skip to content

Commit 75b3f79

Browse files
authored
Merge pull request #3834 from saschagrunert/release-notes-index-fix
Apply fix for release notes index JSON
2 parents 527fb34 + 72da37f commit 75b3f79

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

pkg/release/publish.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,14 @@ func (p *Publisher) PublishToGcs(
402402
return nil
403403
}
404404

405-
func gcsPathToPublisURL(gcsPath string) (string, error) {
406-
const pathSep = "/"
407-
split := strings.Split(strings.TrimPrefix(gcsPath, object.GcsPrefix), pathSep)
408-
if len(split) < 2 {
409-
return "", fmt.Errorf("invalid GCS path: %s", gcsPath)
410-
}
411-
return URLPrefixForBucket(split[0]) + pathSep + strings.Join(split[1:], pathSep), nil
405+
// TODO: remove this function once https://cdn.dl.k8s.io/release/release-notes-index.json
406+
// is fixed.
407+
func FixPublicReleaseNotesURL(gcsPath string) string {
408+
const prefix = "https://storage.googleapis.com/"
409+
for strings.HasPrefix(gcsPath, prefix) {
410+
gcsPath = strings.TrimPrefix(gcsPath, prefix)
411+
}
412+
return gcsPath
412413
}
413414

414415
// PublishReleaseNotesIndex updates or creates the release notes index JSON at
@@ -467,11 +468,7 @@ func (p *Publisher) PublishReleaseNotesIndex(
467468

468469
// Fixup the index to only use public URLS
469470
for v, releaseNotesPath := range versions {
470-
releaseNotesPublicURL, err := gcsPathToPublisURL(releaseNotesPath)
471-
if err != nil {
472-
return fmt.Errorf("get publish URL from release notes GCS path: %w", err)
473-
}
474-
versions[v] = releaseNotesPublicURL
471+
versions[v] = FixPublicReleaseNotesURL(releaseNotesPath)
475472
}
476473

477474
versionJSON, err := p.client.Marshal(versions)

pkg/release/publish_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,31 @@ func TestIsUpToDate(t *testing.T) {
372372
})
373373
}
374374
}
375+
376+
func TestFixPublicReleaseNotesURL(t *testing.T) {
377+
t.Parallel()
378+
379+
for name, tc := range map[string]struct {
380+
input, expected string
381+
}{
382+
"should not affect correct URL": {
383+
input: "https://dl.k8s.io/release/v1.32.0-beta.0/release-notes.json",
384+
expected: "https://dl.k8s.io/release/v1.32.0-beta.0/release-notes.json",
385+
},
386+
"should fix wrong URL with 1 prefix": {
387+
input: "https://storage.googleapis.com/https://dl.k8s.io/release/v1.32.0-alpha.3/release-notes.json",
388+
expected: "https://dl.k8s.io/release/v1.32.0-alpha.3/release-notes.json",
389+
},
390+
"should fix wrong URL with multiple prefixes": {
391+
input: "https://storage.googleapis.com/https://storage.googleapis.com/https://dl.k8s.io/release/v1.28.1/release-notes.json",
392+
expected: "https://dl.k8s.io/release/v1.28.1/release-notes.json",
393+
},
394+
} {
395+
t.Run(name, func(t *testing.T) {
396+
t.Parallel()
397+
398+
res := release.FixPublicReleaseNotesURL(tc.input)
399+
require.Equal(t, tc.expected, res)
400+
})
401+
}
402+
}

0 commit comments

Comments
 (0)