Skip to content

Commit 1f2332f

Browse files
cleanup: simplify and consolidate testdata samples
The testdata samples are designed to showcase various options for users and enable comprehensive testing of tool commands. By aggregating the Grafana and deploy-image plugins into the multigroup layout, we streamline test coverage and reduce redundancy. This change ensures all options are tested within the multigroup layout while keeping project-v4 with and without the optional plugins, to help us ensure the references for users and keep our CI tests. Now, instead of having a separate sample for each optional plugin, we have: - project-v4 - project-v4-multigroup-with-plugins - project-v4-with-plugins This consolidation reduces the number of samples and tests, making the codebase easier to maintain without sacrificing test coverage or usability for users.
1 parent c0ba5ce commit 1f2332f

File tree

477 files changed

+4037
-12970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

477 files changed

+4037
-12970
lines changed

.github/workflows/lint-sample.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ jobs:
2929
uses: golangci/golangci-lint-action@v6
3030
with:
3131
version: v1.59
32-
working-directory: testdata/project-v4-with-deploy-image
32+
working-directory: testdata/project-v4-with-plugins
3333
args: --config .golangci.yml ./...

.github/workflows/test-e2e-samples.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ jobs:
5454
- name: Create kind cluster
5555
run: kind create cluster
5656

57-
- name: Prepare project-v4-with-deploy-image
57+
- name: Prepare project-v4-with-plugins
5858
run: |
59-
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-deploy-image/config/default/kustomization.yaml"
59+
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-plugins/config/default/kustomization.yaml"
6060
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
6161
sed -i '51s/^#//' $KUSTOMIZATION_FILE_PATH
6262
# Uncomment only ValidatingWebhookConfiguration
@@ -68,12 +68,12 @@ jobs:
6868
# Comment the injection for MutatingWebhookConfiguration
6969
# Fixme: We should not scaffold or it should be commented
7070
# by default when only validation webhooks are scaffolded
71-
WEBHOOK_INJECTION_FILE_PATH="testdata/project-v4-with-deploy-image/config/default/webhookcainjection_patch.yaml"
71+
WEBHOOK_INJECTION_FILE_PATH="testdata/project-v4-with-plugins/config/default/webhookcainjection_patch.yaml"
7272
sed -i '3,11s/^/#/' $WEBHOOK_INJECTION_FILE_PATH
73-
cd testdata/project-v4-with-deploy-image/
73+
cd testdata/project-v4-with-plugins/
7474
go mod tidy
7575
76-
- name: Testing make test-e2e for project-v4-with-deploy-image
77-
working-directory: testdata/project-v4-with-deploy-image
76+
- name: Testing make test-e2e for project-v4-with-plugins
77+
working-directory: testdata/project-v4-with-plugins
7878
run: |
7979
make test-e2e

docs/book/src/plugins/deploy-image-plugin-v1-alpha.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ By using this plugin you will have:
1313
<aside class="note">
1414
<h1>Examples</h1>
1515

16-
See the "project-v4-with-deploy-image" directory under the [testdata][testdata] directory of the Kubebuilder project to check an example of a scaffolding created using this plugin.
16+
See the "project-v4-with-optional-plugins" directory under the [testdata][testdata] directory of the Kubebuilder project to check an example of a scaffolding created using this plugin.
1717

1818
</aside>
1919

