From ce4e4f504a6a41b82d5646511b2ed7d6d3b0d120 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Mon, 6 May 2024 20:39:01 +0200 Subject: [PATCH] some more deprecations --- tools/setup-envtest/README.md | 9 +++--- tools/setup-envtest/env/env.go | 16 +++++----- tools/setup-envtest/main.go | 32 +++++++++---------- tools/setup-envtest/remote/gcs_client.go | 4 +++ tools/setup-envtest/versions/platform.go | 1 + .../setup-envtest/workflows/workflows_test.go | 2 +- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/tools/setup-envtest/README.md b/tools/setup-envtest/README.md index 11a59c4a1d..44505dd8a3 100644 --- a/tools/setup-envtest/README.md +++ b/tools/setup-envtest/README.md @@ -2,8 +2,7 @@ This is a small tool that manages binaries for envtest. It can be used to download new binaries, list currently installed and available ones, and -clean up versions. Binaries can be downloaded either via HTTP via an index -or from GCS. +clean up versions. To use it, just go-install it on 1.19+ (it's a separate, self-contained module): @@ -50,7 +49,8 @@ setup-envtest use --index https://custom.com/envtest-releases.yaml # To download from the kubebuilder-tools GCS bucket: (default behavior before v0.18) # Note: This is a Google-owned bucket and it might be shutdown at any time # see: https://github.com/kubernetes/k8s.io/issues/2647#event-12439345373 -setup-envtest use --use-gcs +# Note: This flag will also be removed soon. +setup-envtest use --use-deprecated-gcs ``` ## Where does it put all those binaries? @@ -119,7 +119,8 @@ Then, you have a few options for managing your binaries: https://raw.githubusercontent.com/kubernetes-sigs/controller-tools/master/envtest-releases.yaml - If you want to talk to some internal source in a GCS "style", you can use the - `--remote-bucket` and `--remote-server` options together with `--use-gcs`. The former sets which + `--remote-bucket` and `--remote-server` options together with `--use-deprecated-gcs`. + Note: This is deprecated and will be removed soon. The former sets which GCS bucket to download from, and the latter sets the host to talk to as if it were a GCS endpoint. Theoretically, you could use the latter version to run an internal "mirror" -- the tool expects diff --git a/tools/setup-envtest/env/env.go b/tools/setup-envtest/env/env.go index dc6a6ea4a2..24857916d7 100644 --- a/tools/setup-envtest/env/env.go +++ b/tools/setup-envtest/env/env.go @@ -26,7 +26,7 @@ import ( // envtest binaries. // // In general, the methods will use the Exit{,Cause} functions from this package -// to indicate errors. Catch them with a `defer HandleExitWithCode()`. +// to indicate errors. Catch them with a `defer HandleExitWithCode()`. type Env struct { // the following *must* be set on input @@ -35,18 +35,18 @@ type Env struct { // VerifySum indicates whether we should run checksums. VerifySum bool - // NoDownload forces us to not contact GCS or download the index via HTTP, + // NoDownload forces us to not contact remote services, // looking only at local files instead. NoDownload bool // ForceDownload forces us to ignore local files and always - // contact GCS or download the index via HTTP & re-download. + // contact remote services & re-download. ForceDownload bool - // UseGCS signals if the GCS client is used. - UseGCS bool + // UseDeprecatedGCS signals if the GCS client is used. + // Note: This will be removed together with remote.GCSClient. + UseDeprecatedGCS bool - // Client is our remote client for contacting GCS or - // to download the index via HTTP. + // Client is our remote client for contacting remote services. Client remote.Client // Log allows us to log. @@ -291,7 +291,7 @@ func (e *Env) Fetch(ctx context.Context) { } }) - archiveOut, err := e.FS.TempFile("", "*-"+e.Platform.ArchiveName(e.UseGCS, *e.Version.AsConcrete())) + archiveOut, err := e.FS.TempFile("", "*-"+e.Platform.ArchiveName(e.UseDeprecatedGCS, *e.Version.AsConcrete())) if err != nil { ExitCause(2, err, "unable to open file to write downloaded archive to") } diff --git a/tools/setup-envtest/main.go b/tools/setup-envtest/main.go index bf4fbdaf3a..7e2761a4f6 100644 --- a/tools/setup-envtest/main.go +++ b/tools/setup-envtest/main.go @@ -50,16 +50,16 @@ var ( binDir = flag.String("bin-dir", "", "directory to store binary assets (default: $OS_SPECIFIC_DATA_DIR/envtest-binaries)") - useGCS = flag.Bool("use-gcs", false, "use GCS to fetch envtest binaries") + useDeprecatedGCS = flag.Bool("use-deprecated-gcs", false, "use GCS to fetch envtest binaries. Note: This is deprecated and will be removed soon. For more details see: https://github.com/kubernetes-sigs/controller-runtime/pull/2811") - // These flags are only used with --use-gcs. - remoteBucket = flag.String("remote-bucket", "kubebuilder-tools", "remote GCS bucket to download from (only used with --use-gcs)") + // These flags are only used with --use-deprecated-gcs. + remoteBucket = flag.String("remote-bucket", "kubebuilder-tools", "remote GCS bucket to download from (only used with --use-deprecated-gcs)") remoteServer = flag.String("remote-server", "storage.googleapis.com", "remote server to query from. You can override this if you want to run "+ - "an internal storage server instead, or for testing. (only used with --use-gcs)") + "an internal storage server instead, or for testing. (only used with --use-deprecated-gcs)") - // This flag is only used if --use-gcs is not set or false (default). - index = flag.String("index", remote.DefaultIndexURL, "index to discover envtest binaries (only used if --use-gcs is not set, or set to false)") + // This flag is only used if --use-deprecated-gcs is not set or false (default). + index = flag.String("index", remote.DefaultIndexURL, "index to discover envtest binaries (only used if --use-deprecated-gcs is not set, or set to false)") ) // TODO(directxman12): handle interrupts? @@ -89,28 +89,28 @@ func setupEnv(globalLog logr.Logger, version string) *envp.Env { log.V(1).Info("using binaries directory", "dir", *binDir) var client remote.Client - if useGCS != nil && *useGCS { - client = &remote.GCSClient{ + if useDeprecatedGCS != nil && *useDeprecatedGCS { + client = &remote.GCSClient{ //nolint:staticcheck // deprecation accepted for now Log: globalLog.WithName("storage-client"), Bucket: *remoteBucket, Server: *remoteServer, } - log.V(1).Info("using GCS", "bucket", *remoteBucket, "server", *remoteServer) + log.V(1).Info("using deprecated GCS client", "bucket", *remoteBucket, "server", *remoteServer) } else { client = &remote.HTTPClient{ Log: globalLog.WithName("storage-client"), IndexURL: *index, } - log.V(1).Info("using HTTP", "index", *index) + log.V(1).Info("using HTTP client", "index", *index) } env := &envp.Env{ - Log: globalLog, - UseGCS: useGCS != nil && *useGCS, - Client: client, - VerifySum: *verify, - ForceDownload: *force, - NoDownload: *installedOnly, + Log: globalLog, + UseDeprecatedGCS: useDeprecatedGCS != nil && *useDeprecatedGCS, + Client: client, + VerifySum: *verify, + ForceDownload: *force, + NoDownload: *installedOnly, Platform: versions.PlatformItem{ Platform: versions.Platform{ OS: *targetOS, diff --git a/tools/setup-envtest/remote/gcs_client.go b/tools/setup-envtest/remote/gcs_client.go index 743e9dec64..85f321d5c5 100644 --- a/tools/setup-envtest/remote/gcs_client.go +++ b/tools/setup-envtest/remote/gcs_client.go @@ -33,6 +33,10 @@ var _ Client = &GCSClient{} // GCSClient is a basic client for fetching versions of the envtest binary archives // from GCS. +// +// Deprecated: This client is deprecated and will be removed soon. +// The kubebuilder GCS bucket that we use with this client might be shutdown at any time, +// see: https://github.com/kubernetes/k8s.io/issues/2647. type GCSClient struct { // Bucket is the bucket to fetch from. Bucket string diff --git a/tools/setup-envtest/versions/platform.go b/tools/setup-envtest/versions/platform.go index df92bb1b76..8b32ccd5bc 100644 --- a/tools/setup-envtest/versions/platform.go +++ b/tools/setup-envtest/versions/platform.go @@ -37,6 +37,7 @@ func (p Platform) BaseName(ver Concrete) string { } // ArchiveName returns the full archive name for this version and platform. +// useGCS is deprecated and will be removed when the remote.GCSClient is removed. func (p Platform) ArchiveName(useGCS bool, ver Concrete) string { if useGCS { return "kubebuilder-tools-" + p.BaseName(ver) + ".tar.gz" diff --git a/tools/setup-envtest/workflows/workflows_test.go b/tools/setup-envtest/workflows/workflows_test.go index bae99b8d5b..8c4007a415 100644 --- a/tools/setup-envtest/workflows/workflows_test.go +++ b/tools/setup-envtest/workflows/workflows_test.go @@ -79,7 +79,7 @@ func WorkflowTest(testMode string) { var client remote.Client switch testMode { case gcsMode: - client = &remote.GCSClient{ + client = &remote.GCSClient{ //nolint:staticcheck // deprecation accepted for now Log: testLog.WithName("gcs-client"), Bucket: "kubebuilder-tools-test", // test custom bucket functionality too Server: server.Addr(),