sigs.k8s.io/kubebuilder/v3@v3.14.0/test/testdata/generate.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 source "$(dirname "$0")/../common.sh" 18 19 # This function scaffolds test projects given a project name and flags. 20 # 21 # Usage: 22 # 23 # scaffold_test_project <project name> <flag1> <flag2> 24 function scaffold_test_project { 25 local project=$1 26 shift 27 local init_flags="$@" 28 29 local testdata_dir="$(dirname "$0")/../../testdata" 30 mkdir -p $testdata_dir/$project 31 rm -rf $testdata_dir/$project/* 32 pushd $testdata_dir/$project 33 34 # Remove tool binaries for projects of version 2, which don't have locally-configured binaries, 35 # so the correct versions are used. Also, webhooks in version 2 don't have --make flag 36 if [[ $init_flags =~ --project-version=2 ]]; then 37 rm -f "$(command -v controller-gen)" 38 rm -f "$(command -v kustomize)" 39 fi 40 41 header_text "Generating project ${project} with flags: ${init_flags}" 42 43 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 44 45 header_text "Initializing project ..." 46 $kb init $init_flags --domain testproject.org --license apache2 --owner "The Kubernetes authors" 47 48 if [ $project == "project-v2" ] || [ $project == "project-v3" ] || [ $project == "project-v3-config" ] || [ $project == "project-v4" ] || [ $project == "project-v4-config" ]; then 49 header_text 'Creating APIs ...' 50 $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false 51 $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false --force 52 $kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation 53 if [ $project == "project-v3" ]; then 54 $kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation --force 55 fi 56 57 if [ $project == "project-v2" ]; then 58 $kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false 59 else 60 $kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false 61 fi 62 $kb create webhook --group crew --version v1 --kind FirstMate --conversion 63 64 if [ $project == "project-v3" ] || [ $project == "project-v4" ]; then 65 $kb create api --group crew --version v1 --kind Admiral --plural=admirales --controller=true --resource=true --namespaced=false --make=false 66 $kb create webhook --group crew --version v1 --kind Admiral --plural=admirales --defaulting 67 else 68 $kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false 69 $kb create webhook --group crew --version v1 --kind Admiral --defaulting 70 fi 71 72 $kb create api --group crew --version v1 --kind Laker --controller=true --resource=false --make=false 73 elif [[ $project =~ multigroup ]]; then 74 header_text 'Switching to multigroup layout ...' 75 $kb edit --multigroup=true 76 77 header_text 'Creating APIs ...' 78 $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false 79 $kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation 80 81 $kb create api --group ship --version v1beta1 --kind Frigate --controller=true --resource=true --make=false 82 $kb create webhook --group ship --version v1beta1 --kind Frigate --conversion 83 84 $kb create api --group ship --version v1 --kind Destroyer --controller=true --resource=true --namespaced=false --make=false 85 $kb create webhook --group ship --version v1 --kind Destroyer --defaulting 86 87 $kb create api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false 88 $kb create webhook --group ship --version v2alpha1 --kind Cruiser --programmatic-validation 89 90 $kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false 91 92 $kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false 93 94 $kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false 95 96 $kb create api --group apps --version v1 --kind Deployment --controller=true --resource=false --make=false 97 98 $kb create api --group foo --version v1 --kind Bar --controller=true --resource=true --make=false 99 $kb create api --group fiz --version v1 --kind Bar --controller=true --resource=true --make=false 100 101 if [ $project == "project-v4-multigroup" ] || [ $project == "project-v4-multigroup-with-deploy-image" ] ; then 102 $kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false 103 $kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation 104 fi 105 elif [[ $project =~ deploy-image ]]; then 106 header_text 'Creating Memcached API with deploy-image plugin ...' 107 $kb create api --group example.com --version v1alpha1 --kind Memcached --image=memcached:1.4.36-alpine --image-container-command="memcached,-m=64,-o,modern,-v" --image-container-port="11211" --run-as-user="1001" --plugins="deploy-image/v1-alpha" --make=false 108 $kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.28 --plugins="deploy-image/v1-alpha" --make=false 109 header_text 'Creating Memcached webhook ...' 110 $kb create webhook --group example.com --version v1alpha1 --kind Memcached --programmatic-validation 111 fi 112 113 if [[ $project == project-v4-with-grafana ]]; then 114 header_text 'Editing project with Grafana plugin ...' 115 $kb edit --plugins=grafana.kubebuilder.io/v1-alpha 116 fi 117 118 make generate manifests 119 # TODO fix the error with multigroup layout and allow it be generated 120 # with this one. 121 # Error: trouble configuring builtin PatchTransformer with config: ` 122 # path: patches/webhook_in_sea-creatures_krakens.yaml 123 # `: failed to get the patch file from path(patches/webhook_in_sea-creatures_krakens.yaml): evalsymlink failure on '/Users/camiladeomacedo/go/src/sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/config/crd/patches/webhook_in_sea-creatures_krakens.yaml' : lstat go/src/sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/config/crd/patches/webhook_in_sea-creatures_krakens.yaml: no such file or directory 124 if [[ $project =~ v4 && ! $project =~ multigroup ]]; then 125 make build-installer 126 fi 127 128 rm -f go.sum 129 go mod tidy 130 popd 131 } 132 133 build_kb 134 135 # [Deprecated] - Project version 2 uses plugin go/v2 (default). 136 scaffold_test_project project-v2 --project-version=2 137 138 # [Deprecated] - Project version 3 (default) uses plugin go/v3 (default). 139 scaffold_test_project project-v3 --plugins="go/v3" 140 141 # [Currently, default CLI plugin] - [Next version, alpha] Project version v4-alpha 142 scaffold_test_project project-v4 --plugins="go/v4" 143 scaffold_test_project project-v4-multigroup --plugins="go/v4" 144 scaffold_test_project project-v4-multigroup-with-deploy-image --plugins="go/v4" 145 scaffold_test_project project-v4-with-deploy-image --plugins="go/v4" 146 scaffold_test_project project-v4-with-grafana --plugins="go/v4"