1616
1717source " $( dirname " $0 " ) /../common.sh"
1818
19+ # To keep fixed the cert-manager version used in the scaffold of eternal types and go version used.
20+ CERT_MANAGER_MODULE=" github.com/cert-manager/cert-manager"
21+ CERT_MANAGER_VERSION=" ${CERT_MANAGER_VERSION:- v1.18.2} "
22+ CERT_MANAGER_IMPORT=" ${CERT_MANAGER_MODULE} /pkg/apis/certmanager/v1"
23+ GO_VERSION_DIRECTIVE=" ${GO_VERSION_DIRECTIVE:- 1.24.5} "
24+
1925# This function scaffolds test projects given a project name and flags.
2026#
2127# Usage:
@@ -33,6 +39,10 @@ function scaffold_test_project {
3339
3440 header_text " Generating project ${project} with flags: ${init_flags} "
3541 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
42+ go mod edit -go=" ${GO_VERSION_DIRECTIVE} "
43+ if [[ $project == " project-v4" || $project == " project-v4-multigroup" ]]; then
44+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
45+ fi
3646 header_text " Initializing project ..."
3747 $kb init $init_flags --domain testproject.org --license apache2 --owner " The Kubernetes authors"
3848
@@ -50,9 +60,12 @@ function scaffold_test_project {
5060 $kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false
5161 $kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting
5262 # Controller for External types
53- $kb create api --group " cert-manager" --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 --external-api-domain=io
63+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
64+ $kb create api --group " cert-manager" --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=" ${CERT_MANAGER_IMPORT} " --external-api-domain=io
5465 # Webhook for External types
55- $kb create webhook --group " cert-manager" --version v1 --kind Issuer --defaulting --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 --external-api-domain=io
66+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
67+ $kb create webhook --group " cert-manager" --version v1 --kind Issuer --defaulting --external-api-path=" ${CERT_MANAGER_IMPORT} " --external-api-domain=io
68+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
5669 # Webhook for Core type
5770 $kb create webhook --group core --version v1 --kind Pod --defaulting
5871 # Webhook for kubernetes Core type that is part of an api group
@@ -81,9 +94,12 @@ function scaffold_test_project {
8194 $kb create api --group foo --version v1 --kind Bar --controller=true --resource=true --make=false
8295 $kb create api --group fiz --version v1 --kind Bar --controller=true --resource=true --make=false
8396 # Controller for External types
84- $kb create api --group " cert-manager" --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 --external-api-domain=io
97+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
98+ $kb create api --group " cert-manager" --version v1 --kind Certificate --controller=true --resource=false --make=false --external-api-path=" ${CERT_MANAGER_IMPORT} " --external-api-domain=io
8599 # Webhook for External types
86- $kb create webhook --group " cert-manager" --version v1 --kind Issuer --defaulting --external-api-path=github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 --external-api-domain=io
100+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
101+ $kb create webhook --group " cert-manager" --version v1 --kind Issuer --defaulting --external-api-path=" ${CERT_MANAGER_IMPORT} " --external-api-domain=io
102+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
87103 # Webhook for Core type
88104 $kb create webhook --group core --version v1 --kind Pod --programmatic-validation --make=false
89105 # Webhook for kubernetes Core type that is part of an api group
@@ -120,6 +136,10 @@ function scaffold_test_project {
120136 # To avoid conflicts
121137 rm -f go.sum
122138 go mod tidy
139+ go mod edit -go=" ${GO_VERSION_DIRECTIVE} "
140+ if [[ $project == " project-v4" || $project == " project-v4-multigroup" ]]; then
141+ go mod edit -require=" ${CERT_MANAGER_MODULE} @${CERT_MANAGER_VERSION} "
142+ fi
123143 popd
124144}
125145
0 commit comments