Skip to content

Commit 831ca8d

Browse files
committed
fix envtest handling
1 parent 9b52c49 commit 831ca8d

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

README.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,39 @@ includes:
5555

5656
Since the imported Taskfile is generic, there are a few variables that need to be set in order to configure the tasks correctly. Unless specified otherwise, the variables must not be specified if their respective purpose doesn't apply to the importing repository (e.g. `NESTED_MODULES` is not required if there are no nested modules).
5757
- `NESTED_MODULES`
58-
- List of nested modules, separated by spaces.
59-
- Note that the module has to be located in a subfolder that matches its name.
60-
- Required for multiple tools from the golang environment which are able to work on a single module only and therefore have to be called once per go module.
58+
- List of nested modules, separated by spaces.
59+
- Note that the module has to be located in a subfolder that matches its name.
60+
- Required for multiple tools from the golang environment which are able to work on a single module only and therefore have to be called once per go module.
6161
- `API_DIRS`
62-
- List of files with API type definitions for which k8s CRDs should be generated.
63-
- The `<directory>/...` syntax can be used to refer to all files in the directory and its subdirectories.
64-
- This is fed into the k8s code generation tool for CRD generation.
62+
- List of files with API type definitions for which k8s CRDs should be generated.
63+
- The `<directory>/...` syntax can be used to refer to all files in the directory and its subdirectories.
64+
- This is fed into the k8s code generation tool for CRD generation.
6565
- `MANIFEST_OUT`
66-
- Directory where the generated CRDs should be put in.
66+
- Directory where the generated CRDs should be put in.
6767
- `CODE_DIRS`
68-
- List of files with go code, separated by spaces.
69-
- The `<directory>/...` syntax can be used to refer to all files in the directory and its subdirectories.
70-
- Formatting and linting checks are executed on these files.
71-
- This variable must always be specified.
68+
- List of files with go code, separated by spaces.
69+
- The `<directory>/...` syntax can be used to refer to all files in the directory and its subdirectories.
70+
- Formatting and linting checks are executed on these files.
71+
- This variable must always be specified.
7272
- `COMPONENTS`
73-
- A list of 'components' contained in this repository, separated by spaces.
74-
- This is relevant for binary, image, chart, and OCM component building. Each entry will result in a separate build artifact for the respective builds.
75-
- A 'component' specified here has some implications:
76-
- A `cmd/<component>/main.go` file is expected for binary builds.
77-
- A separate docker image will be built for each component.
78-
- If the component has a helm chart, it is expected under `charts/<component>/`.
79-
- Note that support for helm charts is not fully implemented yet.
80-
- Each component will get its own OCM component.
81-
- Note that support for OCM components is not implemented yet.
82-
- Library repos will not have any component, operator repos will mostly contain just a single component (the operator itself).
73+
- A list of 'components' contained in this repository, separated by spaces.
74+
- This is relevant for binary, image, chart, and OCM component building. Each entry will result in a separate build artifact for the respective builds.
75+
- A 'component' specified here has some implications:
76+
- A `cmd/<component>/main.go` file is expected for binary builds.
77+
- A separate docker image will be built for each component.
78+
- If the component has a helm chart, it is expected under `charts/<component>/`.
79+
- Note that support for helm charts is not fully implemented yet.
80+
- Each component will get its own OCM component.
81+
- Note that support for OCM components is not implemented yet.
82+
- Library repos will not have any component, operator repos will mostly contain just a single component (the operator itself).
8383
- `REPO_URL`
84-
- URL of the github repository that contains the Taskfile.
85-
- This is used for building the OCM component, which will fail if it is not specified.
84+
- URL of the github repository that contains the Taskfile.
85+
- This is used for building the OCM component, which will fail if it is not specified.
8686
- `GENERATE_DOCS_INDEX`
87-
- If this is set and its value is not `false`, the `generate:docs` target will generate a documentation index at `docs/README.md`. Otherwise, the task is skipped.
88-
- See below for a short documentation of the the index generation.
87+
- If this is set and its value is not `false`, the `generate:docs` target will generate a documentation index at `docs/README.md`. Otherwise, the task is skipped.
88+
- See below for a short documentation of the the index generation.
89+
- `ENVTEST_REQUIRED`
90+
- If this is set to `true`, the `test` task will include the `setup-envtest` tooling in its dependencies and download it automatically.
8991

