Skip to content

Commit

Permalink
Merge pull request #3915 from towca/jtuznik/update-vendor-script
Browse files Browse the repository at this point in the history
Simplify update-vendor script
  • Loading branch information
k8s-ci-robot authored Mar 4, 2021
2 parents efdde8a + f8c558e commit 5f2e54a
Show file tree
Hide file tree
Showing 1,320 changed files with 20,504 additions and 46,792 deletions.
40 changes: 8 additions & 32 deletions cluster-autoscaler/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,40 +918,16 @@ Cluster Autoscaler imports a huge chunk of internal k8s code as it calls out to
Therefore we want to keep set of libraries used in CA as close to one used by k8s, to avoid
unexpected problems coming from version incompatibilities.

Cluster Autoscaler depends on `go modules` mechanism for dependency management, but do not use it directly
during build process. `go.mod` file is just used to generate the `vendor` directory and further compilation
is run against set of libraries stored in `vendor`. `vendor` directory can be regenerated using [`update-vendor.sh`](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/hack/update-vendor.sh) script.
The `update-vendor.sh` script is responsible for autogenerating `go.mod` file used by Cluster Autoscaler. The base
of the file is `go.mod` file coming from [kubernetes/kubernetes](https://github.com/kubernetes/kubernetes) repository.
On top of that script adds modifications as defined
locally in [`go.mod-extra`](https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/go.mod-extra) file.

Note: It is important that one should **never manually edit** `go.mod` file as it is regenerated
on each `update-vendor.sh` call. Any extra libraries or version overrides should be put in `go.mod-extra` file (syntax of the file
is same as syntax of `go.mod` file).

Finally `vendor` directry is materialized and validation tests are run.

If everything completes correctly a commit with updated `vendor` directory is created automatically. The pull-request with changed vendor
must be sent out manually. The PR should include the auto-generated commit as well as commits containing any manual changes/fixes that need to
go together.

Execution of `update-vendor.sh` can be parametrized using command line argumets:
- `-f` - kubernetes/kubernetes fork to use. On `master` it defaults to `[email protected]:kubernetes/kubernetes.git`
- `-r` - revision in kubernetes/kubernetes which should be used to get base `go.mod` file
- `-d` - specifies script workdir; useful to speed up execution if script needs to be run multiple times, because updating vendor resulted in some compilation errors on Cluster-Autoscaler side which need to be fixed
- `-o` - overrides go version check, which may be useful if CA needs to use a different go version than the one in kubernetes go.mod file
To sync the repositories' vendored k8s libraries, we have a script that takes a
released version of k8s and updates the `replace` directives of each k8s
sub-library.

Example execution looks like this:
```
./hack/update-vendor.sh -d/tmp/ca-update-vendor.ou1l [email protected]:kubernetes/kubernetes.git -rmaster
./hack/update-vendor.sh 1.20.0-alpha.1
```

Caveats:
- `update-vendor.sh` is called directly in shell (no docker is used) therefore its operation may differ from environment to environment.
- It is important that go version, which isn in use in the shell in which `update-vendor.sh` is called, matches the `go <version>` directive specified in `go.mod` file
in `kubernetes/kubernetes` revision against which revendoring is done.
- `update-vendor.sh` automatically runs unit tests as part of verification process. If one needs to suppress that, it can be done by overriding `VERIFY_COMMAND` variable (`VERIFY_COMMAND=true ./hack/update-vendor.sh ...`)
- If one wants to only add new libraries to `go.mod-extra`, but not change the base `go.mod`, `-r` should be used with kubernetes/kubernets revision, which was used last time `update-vendor.sh` was called. One can determine that revision by looking at `git log` in Cluster Autoscaler repository. Following command will do the trick `git log | grep "Updating vendor against"`.


If you need to update vendor to an unreleased commit of Kubernetes, you can use the breakglass script:
```
./hack/submodule-k8s.sh <k8s commit sha>
```
7 changes: 3 additions & 4 deletions cluster-autoscaler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all: $(addprefix build-arch-,$(ALL_ARCH))
TAG?=dev
FLAGS=
LDFLAGS?=-s
ENVVAR=CGO_ENABLED=0 GO111MODULE=off
ENVVAR=CGO_ENABLED=0
GOOS?=linux
GOARCH?=$(shell go env GOARCH)
REGISTRY?=staging-k8s.gcr.io
Expand Down Expand Up @@ -44,7 +44,7 @@ build-binary-arch-%: clean-arch-%
$(ENVVAR) GOOS=$(GOOS) GOARCH=$* go build -o cluster-autoscaler-$* ${LDFLAGS_FLAG} ${TAGS_FLAG}

test-unit: clean build
GO111MODULE=off go test --test.short -race ./... ${TAGS_FLAG}
go test --test.short -race ./... ${TAGS_FLAG}

dev-release: dev-release-arch-$(GOARCH)

Expand Down Expand Up @@ -108,7 +108,6 @@ container-arch-%: build-in-docker-arch-% make-image-arch-%
@echo "Full in-docker image ${TAG}${FOR_PROVIDER}-$* completed"

test-in-docker: clean docker-builder
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest \
bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && GO111MODULE=off go test -race ./... ${TAGS_FLAG}'
docker run ${RM_FLAG} -v `pwd`:/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /cluster-autoscaler && go test -race ./... ${TAGS_FLAG}'

.PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/alicloud/alibaba-cloud-sdk-go/services/ess"
klog "k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"
"math/rand"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
klog "k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"
provider_aws "k8s.io/legacy-cloud-providers/aws"
)

Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"
provider_aws "k8s.io/legacy-cloud-providers/aws"
)

Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/azure/azure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
cloudvolume "k8s.io/cloud-provider/volume"
"k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"
"math/rand"
"regexp"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/gce/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
"k8s.io/autoscaler/cluster-autoscaler/utils/units"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"

"github.com/ghodss/yaml"
klog "k8s.io/klog/v2"
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
quota "k8s.io/apiserver/pkg/quota/v1"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"

"github.com/stretchr/testify/assert"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
huaweicloudsdkecsmodel "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/services/ecs/v2/model"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
"k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
kubeletapis "k8s.io/kubelet/pkg/apis"
)

// ElasticCloudServerService represents the elastic cloud server interfaces.
Expand Down
41 changes: 0 additions & 41 deletions cluster-autoscaler/fix_gopath.sh

This file was deleted.

Loading

0 comments on commit 5f2e54a

Please sign in to comment.