From 3fa54041f304cb3e84f03df0a489e7763127bf70 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Wed, 28 Apr 2021 17:25:35 -0700 Subject: [PATCH 1/8] Fix download redirects with functions This resolves an issue introduced in the redirect prep for v3 that broke our download redirects. The problem is that v3 releases are `kubebuilder_${os}_${arch}`, whereas v2 & v1 releases are `kubebuilder_${version}_${os}_${arch}.tar.gz`. Since netlify can't handle wildcards that are part of a path component (like `/2.:minorversion`) instead of a whole one (`:version`), we can't select on major version directly in our redirects. Instead, we introduce a function that handles this logic for us, and then use netlify 200-pseudo-redirects to "mount the function on the downloads part of the releases endpoint. --- docs/book/functions/handle-version.js | 36 +++++++++++++++++++++++++++ netlify.toml | 28 ++++++++------------- 2 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 docs/book/functions/handle-version.js diff --git a/docs/book/functions/handle-version.js b/docs/book/functions/handle-version.js new file mode 100644 index 00000000000..63d7b81b74a --- /dev/null +++ b/docs/book/functions/handle-version.js @@ -0,0 +1,36 @@ +function notFound(info) { + return { + statusCode: 404, + headers: {'content-type': 'text/html'}, + body: ("

Not Found

"+ + "

You shouldn't see this page, please file a bug

