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 the test coverage and reduce redundancy. This change ensures all options are tested within the multigroup layout while keeping project-v4 and project-with-deploy-image as simpler, more focused references for users and CI tests.

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 2, 2024
1 parent c0ba5ce commit 7c0d048
Show file tree
Hide file tree
Showing 387 changed files with 245 additions and 14,498 deletions.
60 changes: 19 additions & 41 deletions test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,19 @@ 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

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

$kb create api --group crew --version v1 --kind Laker --controller=true --resource=false --make=false
$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
elif [[ $project =~ multigroup ]]; then
header_text 'Switching to multigroup layout ...'
$kb edit --multigroup=true
Expand All @@ -65,46 +55,36 @@ 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
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
elif [[ $project =~ deploy-image ]] || [[ $project =~ multigroup ]]; 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
if [[ $project =~ deploy-image ]]; then
header_text 'Creating Busybox API with deploy-image plugin ...'
$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 Validating webhook for Memcached ...'
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation
fi
if [[ $project =~ multigroup ]]; then
header_text 'Editing project with Grafana plugin ...'
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
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
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
fi

make build-installer
rm -f go.sum
go mod tidy
popd
Expand All @@ -113,7 +93,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-multigroup-with-optional-plugins --plugins="go/v4"
scaffold_test_project project-v4-with-deploy-image --plugins="go/v4"
scaffold_test_project project-v4-with-grafana --plugins="go/v4"
4 changes: 1 addition & 3 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-multigroup-with-optional-plugins
test_project project-v4-with-deploy-image
test_project project-v4-with-grafana

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7c0d048

Please sign in to comment.