Skip to content

Commit

Permalink
setup-envtest: drop support for GCS
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Aug 9, 2024
1 parent fdc8bd7 commit 3a474bf
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 822 deletions.
30 changes: 1 addition & 29 deletions tools/setup-envtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ setup-envtest sideload 1.16.2 < downloaded-envtest.tar.gz
# To download from a custom index use the following:
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
# 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 @@ -107,8 +102,7 @@ Then, you have a few options for managing your binaries:

`--use-env` makes the command unconditionally use the value of
KUBEBUILDER_ASSETS as long as it contains the required binaries, and
`-i` indicates that we only ever want to work with installed binaries
(no reaching out the remote GCS storage).
`-i` indicates that we only ever want to work with installed binaries.

As noted about, you can use `ENVTEST_INSTALLED_ONLY=true` to switch `-i`
on by default, and you can use `ENVTEST_USE_ENV=true` to switch
Expand All @@ -123,25 +117,3 @@ Then, you have a few options for managing your binaries:
- If you want to talk to some internal source via HTTP, you can simply set `--index`
The index must contain references to envtest binary archives in the same format as:
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-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

- `HOST/storage/v1/b/BUCKET/o` to return JSON like

```json
{"items": [
{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"},
{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"}
]}
```

- `HOST/storage/v1/b/BUCKET/o/TARBALL_NAME` to return JSON like
`{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"}`

- `HOST/storage/v1/b/BUCKET/o/TARBALL_NAME?alt=media` to return the
actual file contents
6 changes: 1 addition & 5 deletions tools/setup-envtest/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ type Env struct {
// contact remote services & re-download.
ForceDownload 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 remote services.
Client remote.Client

Expand Down Expand Up @@ -291,7 +287,7 @@ func (e *Env) Fetch(ctx context.Context) {
}
})

archiveOut, err := e.FS.TempFile("", "*-"+e.Platform.ArchiveName(e.UseDeprecatedGCS, *e.Version.AsConcrete()))
archiveOut, err := e.FS.TempFile("", "*-"+e.Platform.ArchiveName(*e.Version.AsConcrete()))
if err != nil {
ExitCause(2, err, "unable to open file to write downloaded archive to")
}
Expand Down
42 changes: 11 additions & 31 deletions tools/setup-envtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ var (
binDir = flag.String("bin-dir", "",
"directory to store binary assets (default: $OS_SPECIFIC_DATA_DIR/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-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-deprecated-gcs)")

// 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)")
index = flag.String("index", remote.DefaultIndexURL, "index to discover envtest binaries")
)

// TODO(directxman12): handle interrupts?
Expand Down Expand Up @@ -88,29 +79,18 @@ func setupEnv(globalLog logr.Logger, version string) *envp.Env {
}
log.V(1).Info("using binaries directory", "dir", *binDir)

var client remote.Client
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 deprecated GCS client", "bucket", *remoteBucket, "server", *remoteServer)
} else {
client = &remote.HTTPClient{
Log: globalLog.WithName("storage-client"),
IndexURL: *index,
}
log.V(1).Info("using HTTP client", "index", *index)
client := &remote.HTTPClient{
Log: globalLog.WithName("storage-client"),
IndexURL: *index,
}
log.V(1).Info("using HTTP client", "index", *index)

env := &envp.Env{
Log: globalLog,
UseDeprecatedGCS: useDeprecatedGCS != nil && *useDeprecatedGCS,
Client: client,
VerifySum: *verify,
ForceDownload: *force,
NoDownload: *installedOnly,
Log: globalLog,
Client: client,
VerifySum: *verify,
ForceDownload: *force,
NoDownload: *installedOnly,
Platform: versions.PlatformItem{
Platform: versions.Platform{
OS: *targetOS,
Expand Down Expand Up @@ -189,7 +169,7 @@ Commands:
use:
get information for the requested version, downloading it if necessary and allowed.
Needs a concrete platform (no wildcards), but wilcard versions are supported.
Needs a concrete platform (no wildcards), but wildcard versions are supported.
list:
list installed *and* available versions matching the given version & platform.
Expand Down
202 changes: 0 additions & 202 deletions tools/setup-envtest/remote/gcs_client.go

This file was deleted.

2 changes: 1 addition & 1 deletion tools/setup-envtest/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (i Item) String() string {
}

// Filter is a version spec & platform selector (i.e. platform
// potentially with wilcards) to filter store items.
// potentially with wildcards) to filter store items.
type Filter struct {
Version versions.Spec
Platform versions.Platform
Expand Down
30 changes: 0 additions & 30 deletions tools/setup-envtest/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,36 +125,6 @@ var _ = Describe("Store", func() {
})
})

Describe("adding items (GCS archives)", func() {
archiveName := "kubebuilder-tools-1.16.3-linux-amd64.tar.gz"

It("should support .tar.gz input", func() {
Expect(st.Add(logCtx(), newItem, makeFakeArchive(archiveName, "kubebuilder/bin/"))).To(Succeed())
Expect(st.Has(newItem)).To(BeTrue(), "should have the item after adding it")
})

It("should extract binaries from the given archive to a directly to the item's directory, regardless of path", func() {
Expect(st.Add(logCtx(), newItem, makeFakeArchive(archiveName, "kubebuilder/bin/"))).To(Succeed())

dirName := newItem.Platform.BaseName(newItem.Version)
Expect(afero.ReadFile(st.Root, filepath.Join("k8s", dirName, "some-file"))).To(HavePrefix(archiveName + "some-file"))
Expect(afero.ReadFile(st.Root, filepath.Join("k8s", dirName, "other-file"))).To(HavePrefix(archiveName + "other-file"))
})

It("should clean up any existing item directory before creating the new one", func() {
item := localVersions[0]
Expect(st.Add(logCtx(), item, makeFakeArchive(archiveName, "kubebuilder/bin/"))).To(Succeed())
Expect(st.Root.Stat(filepath.Join("k8s", item.Platform.BaseName(item.Version)))).NotTo(BeNil(), "new files should exist")
})
It("should clean up if it errors before finishing", func() {
item := localVersions[0]
Expect(st.Add(logCtx(), item, new(bytes.Buffer))).NotTo(Succeed(), "should fail to extract")
_, err := st.Root.Stat(filepath.Join("k8s", item.Platform.BaseName(item.Version)))
Expect(err).To(HaveOccurred(), "the binaries dir for the item should be gone")

})
})

Describe("adding items (controller-tools archives)", func() {
archiveName := "envtest-v1.16.3-linux-amd64.tar.gz"

Expand Down
Loading

0 comments on commit 3a474bf

Please sign in to comment.