Skip to content

Commit

Permalink
Get rid of most references to GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Mar 1, 2024
1 parent 3c2940f commit 10c32b3
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 72 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ If you want to build Kubernetes right away there are two options:
##### You have a working [Go environment].

```
mkdir -p $GOPATH/src/k8s.io
cd $GOPATH/src/k8s.io
git clone https://github.com/kubernetes/kubernetes
cd kubernetes
make
Expand Down
1 change: 0 additions & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def file_extension(filename):

skipped_names = [
"third_party",
"_gopath",
"_output",
".git",
"cluster/env.sh",
Expand Down
1 change: 0 additions & 1 deletion hack/make-rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ kube::test::find_dirs() {
\( \
-path './_artifacts/*' \
-o -path './_output/*' \
-o -path './_gopath/*' \
-o -path './cmd/kubeadm/test/*' \
-o -path './contrib/podex/*' \
-o -path './release/*' \
Expand Down
1 change: 0 additions & 1 deletion hack/update-yamlfmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ find_files() {
-wholename './output' \
-o -wholename './.git' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/vendor/*' \
Expand Down
1 change: 0 additions & 1 deletion hack/verify-description.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ find_files() {
\( \
-wholename './output' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
Expand Down
1 change: 0 additions & 1 deletion hack/verify-fieldname-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ find_files() {
\( \
-wholename './output' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
Expand Down
2 changes: 0 additions & 2 deletions hack/verify-flags-underscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def get_all_files(rootdir):
dirs.remove('staging')
if '_output' in dirs:
dirs.remove('_output')
if '_gopath' in dirs:
dirs.remove('_gopath')
if 'third_party' in dirs:
dirs.remove('third_party')
if '.git' in dirs:
Expand Down
1 change: 0 additions & 1 deletion hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ find_files() {
-wholename './output' \
-o -wholename './.git' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
Expand Down
1 change: 0 additions & 1 deletion hack/verify-netparse-cve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ find_files() {
-wholename './output' \
-o -wholename './.git' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
Expand Down
1 change: 0 additions & 1 deletion hack/verify-readonly-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ find_files() {
\( \
-wholename './output' \
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
Expand Down
10 changes: 2 additions & 8 deletions staging/src/k8s.io/client-go/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,8 @@ go get k8s.io/[email protected]
### Go modules disabled

If you get a message like `cannot use path@version syntax in GOPATH mode`,
you likely do not have go modules enabled.

Dependency management tools are built into go 1.11+ in the form of
[go modules](https://github.com/golang/go/wiki/Modules).
These are used by the main Kubernetes repo (>= `v1.15.0`) and
`client-go` (>= `kubernetes-1.15.0`) to manage dependencies.
If you are using go 1.11 or 1.12 and are working with a project located within `$GOPATH`,
you must opt into using go modules:
you likely do not have go modules enabled. This should be on by default in all
supported versions of Go.

```sh
export GO111MODULE=on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package fake