9092
There are two main Taskfiles, one of which should be included:
9193
- `Taskfile_controller.yaml` is meant for operator repositories and contains task definitions for code generation and validation, binary builds, and image builds.
@@ -108,10 +110,12 @@ includes:
108110

109111
Adding new specialized tasks in addition to the imported generic ones is straightforward: simply add the task definitions in the importing Taskfile.
110112

111-
It is also possible to exclude or overwrite generic tasks. The following example uses an `external-apis` task that should be executed as part of the generic `generate:code` task, and it adds a envtest dependency to the `validate:test` task.
113+
It is also possible to exclude or overwrite generic tasks. The following example uses an `external-apis` task that should be executed as part of the generic `generate:code` task.
112114

113115
Overwriting basically works by excluding and re-defining the generic task that should be overwritten. If the generic task's logic should be kept as part of the overwritten definition, the generic file needs to be imported a second time with `internal: true`, so that the original task can be called.
114116

117+
Note that some tasks are re-used internally with a different name due to the way `task` handles scoping. If you overwrite a task and run into issues, you might have to overwrite the same task again with a different name. In theory, adding a fitting alias to the overwrite should suffice. This theory has not yet been tested, though.
118+
115119
```yaml
116120
includes:
117121
shared:
@@ -141,17 +145,6 @@ tasks:
141145
run: once
142146
<...>
143147
internal: true
144-
145-
validate:test: # overwrites the test task to add a dependency towards envtest
146-
desc: " Run all tests."
147-
aliases:
148-
- val:test
149-
- v:test
150-
run: once
151-
deps:
152-
- tools:envtest
153-
cmds:
154-
- task: c:validate:test
155148
```
156149

157150
### Makefile

Taskfile_library.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ vars:
5858
YAML2JSON_VERSION: '{{ .YAML2JSON_VERSION | default "v1.3.5" }}'
5959
OCM: '{{ .OCM | default (print .LOCALBIN "/ocm") }}'
6060
OCM_VERSION: '{{ .OCM_VERSION | default "v0.21.0" }}'
61-
ENVTEST: '{{ .ENVTEST | default (print .LOCALTMP "/setup-envtest") }}'
61+
ENVTEST: '{{ .ENVTEST | default (print .LOCALBIN "/setup-envtest") }}'
6262
ENVTEST_VERSION: '{{ .ENVTEST_VERSION | default "release-0.16" }}'
6363

6464
DOCKER_BUILDER_NAME: # move to build taskfile later

tasks_tools.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,5 @@ tasks:
173173
- 'cat {{.LOCALBIN}}/envtest_version | grep -q "{{.ENVTEST_VERSION}}"'
174174
cmds:
175175
- 'GOBIN="{{.LOCALBIN}}" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@{{.ENVTEST_VERSION}}'
176+
- echo -n "{{.ENVTEST_VERSION}}" > {{.LOCALBIN}}/envtest_version
176177
internal: true

tasks_val.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@ tasks:
2626
requires:
2727
vars:
2828
- CODE_DIRS
29+
deps:
30+
- test-envtest-dep
2931
cmds:
3032
- 'PROJECT_ROOT="{{.ROOT_DIR2}}" NESTED_MODULES="{{.NESTED_MODULES}}" {{.TASKFILE_DIR2}}/run-tests.sh {{.CODE_DIRS}}'
3133

34+
test-envtest-dep:
35+
desc: " Install the envtest dependency, if marked as required."
36+
run: once
37+
status:
38+
- '[ "{{.ENVTEST_REQUIRED | default "false"}}" != "true" ]'
39+
cmds:
40+
- task: tools:envtest
41+
internal: true
42+
3243
validate:
3344
desc: " Combines all validation tasks except for tests."
3445
run: once

0 commit comments

Comments
 (0)