docs/book/src/reference/envtest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Logs from the test runs are prefixed with `test-env`.
8383
8484
You can use the plugin [DeployImage](https://book.kubebuilder.io/plugins/deploy-image-plugin-v1-alpha.html) to check examples. This plugin allows users to scaffold API/Controllers to deploy and manage an Operand (image) on the cluster following the guidelines and best practices. It abstracts the complexities of achieving this goal while allowing users to customize the generated code.
8585
86-
Therefore, you can check that a test using ENV TEST will be generated for the controller which has the purpose to ensure that the Deployment is created successfully. You can see an example of its code implementation under the `testdata` directory with the [DeployImage](https://book.kubebuilder.io/plugins/deploy-image-plugin-v1-alpha.html) samples [here](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go).
86+
Therefore, you can check that a test using ENV TEST will be generated for the controller which has the purpose to ensure that the Deployment is created successfully. You can see an example of its code implementation under the `testdata` directory with the [DeployImage](https://book.kubebuilder.io/plugins/deploy-image-plugin-v1-alpha.html) samples [here](https://github.com/kubernetes-sigs/kubebuilder/blob/v3.7.0/testdata/project-v4-with-plugins/controllers/busybox_controller_test.go).
8787
8888
</aside>
8989

docs/book/src/reference/rescaffold.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ This way, you can easily overlay your project's code changes atop the new scaffo
4949
- Check out [video to show how it works](https://youtu.be/7997RIbx8kw?si=ODYMud5lLycz7osp)
5050
- See the [desing proposal documentation](../../../../designs/helper_to_upgrade_projects_by_rescaffolding.md)
5151

52-
[example]: ./../../../../testdata/project-v4-with-deploy-image/PROJECT
52+
[example]: ./../../../../testdata/project-v4-with-plugins/PROJECT
5353
[more-info]: ./../reference/project-config.md

test/testdata/generate.sh

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,22 @@ function scaffold_test_project {
3232
pushd $testdata_dir/$project
3333

3434
header_text "Generating project ${project} with flags: ${init_flags}"
35-
3635
go mod init sigs.k8s.io/kubebuilder/testdata/$project # our repo autodetection will traverse up to the kb module if we don't do this
37-
3836
header_text "Initializing project ..."
3937
$kb init $init_flags --domain testproject.org --license apache2 --owner "The Kubernetes authors"
4038

41-
if [ $project == "project-v4" ] || [ $project == "project-v4-config" ]; then
39+
if [ $project == "project-v4" ] ; then
4240
header_text 'Creating APIs ...'
4341
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false
4442
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false --force
4543
$kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation
4644
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
4745
$kb create webhook --group crew --version v1 --kind FirstMate --conversion
46+
$kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false
47+
$kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting
48+
fi
4849

49-
if [ $project == "project-v4" ]; then
50-
$kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false
51-
$kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting
52-
else
53-
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false
54-
$kb create webhook --group crew --version v1 --kind Admiral --defaulting
55-
fi
56-
57-
$kb create api --group crew --version v1 --kind Laker --controller=true --resource=false --make=false
58-
elif [[ $project =~ multigroup ]]; then
50+
if [[ $project =~ multigroup ]]; then
5951
header_text 'Switching to multigroup layout ...'
6052
$kb edit --multigroup=true
6153

@@ -65,46 +57,33 @@ function scaffold_test_project {
6557

6658
$kb create api --group ship --version v1beta1 --kind Frigate --controller=true --resource=true --make=false
6759
$kb create webhook --group ship --version v1beta1 --kind Frigate --conversion
68-
6960
$kb create api --group ship --version v1 --kind Destroyer --controller=true --resource=true --namespaced=false --make=false
7061
$kb create webhook --group ship --version v1 --kind Destroyer --defaulting
71-
7262
$kb create api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false
7363
$kb create webhook --group ship --version v2alpha1 --kind Cruiser --programmatic-validation
7464

7565
$kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false
76-
7766
$kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false
78-
7967
$kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false
80-
8168
$kb create api --group apps --version v1 --kind Deployment --controller=true --resource=false --make=false
82-
8369
$kb create api --group foo --version v1 --kind Bar --controller=true --resource=true --make=false
8470
$kb create api --group fiz --version v1 --kind Bar --controller=true --resource=true --make=false
8571

86-
if [ $project == "project-v4-multigroup" ] || [ $project == "project-v4-multigroup-with-deploy-image" ] ; then
87-
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
88-
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
89-
fi
90-
elif [[ $project =~ deploy-image ]]; then
91-
header_text 'Creating Memcached API with deploy-image plugin ...'
92-
$kb create api --group example.com --version v1alpha1 --kind Memcached --image=memcached:memcached:1.6.26-alpine3.19 --image-container-command="memcached,-m=64,-o,modern,-v" --image-container-port="11211" --run-as-user="1001" --plugins="deploy-image/v1-alpha" --make=false
93-
$kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false
94-
header_text 'Creating Memcached webhook ...'
95-
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation
72+
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
73+
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
9674
fi
9775

98-
if [[ $project == project-v4-with-grafana ]]; then
99-
header_text 'Editing project with Grafana plugin ...'
100-
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
101-
fi
102-
103-
make generate manifests
104-
if [[ $project =~ v4 ]]; then
105-
make build-installer
76+
if [[ $project =~ multigroup ]] || [[ $project =~ with-plugins ]] ; then
77+
header_text 'With Optional Plugins ...'
78+
header_text 'Creating APIs with deploy-image plugin ...'
79+
$kb create api --group example.com --version v1alpha1 --kind Memcached --image=memcached:memcached:1.6.26-alpine3.19 --image-container-command="memcached,-m=64,-o,modern,-v" --image-container-port="11211" --run-as-user="1001" --plugins="deploy-image/v1-alpha" --make=false
80+
$kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false
81+
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation
82+
header_text 'Editing project with Grafana plugin ...'
83+
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
10684
fi
10785

86+
make build-installer
10887
rm -f go.sum
10988
go mod tidy
11089
popd
@@ -113,7 +92,5 @@ function scaffold_test_project {
11392
build_kb
11493

11594
scaffold_test_project project-v4 --plugins="go/v4"
116-
scaffold_test_project project-v4-multigroup --plugins="go/v4"
117-
scaffold_test_project project-v4-multigroup-with-deploy-image --plugins="go/v4"
118-
scaffold_test_project project-v4-with-deploy-image --plugins="go/v4"
119-
scaffold_test_project project-v4-with-grafana --plugins="go/v4"
95+
scaffold_test_project project-v4-multigroup-with-plugins --plugins="go/v4"
96+
scaffold_test_project project-v4-with-plugins --plugins="go/v4"

test/testdata/test.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,5 @@ build_kb
3232

3333
# Project version v4-alpha
3434
test_project project-v4
35-
test_project project-v4-multigroup
36-
test_project project-v4-multigroup-with-deploy-image
37-
test_project project-v4-with-deploy-image
38-
test_project project-v4-with-grafana
35+
test_project project-v4-multigroup-with-plugins
36+
test_project project-v4-with-plugins

testdata/project-v4-multigroup-with-deploy-image/Makefile

Lines changed: 0 additions & 212 deletions
This file was deleted.

0 commit comments

Comments
 (0)