import (
"io"
gopath "path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -153,7 +152,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
if generateApply {
// Generated apply builder type references required for generated Apply function
_, gvString := util.ParsePathGroupVersion(g.inputPackage)
m["inputApplyConfig"] = types.Ref(gopath.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration")
m["inputApplyConfig"] = types.Ref(filepath.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration")
}

if tags.NonNamespaced {
Expand Down Expand Up @@ -237,7 +236,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
m["resultType"] = &resultType
m["subresourcePath"] = e.SubResourcePath
if e.HasVerb("apply") {
m["inputApplyConfig"] = types.Ref(gopath.Join(g.applyConfigurationPackage, inputGVString), inputType.Name.Name+"ApplyConfiguration")
m["inputApplyConfig"] = types.Ref(filepath.Join(g.applyConfigurationPackage, inputGVString), inputType.Name.Name+"ApplyConfiguration")
}

if e.HasVerb("get") {
Expand Down
23 changes: 3 additions & 20 deletions staging/src/k8s.io/sample-apiserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,11 @@ Code changes are made in that location, merged into `k8s.io/kubernetes` and late

## Fetch sample-apiserver and its dependencies

Like the rest of Kubernetes, sample-apiserver has used
[godep](https://github.com/tools/godep) and `$GOPATH` for years and is
now adopting go 1.11 modules. There are thus two alternative ways to
go about fetching this demo and its dependencies.

### Fetch with godep

When NOT using go 1.11 modules, you can use the following commands.

```sh
go get -d k8s.io/sample-apiserver
cd $GOPATH/src/k8s.io/sample-apiserver # assuming your GOPATH has just one entry
godep restore
```

### When using go 1.11 modules

When using go 1.11 modules (`GO111MODULE=on`), issue the following
commands --- starting in whatever working directory you like.
Issue the following commands --- starting in whatever working directory you
like.

```sh
git clone https://github.com/kubernetes/sample-apiserver.git
git clone https://github.com/kubernetes/sample-apiserver
cd sample-apiserver
```

Expand Down
23 changes: 3 additions & 20 deletions staging/src/k8s.io/sample-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,11 @@ explained [here](docs/controller-client-go.md).

## Fetch sample-controller and its dependencies

Like the rest of Kubernetes, sample-controller has used
[godep](https://github.com/tools/godep) and `$GOPATH` for years and is
now adopting go 1.11 modules. There are thus two alternative ways to
go about fetching this demo and its dependencies.

### Fetch with godep

When NOT using go 1.11 modules, you can use the following commands.

```sh
go get -d k8s.io/sample-controller
cd $GOPATH/src/k8s.io/sample-controller
godep restore
```

### When using go 1.11 modules

When using go 1.11 modules (`GO111MODULE=on`), issue the following
commands --- starting in whatever working directory you like.
Issue the following commands --- starting in whatever working directory you
like.

```sh
git clone https://github.com/kubernetes/sample-controller.git
git clone https://github.com/kubernetes/sample-controller
cd sample-controller
```

Expand Down
20 changes: 11 additions & 9 deletions test/integration/auth/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,35 +583,37 @@ func TestRBAC(t *testing.T) {
previousResourceVersion := make(map[string]float64)

for j, r := range tc.requests {
path := "/"
// This is a URL-path, not a local path, so we use the "path"
// package (aliased as "gopath") instead of "path/filepath".
urlPath := "/"
if r.apiGroup == "" {
path = gopath.Join(path, "api/v1")
urlPath = gopath.Join(urlPath, "api/v1")
} else {
path = gopath.Join(path, "apis", r.apiGroup, "v1")
urlPath = gopath.Join(urlPath, "apis", r.apiGroup, "v1")
}
if r.namespace != "" {
path = gopath.Join(path, "namespaces", r.namespace)
urlPath = gopath.Join(urlPath, "namespaces", r.namespace)
}
if r.resource != "" {
path = gopath.Join(path, r.resource)
urlPath = gopath.Join(urlPath, r.resource)
}
if r.name != "" {
path = gopath.Join(path, r.name)
urlPath = gopath.Join(urlPath, r.name)
}

var body io.Reader
if r.body != "" {
sub := ""
if r.verb == "PUT" {
// For update operations, insert previous resource version
if resVersion := previousResourceVersion[getPreviousResourceVersionKey(path, "")]; resVersion != 0 {
if resVersion := previousResourceVersion[getPreviousResourceVersionKey(urlPath, "")]; resVersion != 0 {
sub += fmt.Sprintf(",\"resourceVersion\": \"%v\"", resVersion)
}
}
body = strings.NewReader(fmt.Sprintf(r.body, sub))
}

req, err := http.NewRequest(r.verb, kubeConfig.Host+path, body)
req, err := http.NewRequest(r.verb, kubeConfig.Host+urlPath, body)
if r.verb == "PATCH" {
// For patch operations, use the apply content type
req.Header.Add("Content-Type", string(types.ApplyPatchType))
Expand Down Expand Up @@ -662,7 +664,7 @@ func TestRBAC(t *testing.T) {
// For successful create operations, extract resourceVersion
id, currentResourceVersion, err := parseResourceVersion(b)
if err == nil {
key := getPreviousResourceVersionKey(path, id)
key := getPreviousResourceVersionKey(urlPath, id)
previousResourceVersion[key] = currentResourceVersion
} else {
t.Logf("error in trying to extract resource version: %s", err)
Expand Down

0 comments on commit 10c32b3

Please sign in to comment.