"+ + `
debug details
${JSON.stringify(info)}
` + ), + }; +} + +function redirectToDownload(version, file) { + const loc = `https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/${file}`; + return { + statusCode: 302, + headers: {'location': loc}, + }; +} + + +exports.handler = async function(evt, ctx) { + // grab the prefix too to check for coherence + const [prefix, version, os, arch] = evt.path.split("/").slice(-4); + if (prefix !== 'releases' || !version || !os || !arch) { + return notFound({version: version, os: os, arch: arch, prefix: constPrefix, rawPath: evt.path}); + } + + switch(version[0]) { + case '1': + // fallthrough + case '2': + return redirectToDownload(version, `kubebuilder_${version}_${os}_${arch}.tar.gz`); + default: + return redirectToDownload(version, `kubebuilder_${os}_${arch}`); + } +} diff --git a/netlify.toml b/netlify.toml index 2f7374c593d..2cb6b34752b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,6 +3,9 @@ command = "./install-and-build.sh" publish = "docs/book/book" +# used to handle the split between v2 and v3+ download links +[functions] + directory = "functions" # Standard Netlify redirects [[redirects]] @@ -63,21 +66,7 @@ status = 302 force = true -# v1 redirects. -[[redirects]] - from = "https://go.kubebuilder.io/releases/1.:minorpatch/:os/:arch" - to = "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v1.:minorpatch/kubebuilder_1.:minorpatch_:os_:arch.tar.gz" - status = 302 - force = true - -# v2 redirects. -[[redirects]] - from = "https://go.kubebuilder.io/releases/2.:minorpatch/:os/:arch" - to = "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.:minorpatch/kubebuilder_2.:minorpatch_:os_:arch.tar.gz" - status = 302 - force = true - -# v3+ redirects. +# general release redirects [[redirects]] from = "https://go.kubebuilder.io/releases/:version" to = "https://github.com/kubernetes-sigs/kubebuilder/releases/v:version" @@ -90,10 +79,15 @@ status = 302 force = true +# release download redirect [[redirects]] from = "https://go.kubebuilder.io/releases/:version/:os/:arch" - to = "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v:version/kubebuilder_:os_:arch" - status = 302 + # I don't quite know why, but netlify (or at least the dev mode) *insists* + # on eating every other query parameter, so just use paths instead + to = "/.netlify/functions/handle-version/:version/:os/:arch" + # 200 --> don't redirect to the the function then to whereever it says, + # just pretend like the function is mounted directly here + status = 200 force = true # Tools redirects. From a735bb37fdf25b2e7056355710dc81d5a728a1cf Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Thu, 29 Apr 2021 11:01:24 -0700 Subject: [PATCH 2/8] Fix netlify functions configuration The local `netlify` dev server and documentation expect a top-level configuration block named functions, but the remote netlify builder expects a key under the build block instead. Who knows why. --- docs/book/functions/handle-version.js | 5 +++-- netlify.toml | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/book/functions/handle-version.js b/docs/book/functions/handle-version.js index 63d7b81b74a..54b657e8763 100644 --- a/docs/book/functions/handle-version.js +++ b/docs/book/functions/handle-version.js @@ -13,7 +13,8 @@ function redirectToDownload(version, file) { const loc = `https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/${file}`; return { statusCode: 302, - headers: {'location': loc}, + headers: {'location': loc, 'content-type': 'text/plain'}, + body: `Redirecting to ${loc}`, }; } @@ -22,7 +23,7 @@ exports.handler = async function(evt, ctx) { // grab the prefix too to check for coherence const [prefix, version, os, arch] = evt.path.split("/").slice(-4); if (prefix !== 'releases' || !version || !os || !arch) { - return notFound({version: version, os: os, arch: arch, prefix: constPrefix, rawPath: evt.path}); + return notFound({version: version, os: os, arch: arch, prefix: prefix, rawPath: evt.path}); } switch(version[0]) { diff --git a/netlify.toml b/netlify.toml index 2cb6b34752b..77ce7354d55 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,9 +2,15 @@ base = "docs/book" command = "./install-and-build.sh" publish = "docs/book/book" + functions = "docs/book/functions" + +# TODO(directxman12): I don't know why, but this (functions) stanza is in the +# docs and local `netlify dev`, but the above one (under build) is used by the +# online version :-/ # used to handle the split between v2 and v3+ download links [functions] + # relative to base directory directory = "functions" # Standard Netlify redirects From 12f9460626e1b720920fc318fa5ca9a780ef58f7 Mon Sep 17 00:00:00 2001 From: varshaprasad96 Date: Mon, 3 May 2021 09:39:51 -0700 Subject: [PATCH 3/8] :sparkles: bump controller-runtime to 0.8.3 --- .../src/migration/manually_migration_guide_v2_v3.md | 6 +++--- docs/book/src/migration/migration_guide_v2tov3.md | 4 ++-- docs/book/src/migration/v2vsv3.md | 2 +- pkg/plugins/golang/declarative/v1/api.go | 2 +- pkg/plugins/golang/v3/scaffolds/init.go | 2 +- testdata/project-v3-addon/Makefile | 2 +- testdata/project-v3-addon/go.mod | 8 ++++---- testdata/project-v3-config/Makefile | 2 +- .../controllers/admiral_controller.go | 2 +- .../controllers/captain_controller.go | 2 +- .../project-v3-config/controllers/laker_controller.go | 2 +- testdata/project-v3-config/go.mod | 10 +++++----- testdata/project-v3-multigroup/Makefile | 2 +- .../controllers/apps/deployment_controller.go | 2 +- .../controllers/crew/captain_controller.go | 2 +- .../foo.policy/healthcheckpolicy_controller.go | 2 +- .../controllers/lakers_controller.go | 2 +- .../controllers/sea-creatures/kraken_controller.go | 2 +- .../controllers/sea-creatures/leviathan_controller.go | 2 +- .../controllers/ship/cruiser_controller.go | 2 +- .../controllers/ship/destroyer_controller.go | 2 +- .../controllers/ship/frigate_controller.go | 2 +- testdata/project-v3-multigroup/go.mod | 8 ++++---- testdata/project-v3/Makefile | 2 +- testdata/project-v3/controllers/admiral_controller.go | 2 +- testdata/project-v3/controllers/captain_controller.go | 2 +- testdata/project-v3/controllers/laker_controller.go | 2 +- testdata/project-v3/go.mod | 10 +++++----- 28 files changed, 45 insertions(+), 45 deletions(-) diff --git a/docs/book/src/migration/manually_migration_guide_v2_v3.md b/docs/book/src/migration/manually_migration_guide_v2_v3.md index 3a995e76bcd..4577aac0fdb 100644 --- a/docs/book/src/migration/manually_migration_guide_v2_v3.md +++ b/docs/book/src/migration/manually_migration_guide_v2_v3.md @@ -359,9 +359,9 @@ require ( github.com/go-logr/logr v0.3.0 github.com/onsi/ginkgo v1.14.1 github.com/onsi/gomega v1.10.2 - k8s.io/apimachinery v0.19.2 - k8s.io/client-go v0.19.2 - sigs.k8s.io/controller-runtime v0.7.0 + k8s.io/apimachinery v0.20.2 + k8s.io/client-go v0.20.2 + sigs.k8s.io/controller-runtime v0.8.3 ) ``` diff --git a/docs/book/src/migration/migration_guide_v2tov3.md b/docs/book/src/migration/migration_guide_v2tov3.md index be1a1d2dcbd..84227b1db1b 100644 --- a/docs/book/src/migration/migration_guide_v2tov3.md +++ b/docs/book/src/migration/migration_guide_v2tov3.md @@ -39,7 +39,7 @@ go mod init tutorial.kubebuilder.io/migration-project