Skip to content

Commit

Permalink
cleanup: simplify and consolidate testdata samples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
camilamacedo86 committed Sep 8, 2024
1 parent 8f9e72c commit df7dfa6
Show file tree
Hide file tree
Showing 471 changed files with 4,084 additions and 13,550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
working-directory: testdata/project-v4-with-deploy-image
working-directory: testdata/project-v4-with-plugins
args: --config .golangci.yml ./...
12 changes: 6 additions & 6 deletions .github/workflows/test-e2e-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ jobs:
- name: Create kind cluster
run: kind create cluster

- name: Prepare project-v4-with-deploy-image
- name: Prepare project-v4-with-plugins
run: |
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-deploy-image/config/default/kustomization.yaml"
KUSTOMIZATION_FILE_PATH="testdata/project-v4-with-plugins/config/default/kustomization.yaml"
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '51s/^#//' $KUSTOMIZATION_FILE_PATH
# Uncomment only ValidatingWebhookConfiguration
Expand All @@ -68,12 +68,12 @@ jobs:
# Comment the injection for MutatingWebhookConfiguration
# Fixme: We should not scaffold or it should be commented
# by default when only validation webhooks are scaffolded
WEBHOOK_INJECTION_FILE_PATH="testdata/project-v4-with-deploy-image/config/default/webhookcainjection_patch.yaml"
WEBHOOK_INJECTION_FILE_PATH="testdata/project-v4-with-plugins/config/default/webhookcainjection_patch.yaml"
sed -i '3,11s/^/#/' $WEBHOOK_INJECTION_FILE_PATH
cd testdata/project-v4-with-deploy-image/
cd testdata/project-v4-with-plugins/
go mod tidy
- name: Testing make test-e2e for project-v4-with-deploy-image
working-directory: testdata/project-v4-with-deploy-image
- name: Testing make test-e2e for project-v4-with-plugins
working-directory: testdata/project-v4-with-plugins
run: |
make test-e2e
2 changes: 1 addition & 1 deletion docs/book/src/plugins/deploy-image-plugin-v1-alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ By using this plugin you will have:
<aside class="note">
<h1>Examples</h1>

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.
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.

</aside>

Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/reference/envtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Logs from the test runs are prefixed with `test-env`.
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.
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).
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).
</aside>
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/reference/rescaffold.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ This way, you can easily overlay your project's code changes atop the new scaffo
- Check out [video to show how it works](https://youtu.be/7997RIbx8kw?si=ODYMud5lLycz7osp)
- See the [desing proposal documentation](../../../../designs/helper_to_upgrade_projects_by_rescaffolding.md)

[example]: ./../../../../testdata/project-v4-with-deploy-image/PROJECT
[example]: ./../../../../testdata/project-v4-with-plugins/PROJECT
[more-info]: ./../reference/project-config.md
57 changes: 18 additions & 39 deletions test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,22 @@ function scaffold_test_project {
pushd $testdata_dir/$project

header_text "Generating project ${project} with flags: ${init_flags}"

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

header_text "Initializing project ..."
$kb init $init_flags --domain testproject.org --license apache2 --owner "The Kubernetes authors"

if [ $project == "project-v4" ] || [ $project == "project-v4-config" ]; then
if [ $project == "project-v4" ] ; then
header_text 'Creating APIs ...'
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false --force
$kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
$kb create webhook --group crew --version v1 --kind FirstMate --conversion
$kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false
$kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting
fi

if [ $project == "project-v4" ]; then
$kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false
$kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting
else
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false
$kb create webhook --group crew --version v1 --kind Admiral --defaulting
fi
elif [[ $project =~ multigroup ]]; then
if [[ $project =~ multigroup ]]; then
header_text 'Switching to multigroup layout ...'
$kb edit --multigroup=true

Expand All @@ -63,46 +57,33 @@ function scaffold_test_project {

$kb create api --group ship --version v1beta1 --kind Frigate --controller=true --resource=true --make=false
$kb create webhook --group ship --version v1beta1 --kind Frigate --conversion

$kb create api --group ship --version v1 --kind Destroyer --controller=true --resource=true --namespaced=false --make=false
$kb create webhook --group ship --version v1 --kind Destroyer --defaulting

$kb create api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false
$kb create webhook --group ship --version v2alpha1 --kind Cruiser --programmatic-validation

$kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false

$kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false

$kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false

$kb create api --group apps --version v1 --kind Deployment --controller=true --resource=false --make=false

$kb create api --group foo --version v1 --kind Bar --controller=true --resource=true --make=false
$kb create api --group fiz --version v1 --kind Bar --controller=true --resource=true --make=false

if [ $project == "project-v4-multigroup" ] || [ $project == "project-v4-multigroup-with-deploy-image" ] ; then
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
fi
elif [[ $project =~ deploy-image ]]; then
header_text 'Creating Memcached API with deploy-image plugin ...'
$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
$kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false
header_text 'Creating Memcached webhook ...'
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
fi

if [[ $project == project-v4-with-grafana ]]; then
header_text 'Editing project with Grafana plugin ...'
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
fi

make generate manifests
if [[ $project =~ v4 ]]; then
make build-installer
if [[ $project =~ multigroup ]] || [[ $project =~ with-plugins ]] ; then
header_text 'With Optional Plugins ...'
header_text 'Creating APIs with deploy-image plugin ...'
$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
$kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation
header_text 'Editing project with Grafana plugin ...'
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
fi

make build-installer
rm -f go.sum
go mod tidy
popd
Expand All @@ -111,7 +92,5 @@ function scaffold_test_project {
build_kb

scaffold_test_project project-v4 --plugins="go/v4"
scaffold_test_project project-v4-multigroup --plugins="go/v4"
scaffold_test_project project-v4-multigroup-with-deploy-image --plugins="go/v4"
scaffold_test_project project-v4-with-deploy-image --plugins="go/v4"
scaffold_test_project project-v4-with-grafana --plugins="go/v4"
scaffold_test_project project-v4-multigroup-with-plugins --plugins="go/v4"
scaffold_test_project project-v4-with-plugins --plugins="go/v4"
6 changes: 2 additions & 4 deletions test/testdata/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ build_kb

# Project version v4-alpha
test_project project-v4
test_project project-v4-multigroup
test_project project-v4-multigroup-with-deploy-image
test_project project-v4-with-deploy-image
test_project project-v4-with-grafana
test_project project-v4-multigroup-with-plugins
test_project project-v4-with-plugins
212 changes: 0 additions & 212 deletions testdata/project-v4-multigroup-with-deploy-image/Makefile

This file was deleted.

Loading

0 comments on commit df7dfa6

Please sign in to comment.