Skip to content

Commit

Permalink
some more deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed May 22, 2024
1 parent 56dcc14 commit ce4e4f5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
9 changes: 5 additions & 4 deletions tools/setup-envtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tools/setup-envtest/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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")
}
Expand Down
32 changes: 16 additions & 16 deletions tools/setup-envtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tools/setup-envtest/remote/gcs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/setup-envtest/versions/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/setup-envtest/workflows/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ce4e4f5

Please sign in to comment.