Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Download CRD deps only when necessary #783

Merged
merged 1 commit into from
Jan 27, 2023
Merged

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented Jan 16, 2023

Create individual make targets for the CRD dependencies so that make can identify that the CRD dependencies have already been downloaded and skip. When the SOURCE_VER changes, old CRDs are deleted and new ones are
downloaded, keeping a record of the source CRD versions in build/.src-crd-<version> by file name.
Also, introduce cleanup-crd-deps make target to delete the previously downloaded CRDs.

Without this, the CRDs were downloaded every single time when running tests:

$ ls config/crd/bases/
buckets.yaml  gitrepositories.yaml  kustomize.toolkit.fluxcd.io_kustomizations.yaml  ocirepositories.yaml

# After removing the curl silence option from Makefile. 
$ make test
...
curl https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml > config/crd/bases/gitrepositories.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 38070  100 38070    0     0  31504      0  0:00:01  0:00:01 --:--:-- 31488
curl https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml > config/crd/bases/buckets.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24578  100 24578    0     0  66385      0 --:--:-- --:--:-- --:--:-- 66427
curl https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml > config/crd/bases/ocirepositories.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17450  100 17450    0     0  16903      0  0:00:01  0:00:01 --:--:-- 16908
...

An alternative is to pass the curl continue-at option -C - which checks with remote and doesn't downloads the same file if it has been downloaded already:

curl -C - https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml -o config/crd/bases/gitrepositories.yaml
** Resuming transfer from byte position 38070
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl -C - https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml -o config/crd/bases/buckets.yaml
** Resuming transfer from byte position 24578
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl -C - https://raw.githubusercontent.com/fluxcd/source-controller/v0.33.0/config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml -o config/crd/bases/ocirepositories.yaml
** Resuming transfer from byte position 17450
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

But with individual make targets for the CRDs, there's no need to check if the downloaded files match with the remote. It's better to just skip downloading entirely if the file exists using make's native style.

For handling overall updates to such dependencies, it may be better to introduce a distclean make target that resets the repository, deleting any old files that need to be updated. Maybe later as a separate PR.

@darkowlzz darkowlzz added the area/ci CI related issues and pull requests label Jan 16, 2023
Makefile Show resolved Hide resolved
@darkowlzz
Copy link
Contributor Author

darkowlzz commented Jan 16, 2023

I've pinned envtest kubernetes version to 1.25 in #784, which fixes the controller test failure due to the new HorizontalPodAutoscaler API.

@darkowlzz darkowlzz force-pushed the crd-deps-downloads branch 3 times, most recently from 2468434 to 2f55576 Compare January 17, 2023 16:41
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @darkowlzz

Create individual make targets for the CRD dependencies so that make can
identify that the CRD dependencies have already been downloaded and
skip. When the SOURCE_VER changes, old CRDs are deleted and new ones are
downloaded, keeping a record of the source CRD versions in
build/.src-crd-<version> by file name.
Also, introduce `cleanup-crd-deps` make target to delete the previously
downloaded CRDs.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
@stefanprodan stefanprodan merged commit 14b3d4a into main Jan 27, 2023
@stefanprodan stefanprodan deleted the crd-deps-downloads branch January 27, 2023 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci CI related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants