From 6fafcb9386e577c404bd9aad339473013c87fb26 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Wed, 5 Feb 2020 18:51:47 +0000 Subject: [PATCH] clean code - remove V1 implementations --- .travis.yml | 2 - CONTRIBUTING.md | 5 +- Makefile | 4 - cmd/init.go | 53 +--- cmd/internal/config.go | 31 +- cmd/main.go | 32 +- cmd/webhook.go | 105 ------- common.sh | 49 --- generate_golden.sh | 89 ++---- generate_vendor.sh | 61 ---- golden_test.sh | 1 - pkg/scaffold/api.go | 53 +--- pkg/scaffold/init.go | 27 +- pkg/scaffold/v1/authproxyservice.go | 61 ---- pkg/scaffold/v1/controller/add.go | 60 ---- pkg/scaffold/v1/controller/controller.go | 220 ------------- .../v1/controller/controllersuitetest.go | 107 ------- pkg/scaffold/v1/controller/controllertest.go | 125 -------- pkg/scaffold/v1/crd/addtoscheme.go | 67 ---- pkg/scaffold/v1/crd/crd_sample.go | 65 ---- pkg/scaffold/v1/crd/doc.go | 60 ---- pkg/scaffold/v1/crd/group.go | 54 ---- pkg/scaffold/v1/crd/register.go | 83 ----- pkg/scaffold/v1/crd/types.go | 108 ------- pkg/scaffold/v1/crd/typestest.go | 101 ------ pkg/scaffold/v1/crd/version_suitetest.go | 92 ------ pkg/scaffold/v1/kustomize_image_patch.go | 61 ---- pkg/scaffold/v1/manager/apis.go | 81 ----- pkg/scaffold/v1/manager/cmd.go | 110 ------- pkg/scaffold/v1/manager/config.go | 127 -------- pkg/scaffold/v1/manager/controller.go | 61 ---- pkg/scaffold/v1/manager/dockerfile.go | 56 ---- pkg/scaffold/v1/manager/webhook.go | 65 ---- .../metricsauth/kustomize_auth_proxy_patch.go | 67 ---- .../v1/metricsauth/kustomize_metrics_patch.go | 62 ---- .../webhook/add_admissionbuilder_handler.go | 85 ----- pkg/scaffold/v1/webhook/add_server.go | 56 ---- pkg/scaffold/v1/webhook/admissionbuilder.go | 93 ------ pkg/scaffold/v1/webhook/admissionhandler.go | 165 ---------- pkg/scaffold/v1/webhook/admissionwebhooks.go | 69 ----- pkg/scaffold/v1/webhook/config.go | 27 -- pkg/scaffold/v1/webhook/server.go | 120 ------- pkg/scaffold/v1/webhook/util.go | 27 -- pkg/scaffold/webhook.go | 24 +- scripts/generate_dep_manifest.sh | 61 ---- test.sh | 19 +- test/e2e/v1/e2e_suite.go | 166 ---------- test/e2e/v1/e2e_test.go | 32 -- test_e2e.sh | 5 - testdata/gopath/src/project/.gitignore | 24 -- testdata/gopath/src/project/Dockerfile | 17 - testdata/gopath/src/project/Gopkg.toml | 37 --- testdata/gopath/src/project/Makefile | 55 ---- testdata/gopath/src/project/PROJECT | 3 - .../gopath/src/project/cmd/manager/main.go | 85 ----- .../crds/creatures_v2alpha1_kraken.yaml | 39 --- .../config/crds/crew_v1_firstmate.yaml | 39 --- .../policy_v1beta1_healthcheckpolicy.yaml | 39 --- .../config/crds/ship_v1beta1_frigate.yaml | 39 --- .../project/config/default/kustomization.yaml | 37 --- .../default/manager_auth_proxy_patch.yaml | 24 -- .../config/default/manager_image_patch.yaml | 12 - .../manager_prometheus_metrics_patch.yaml | 19 -- .../project/config/manager/kustomization.yaml | 2 - .../src/project/config/manager/manager.yaml | 84 ----- .../project/config/rbac/auth_proxy_role.yaml | 13 - .../config/rbac/auth_proxy_role_binding.yaml | 12 - .../config/rbac/auth_proxy_service.yaml | 20 -- .../project/config/rbac/kustomization.yaml | 9 - .../src/project/config/rbac/rbac_role.yaml | 163 ---------- .../config/rbac/rbac_role_binding.yaml | 13 - .../samples/creatures_v2alpha1_kraken.yaml | 9 - .../config/samples/crew_v1_firstmate.yaml | 9 - .../policy_v1beta1_healthcheckpolicy.yaml | 9 - .../config/samples/ship_v1beta1_frigate.yaml | 9 - .../src/project/hack/boilerplate.go.txt | 15 - .../apis/addtoscheme_creatures_v2alpha1.go | 26 -- .../project/pkg/apis/addtoscheme_crew_v1.go | 26 -- .../pkg/apis/addtoscheme_policy_v1beta1.go | 26 -- .../pkg/apis/addtoscheme_ship_v1beta1.go | 26 -- testdata/gopath/src/project/pkg/apis/apis.go | 33 -- .../src/project/pkg/apis/creatures/group.go | 18 -- .../pkg/apis/creatures/v2alpha1/doc.go | 23 -- .../apis/creatures/v2alpha1/kraken_types.go | 64 ---- .../creatures/v2alpha1/kraken_types_test.go | 56 ---- .../pkg/apis/creatures/v2alpha1/register.go | 46 --- .../creatures/v2alpha1/v2alpha1_suite_test.go | 55 ---- .../v2alpha1/zz_generated.deepcopy.go | 117 ------- .../gopath/src/project/pkg/apis/crew/group.go | 18 -- .../src/project/pkg/apis/crew/v1/doc.go | 23 -- .../pkg/apis/crew/v1/firstmate_types.go | 62 ---- .../pkg/apis/crew/v1/firstmate_types_test.go | 58 ---- .../src/project/pkg/apis/crew/v1/register.go | 46 --- .../project/pkg/apis/crew/v1/v1_suite_test.go | 55 ---- .../pkg/apis/crew/v1/zz_generated.deepcopy.go | 117 ------- .../src/project/pkg/apis/policy/group.go | 18 -- .../project/pkg/apis/policy/v1beta1/doc.go | 23 -- .../policy/v1beta1/healthcheckpolicy_types.go | 64 ---- .../v1beta1/healthcheckpolicy_types_test.go | 56 ---- .../pkg/apis/policy/v1beta1/register.go | 46 --- .../apis/policy/v1beta1/v1beta1_suite_test.go | 55 ---- .../policy/v1beta1/zz_generated.deepcopy.go | 117 ------- .../gopath/src/project/pkg/apis/ship/group.go | 18 -- .../src/project/pkg/apis/ship/v1beta1/doc.go | 23 -- .../pkg/apis/ship/v1beta1/frigate_types.go | 62 ---- .../apis/ship/v1beta1/frigate_types_test.go | 58 ---- .../project/pkg/apis/ship/v1beta1/register.go | 46 --- .../apis/ship/v1beta1/v1beta1_suite_test.go | 55 ---- .../ship/v1beta1/zz_generated.deepcopy.go | 117 ------- .../project/pkg/controller/add_firstmate.go | 26 -- .../src/project/pkg/controller/add_frigate.go | 26 -- .../pkg/controller/add_healthcheckpolicy.go | 26 -- .../src/project/pkg/controller/add_kraken.go | 26 -- .../project/pkg/controller/add_namespace.go | 26 -- .../src/project/pkg/controller/controller.go | 34 -- .../firstmate/firstmate_controller.go | 168 ---------- .../firstmate_controller_suite_test.go | 76 ----- .../firstmate/firstmate_controller_test.go | 89 ------ .../controller/frigate/frigate_controller.go | 107 ------- .../frigate/frigate_controller_suite_test.go | 76 ----- .../frigate/frigate_controller_test.go | 73 ----- .../healthcheckpolicy_controller.go | 107 ------- ...healthcheckpolicy_controller_suite_test.go | 76 ----- .../healthcheckpolicy_controller_test.go | 73 ----- .../controller/kraken/kraken_controller.go | 107 ------- .../kraken/kraken_controller_suite_test.go | 76 ----- .../kraken/kraken_controller_test.go | 73 ----- .../namespace/namespace_controller.go | 106 ------- .../namespace_controller_suite_test.go | 76 ----- .../namespace/namespace_controller_test.go | 72 ----- .../project/pkg/webhook/add_default_server.go | 26 -- .../default_server/add_mutating_firstmate.go | 48 --- .../default_server/add_mutating_namespace.go | 48 --- .../default_server/add_validating_frigate.go | 48 --- .../default_server/add_validating_kraken.go | 48 --- .../mutating/create_update_webhook.go | 36 --- .../firstmate/mutating/delete_webhook.go | 36 --- .../firstmate_create_update_handler.go | 88 ------ .../mutating/firstmate_delete_handler.go | 88 ------ .../firstmate/mutating/webhooks.go | 29 -- .../validating/frigate_update_handler.go | 87 ------ .../frigate/validating/update_webhook.go | 36 --- .../frigate/validating/webhooks.go | 29 -- .../kraken/validating/create_webhook.go | 36 --- .../validating/kraken_create_handler.go | 87 ------ .../kraken/validating/webhooks.go | 29 -- .../mutating/namespace_update_handler.go | 87 ------ .../namespace/mutating/update_webhook.go | 35 --- .../namespace/mutating/webhooks.go | 29 -- .../pkg/webhook/default_server/server.go | 91 ------ .../gopath/src/project/pkg/webhook/webhook.go | 37 --- .../apis/crew/v1/zz_generated.deepcopy.go | 114 ------- .../foo.policy/v1/zz_generated.deepcopy.go | 114 ------- .../v1beta1/zz_generated.deepcopy.go | 114 ------- .../v1beta2/zz_generated.deepcopy.go | 114 ------- .../apis/ship/v1/zz_generated.deepcopy.go | 114 ------- .../ship/v1beta1/zz_generated.deepcopy.go | 114 ------- .../ship/v2alpha1/zz_generated.deepcopy.go | 114 ------- .../bases/crew.testproject.org_captains.yaml | 56 ---- ...y.testproject.org_healthcheckpolicies.yaml | 56 ---- ...sea-creatures.testproject.org_krakens.yaml | 56 ---- ...-creatures.testproject.org_leviathans.yaml | 56 ---- .../bases/ship.testproject.org_cruisers.yaml | 56 ---- .../ship.testproject.org_destroyers.yaml | 56 ---- .../bases/ship.testproject.org_frigates.yaml | 56 ---- .../config/rbac/role.yaml | 148 --------- .../config/webhook/manifests.yaml | 52 ---- testdata/project-v2-multigroup/go.mod | 3 - .../api/v1/zz_generated.deepcopy.go | 292 ------------------ .../bases/crew.testproject.org_admirals.yaml | 56 ---- .../bases/crew.testproject.org_captains.yaml | 56 ---- .../crew.testproject.org_firstmates.yaml | 56 ---- testdata/project-v2/config/rbac/role.yaml | 68 ---- .../project-v2/config/webhook/manifests.yaml | 52 ---- testdata/project-v2/go.mod | 3 - 175 files changed, 79 insertions(+), 10337 deletions(-) delete mode 100755 generate_vendor.sh delete mode 100644 pkg/scaffold/v1/authproxyservice.go delete mode 100644 pkg/scaffold/v1/controller/add.go delete mode 100644 pkg/scaffold/v1/controller/controller.go delete mode 100644 pkg/scaffold/v1/controller/controllersuitetest.go delete mode 100644 pkg/scaffold/v1/controller/controllertest.go delete mode 100644 pkg/scaffold/v1/crd/addtoscheme.go delete mode 100644 pkg/scaffold/v1/crd/crd_sample.go delete mode 100644 pkg/scaffold/v1/crd/doc.go delete mode 100644 pkg/scaffold/v1/crd/group.go delete mode 100644 pkg/scaffold/v1/crd/register.go delete mode 100644 pkg/scaffold/v1/crd/types.go delete mode 100644 pkg/scaffold/v1/crd/typestest.go delete mode 100644 pkg/scaffold/v1/crd/version_suitetest.go delete mode 100644 pkg/scaffold/v1/kustomize_image_patch.go delete mode 100644 pkg/scaffold/v1/manager/apis.go delete mode 100644 pkg/scaffold/v1/manager/cmd.go delete mode 100644 pkg/scaffold/v1/manager/config.go delete mode 100644 pkg/scaffold/v1/manager/controller.go delete mode 100644 pkg/scaffold/v1/manager/dockerfile.go delete mode 100644 pkg/scaffold/v1/manager/webhook.go delete mode 100644 pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go delete mode 100644 pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go delete mode 100644 pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go delete mode 100644 pkg/scaffold/v1/webhook/add_server.go delete mode 100644 pkg/scaffold/v1/webhook/admissionbuilder.go delete mode 100644 pkg/scaffold/v1/webhook/admissionhandler.go delete mode 100644 pkg/scaffold/v1/webhook/admissionwebhooks.go delete mode 100644 pkg/scaffold/v1/webhook/config.go delete mode 100644 pkg/scaffold/v1/webhook/server.go delete mode 100644 pkg/scaffold/v1/webhook/util.go delete mode 100755 scripts/generate_dep_manifest.sh delete mode 100644 test/e2e/v1/e2e_suite.go delete mode 100644 test/e2e/v1/e2e_test.go delete mode 100644 testdata/gopath/src/project/.gitignore delete mode 100644 testdata/gopath/src/project/Dockerfile delete mode 100644 testdata/gopath/src/project/Gopkg.toml delete mode 100644 testdata/gopath/src/project/Makefile delete mode 100644 testdata/gopath/src/project/PROJECT delete mode 100644 testdata/gopath/src/project/cmd/manager/main.go delete mode 100644 testdata/gopath/src/project/config/crds/creatures_v2alpha1_kraken.yaml delete mode 100644 testdata/gopath/src/project/config/crds/crew_v1_firstmate.yaml delete mode 100644 testdata/gopath/src/project/config/crds/policy_v1beta1_healthcheckpolicy.yaml delete mode 100644 testdata/gopath/src/project/config/crds/ship_v1beta1_frigate.yaml delete mode 100644 testdata/gopath/src/project/config/default/kustomization.yaml delete mode 100644 testdata/gopath/src/project/config/default/manager_auth_proxy_patch.yaml delete mode 100644 testdata/gopath/src/project/config/default/manager_image_patch.yaml delete mode 100644 testdata/gopath/src/project/config/default/manager_prometheus_metrics_patch.yaml delete mode 100644 testdata/gopath/src/project/config/manager/kustomization.yaml delete mode 100644 testdata/gopath/src/project/config/manager/manager.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/auth_proxy_role.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/auth_proxy_role_binding.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/auth_proxy_service.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/kustomization.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/rbac_role.yaml delete mode 100644 testdata/gopath/src/project/config/rbac/rbac_role_binding.yaml delete mode 100644 testdata/gopath/src/project/config/samples/creatures_v2alpha1_kraken.yaml delete mode 100644 testdata/gopath/src/project/config/samples/crew_v1_firstmate.yaml delete mode 100644 testdata/gopath/src/project/config/samples/policy_v1beta1_healthcheckpolicy.yaml delete mode 100644 testdata/gopath/src/project/config/samples/ship_v1beta1_frigate.yaml delete mode 100644 testdata/gopath/src/project/hack/boilerplate.go.txt delete mode 100644 testdata/gopath/src/project/pkg/apis/addtoscheme_creatures_v2alpha1.go delete mode 100644 testdata/gopath/src/project/pkg/apis/addtoscheme_crew_v1.go delete mode 100644 testdata/gopath/src/project/pkg/apis/addtoscheme_policy_v1beta1.go delete mode 100644 testdata/gopath/src/project/pkg/apis/addtoscheme_ship_v1beta1.go delete mode 100644 testdata/gopath/src/project/pkg/apis/apis.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/group.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/doc.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/register.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/v2alpha1_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/zz_generated.deepcopy.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/group.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/doc.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/register.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/v1_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/crew/v1/zz_generated.deepcopy.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/group.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/doc.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/register.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/v1beta1_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/policy/v1beta1/zz_generated.deepcopy.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/group.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/doc.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/register.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/v1beta1_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/apis/ship/v1beta1/zz_generated.deepcopy.go delete mode 100644 testdata/gopath/src/project/pkg/controller/add_firstmate.go delete mode 100644 testdata/gopath/src/project/pkg/controller/add_frigate.go delete mode 100644 testdata/gopath/src/project/pkg/controller/add_healthcheckpolicy.go delete mode 100644 testdata/gopath/src/project/pkg/controller/add_kraken.go delete mode 100644 testdata/gopath/src/project/pkg/controller/add_namespace.go delete mode 100644 testdata/gopath/src/project/pkg/controller/controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/namespace/namespace_controller.go delete mode 100644 testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_suite_test.go delete mode 100644 testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_test.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/add_default_server.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_firstmate.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_namespace.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/add_validating_frigate.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/add_validating_kraken.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/create_update_webhook.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/delete_webhook.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_create_update_handler.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_delete_handler.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/webhooks.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/update_webhook.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/webhooks.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/create_webhook.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/kraken_create_handler.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/webhooks.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/namespace_update_handler.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/update_webhook.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/webhooks.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/default_server/server.go delete mode 100644 testdata/gopath/src/project/pkg/webhook/webhook.go delete mode 100644 testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/crew.testproject.org_captains.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml delete mode 100644 testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml delete mode 100644 testdata/project-v2-multigroup/config/rbac/role.yaml delete mode 100644 testdata/project-v2-multigroup/config/webhook/manifests.yaml delete mode 100644 testdata/project-v2/api/v1/zz_generated.deepcopy.go delete mode 100644 testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml delete mode 100644 testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml delete mode 100644 testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml delete mode 100644 testdata/project-v2/config/rbac/role.yaml delete mode 100644 testdata/project-v2/config/webhook/manifests.yaml diff --git a/.travis.yml b/.travis.yml index 489c94a3d68..7bb6c728b6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,8 +24,6 @@ go_import_path: sigs.k8s.io/kubebuilder services: docker # Install must be set to prevent default `go get` to run. -# The dependencies have already been vendored by `dep` so -# we don't need to fetch them. install: skip before_script: PATH=$PATH:$(pwd) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e5ea7ee6e02..732b66c3ece 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,11 +8,10 @@ Please see https://git.k8s.io/community/CLA.md for more info. ## Prerequisites - [go](https://golang.org/dl/) version v1.13+. -- [dep](https://github.com/golang/dep) dep v0.5+ - [docker](https://docs.docker.com/install/) version 17.03+. -- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) version v1.11.3+. +- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) version v1.14.1+. - [kustomize](https://sigs.k8s.io/kustomize/docs/INSTALL.md) v3.1.0+ -- Access to a Kubernetes v1.11.3+ cluster. +- Access to a Kubernetes v1.14.1+ cluster. ## Contributing steps 1. Submit an issue describing your proposed change to the repo in question. diff --git a/Makefile b/Makefile index 2db47ae1f5c..4d0a8ca5a64 100644 --- a/Makefile +++ b/Makefile @@ -53,10 +53,6 @@ generate: ## Update/generate all mock data. You should run this commands to upda generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder GO111MODULE=on ./generate_golden.sh -.PHONY: generate-vendor -generate-vendor: ## (Deprecated) Update/generate the vendor by using the path $GOPATH/src/sigs.k8s.io/kubebuilder-test - GO111MODULE=off ./generate_vendor.sh - .PHONY: generate-setup generate-setup: ## Current workarround to generate the testdata with the correct controller-gen version - rm -rf $(CONTROLLER_GEN_BIN_PATH) diff --git a/cmd/init.go b/cmd/init.go index 089b3d3cd34..00c25e85969 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -17,18 +17,14 @@ limitations under the License. package main import ( - "bufio" "errors" "fmt" "log" "os" - "os/exec" "path/filepath" "strings" "github.com/spf13/cobra" - flag "github.com/spf13/pflag" - "sigs.k8s.io/kubebuilder/cmd/internal" "sigs.k8s.io/kubebuilder/internal/config" "sigs.k8s.io/kubebuilder/pkg/scaffold" @@ -48,7 +44,7 @@ func newInitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "init", Short: "Initialize a new project", - Long: `Initialize a new project including vendor/ directory and Go package directories. + Long: `Initialize a new project including Go package directories. Writes the following files: - a boilerplate license file @@ -59,8 +55,6 @@ Writes the following files: - a Patch file for customizing image for manager manifests - a Patch file for enabling prometheus metrics - a cmd/manager/main.go to run - -project will prompt the user to run 'dep ensure' after writing the project files. `, Example: `# Scaffold a project using the apache2 license with "The Kubernetes authors" as owners kubebuilder init --domain example.org --license apache2 --owner "The Kubernetes authors" @@ -86,11 +80,6 @@ type initOptions struct { license string owner string - // deprecated flags - depFlag *flag.Flag - depArgs []string - dep bool - // flags fetchDeps bool skipGoVersionCheck bool @@ -103,18 +92,6 @@ func (o *initOptions) bindFlags(cmd *cobra.Command) { // dependency args cmd.Flags().BoolVar(&o.fetchDeps, "fetch-deps", true, "ensure dependencies are downloaded") - // deprecated dependency args - cmd.Flags().BoolVar(&o.dep, "dep", true, "if specified, determines whether dep will be used.") - o.depFlag = cmd.Flag("dep") - cmd.Flags().StringArrayVar(&o.depArgs, "depArgs", nil, "additional arguments for dep") - - if err := cmd.Flags().MarkDeprecated("dep", "use the fetch-deps flag instead"); err != nil { - log.Printf("error to mark dep flag as deprecated: %v", err) - } - if err := cmd.Flags().MarkDeprecated("depArgs", "will be removed with version 1 scaffolding"); err != nil { - log.Printf("error to mark dep flag as deprecated: %v", err) - } - // boilerplate args cmd.Flags().StringVar(&o.license, "license", "apache2", "license to use to boilerplate, may be one of 'apache2', 'none'") @@ -164,18 +141,6 @@ func (o *initOptions) validate(c *config.Config) error { c.Repo = repoPath } - // v1 only checks - if c.IsV1() { - // v1 is deprecated - internal.PrintV1DeprecationWarning() - - // Verify dep is installed - if _, err := exec.LookPath("dep"); err != nil { - return fmt.Errorf("dep is not installed: %v\n"+ - "Follow steps at: https://golang.github.io/dep/docs/installation.html", err) - } - } - return nil } @@ -186,20 +151,8 @@ func (o *initOptions) scaffolder(c *config.Config) (scaffold.Scaffolder, error) func (o *initOptions) postScaffold(c *config.Config) error { switch { case c.IsV1(): - if !o.depFlag.Changed { - reader := bufio.NewReader(os.Stdin) - fmt.Println("Run `dep ensure` to fetch dependencies (Recommended) [y/n]?") - o.dep = internal.YesNo(reader) - } - if !o.dep { - fmt.Println("Skipping fetching dependencies.") - return nil - } - - err := internal.RunCmd("Fetching dependencies", "dep", append([]string{"ensure"}, o.depArgs...)...) - if err != nil { - return err - } + return fmt.Errorf("The v1 projects are deprecated since Feb 1, 2020.\n" + + "See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") case c.IsV2(): // Ensure that we are pinning controller-runtime version diff --git a/cmd/internal/config.go b/cmd/internal/config.go index c2249b955b8..6f18b824fc6 100644 --- a/cmd/internal/config.go +++ b/cmd/internal/config.go @@ -17,20 +17,15 @@ limitations under the License. package internal import ( - "fmt" "log" "os" "sigs.k8s.io/kubebuilder/internal/config" ) -const ( - noticeColor = "\033[1;36m%s\033[0m" -) - -// ConfiguredAndV1 returns true if the project is already configured and it is v1 -func ConfiguredAndV1() bool { - projectConfig, err := config.Read() +// IsConfigured returns true if the project is already configured +func IsConfigured() bool { + _, err := config.Read() if os.IsNotExist(err) { return false @@ -40,10 +35,20 @@ func ConfiguredAndV1() bool { log.Fatalf("failed to read the configuration file: %v", err) } - return projectConfig.IsV1() + return true } -func PrintV1DeprecationWarning() { - fmt.Printf(noticeColor, "[Deprecation Notice] The v1 projects are deprecated and will not be supported beyond "+ - "Feb 1, 2020.\nSee how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") -} +// IsSupportable returns true if the project is already configured and it is v2 +func IsSupportable() bool { + projectConfig, err := config.Read() + + if os.IsNotExist(err) { + return false + } + + if err != nil { + log.Fatalf("failed to read the configuration file: %v", err) + } + + return projectConfig.IsV2() +} \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index f90a75ea848..ba2b539047b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "fmt" "log" "github.com/spf13/cobra" @@ -27,6 +28,11 @@ import ( "sigs.k8s.io/kubebuilder/pkg/scaffold" ) +// Just to show with colours that the V1 is no longer supported +const ( + noticeColor = "\033[1;36m%s\033[0m" +) + // commandOptions represent the types used to implement the different commands type commandOptions interface { // bindFlags binds the command flags to the fields in the options struct @@ -78,19 +84,22 @@ func run(options commandOptions) error { } func buildCmdTree() *cobra.Command { - if internal.ConfiguredAndV1() { - internal.PrintV1DeprecationWarning() + if internal.IsConfigured() && !internal.IsSupportable() { + fmt.Printf(noticeColor, "The v1 projects are deprecated since Feb 1, 2020.\n"+ + "See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") } // kubebuilder rootCmd := newRootCmd() + // kubebuilder update (v1 only) + if !internal.IsSupportable() { + rootCmd.AddCommand(newUpdateCmd()) + } + // kubebuilder alpha alphaCmd := newAlphaCmd() - // kubebuilder alpha webhook (v1 only) - if internal.ConfiguredAndV1() { - alphaCmd.AddCommand(newWebhookCmd()) - } + // Only add alpha group if it has subcommands if alphaCmd.HasSubCommands() { rootCmd.AddCommand(alphaCmd) @@ -100,10 +109,8 @@ func buildCmdTree() *cobra.Command { createCmd := newCreateCmd() // kubebuilder create api createCmd.AddCommand(newAPICmd()) - // kubebuilder create webhook (v2 only) - if !internal.ConfiguredAndV1() { - createCmd.AddCommand(newWebhookV2Cmd()) - } + createCmd.AddCommand(newWebhookV2Cmd()) + // Only add create group if it has subcommands if createCmd.HasSubCommands() { rootCmd.AddCommand(createCmd) @@ -115,11 +122,6 @@ func buildCmdTree() *cobra.Command { // kubebuilder init rootCmd.AddCommand(newInitCmd()) - // kubebuilder update (v1 only) - if internal.ConfiguredAndV1() { - rootCmd.AddCommand(newUpdateCmd()) - } - // kubebuilder version rootCmd.AddCommand(version.NewVersionCmd()) diff --git a/cmd/webhook.go b/cmd/webhook.go index 8e136e78a19..cfc5ecb182f 100644 --- a/cmd/webhook.go +++ b/cmd/webhook.go @@ -26,7 +26,6 @@ import ( "github.com/spf13/cobra" - "sigs.k8s.io/kubebuilder/cmd/internal" "sigs.k8s.io/kubebuilder/internal/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold" @@ -40,110 +39,6 @@ func (e webhookError) Error() string { return fmt.Sprintf("failed to create webhook: %v", e.err) } -func newWebhookCmd() *cobra.Command { - options := &webhookV1Options{} - - cmd := &cobra.Command{ - Use: "webhook", - Short: "Scaffold a webhook server", - Long: `Scaffold a webhook server if there is no existing server. -Scaffolds webhook handlers based on group, version, kind and other user inputs. -This command is only available for v1 scaffolding project. -`, - Example: ` # Create webhook for CRD of group crew, version v1 and kind FirstMate. - # Set type to be mutating and operations to be create and update. - kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update -`, - Run: func(_ *cobra.Command, _ []string) { - if err := run(options); err != nil { - log.Fatal(webhookError{err}) - } - }, - } - - options.bindFlags(cmd) - - return cmd -} - -var _ commandOptions = &webhookV1Options{} - -type webhookV1Options struct { - resource *resource.Options - server string - webhookType string - operations []string - doMake bool -} - -func (o *webhookV1Options) bindFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.server, "server", "default", "name of the server") - cmd.Flags().StringVar(&o.webhookType, "type", "", "webhook type, e.g. mutating or validating") - cmd.Flags().StringSliceVar(&o.operations, "operations", []string{"create"}, - "the operations that the webhook will intercept, e.g. create, update, delete and connect") - - cmd.Flags().BoolVar(&o.doMake, "make", true, "if true, run make after generating files") - - o.resource = &resource.Options{} - cmd.Flags().StringVar(&o.resource.Group, "group", "", "resource Group") - cmd.Flags().StringVar(&o.resource.Version, "version", "", "resource Version") - cmd.Flags().StringVar(&o.resource.Kind, "kind", "", "resource Kind") - cmd.Flags().StringVar(&o.resource.Plural, "resource", "", "resource Resource") -} - -func (o *webhookV1Options) loadConfig() (*config.Config, error) { - projectConfig, err := config.Load() - if os.IsNotExist(err) { - return nil, errors.New("unable to find configuration file, project must be initialized") - } - - return projectConfig, err -} - -func (o *webhookV1Options) validate(c *config.Config) error { - if !c.IsV1() { - return fmt.Errorf("webhook scaffolding is no longer alpha for version %s", c.Version) - } - - if err := o.resource.Validate(); err != nil { - return err - } - - return nil -} - -func (o *webhookV1Options) scaffolder(c *config.Config) (scaffold.Scaffolder, error) { - // Load the boilerplate - bp, err := ioutil.ReadFile(filepath.Join("hack", "boilerplate.go.txt")) // nolint:gosec - if err != nil { - return nil, fmt.Errorf("unable to load boilerplate: %v", err) - } - - // Create the actual resource from the resource options - var res *resource.Resource - switch { - case c.IsV1(): - res = o.resource.NewV1Resource(&c.Config, false) - case c.IsV2(): - res = o.resource.NewResource(&c.Config, false) - default: - return nil, fmt.Errorf("unknown project version %v", c.Version) - } - - return scaffold.NewV1WebhookScaffolder(&c.Config, string(bp), res, o.server, o.webhookType, o.operations), nil -} - -func (o *webhookV1Options) postScaffold(_ *config.Config) error { - if o.doMake { - err := internal.RunCmd("Running make", "make") - if err != nil { - return err - } - } - - return nil -} - func newWebhookV2Cmd() *cobra.Command { options := &webhookV2Options{} diff --git a/common.sh b/common.sh index 51d5a81d09e..03ec11f9457 100644 --- a/common.sh +++ b/common.sh @@ -155,33 +155,6 @@ function build_kb { GO111MODULE=on go build $opts -o $tmp_root/kubebuilder/bin/kubebuilder ./cmd } -# Required to install the go dep in the https://prow.k8s.io/. -function install_dep_by_git { - header_text "Checking for dep" - export PATH=$(go env GOPATH)/src/github.com/golang/dep/bin:$PATH - if ! is_installed dep ; then - header_text "Installing dep" - DEP_DIR=$(go env GOPATH)/src/github.com/golang/dep - mkdir -p $DEP_DIR - pushd $DEP_DIR - git clone https://github.com/golang/dep.git . - DEP_LATEST=$(git describe --abbrev=0 --tags) - git checkout $DEP_LATEST - mkdir bin - GO111MODULE=off go build -ldflags="-X main.version=$DEP_LATEST" -o bin/dep ./cmd/dep - popd - fi -} - -function install_go_dep { - header_text "Checking for dep" - export PATH=$(go env GOPATH)/src/github.com/golang/dep/bin:$PATH - if ! is_installed dep ; then - header_text "Installing dep" - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - fi -} - function install_kind { header_text "Checking for kind" if ! is_installed kind ; then @@ -219,27 +192,6 @@ function setup_envs { export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" } -# download_vendor_archive downloads vendor tarball for v1 projects. It skips the -# download if tarball exists. -function download_vendor_archive { - archive_name="vendor.v1.tgz" - archive_download_url="https://storage.googleapis.com/kubebuilder-vendor/$archive_name" - archive_path="$tmp_root/$archive_name" - header_text "checking the path $archive_path to download the $archive_name" - if [ -f $archive_path ]; then - header_text "removing file which exists" - rm $archive_path - fi - header_text "downloading vendor archive from $archive_download_url" - curl -sL ${archive_download_url} -o "$archive_path" -} - -function restore_go_deps { - header_text "restoring Go dependencies" - download_vendor_archive - tar -zxf $tmp_root/vendor.v1.tgz -} - function cache_project { header_text "caching initialized projects" if [ -d "$TEST_DEP" ]; then @@ -253,6 +205,5 @@ function dump_project { header_text "restoring cached project" if [ -d "$TEST_DEP" ]; then cp -r $TEST_DEP/* . - restore_go_deps fi } diff --git a/generate_golden.sh b/generate_golden.sh index 48b8091137a..e9208962c05 100755 --- a/generate_golden.sh +++ b/generate_golden.sh @@ -37,69 +37,45 @@ scaffold_test_project() { cd testdata/$project kb=$testdata_dir/../bin/kubebuilder oldgopath=$GOPATH - if [ $version == "1" ]; then - export GO111MODULE=off - export GOPATH=$(pwd)/../.. # go ignores vendor under testdata, so fake out a gopath - # untar Gopkg.lock and vendor directory for appropriate project version - download_vendor_archive - tar -zxf $tmp_root/vendor.v$version.tgz + if [ $project == "project-v2" ]; then + header_text 'Generating project-v2' + export GO111MODULE=on + export PATH=$PATH:$(go env GOPATH)/bin + go mod init sigs.k8s.io/kubebuilder/testdata/project-v2 # our repo autodetection will traverse up to the kb module if we don't do this - $kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false - $kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false - $kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update --make=false - $kb alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete --make=false - $kb create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false - $kb alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update --make=false - $kb create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false - $kb alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create --make=false - $kb create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false --make=false - $kb alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update --make=false - $kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false - elif [ $version == "2" ]; then - header_text 'Starting to generate projects with version 2' - if [ $project == "project-v2" ]; then - header_text 'Generating project-v2' - export GO111MODULE=on - export PATH=$PATH:$(go env GOPATH)/bin - go mod init sigs.k8s.io/kubebuilder/testdata/project-v2 # our repo autodetection will traverse up to the kb module if we don't do this - - header_text 'initializing project-v2 ...' - $kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" + header_text 'initializing project-v2 ...' + $kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" - header_text 'Creating APIs ...' - $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false - $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 --controller=true --resource=true --namespaced=false --make=false - elif [ $project == "project-v2-multigroup" ]; then - header_text 'Generating project-v2-multigroup' - export GO111MODULE=on - export PATH=$PATH:$(go env GOPATH)/bin - go mod init sigs.k8s.io/kubebuilder/testdata/project-v2-multigroup # our repo autodetection will traverse up to the kb module if we don't do this + header_text 'Creating APIs ...' + $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false + $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 --controller=true --resource=true --namespaced=false --make=false + elif [ $project == "project-v2-multigroup" ]; then + header_text 'Generating project-v2-multigroup' + export GO111MODULE=on + export PATH=$PATH:$(go env GOPATH)/bin + go mod init sigs.k8s.io/kubebuilder/testdata/project-v2-multigroup # our repo autodetection will traverse up to the kb module if we don't do this - header_text 'initializing project-v2-multigroup ...' - $kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" + header_text 'initializing project-v2-multigroup ...' + $kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" - header_text 'Switching to multigroup layout ...' - $kb edit --multigroup=true + header_text 'Switching to multigroup layout ...' + $kb edit --multigroup=true - header_text 'Creating APIs ...' - $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false - $kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation - $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 api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false - $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 - fi + header_text 'Creating APIs ...' + $kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --make=false + $kb create webhook --group crew --version v1 --kind Captain --defaulting --programmatic-validation + $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 api --group ship --version v2alpha1 --kind Cruiser --controller=true --resource=true --namespaced=false --make=false + $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 fi - make all test # v2 doesn't test by default - rm -f Gopkg.lock rm -f go.sum - rm -rf ./vendor rm -rf ./bin export GOPATH=$oldgopath popd @@ -108,6 +84,5 @@ scaffold_test_project() { set -e build_kb -scaffold_test_project gopath/src/project 1 scaffold_test_project project-v2 2 scaffold_test_project project-v2-multigroup 2 diff --git a/generate_vendor.sh b/generate_vendor.sh deleted file mode 100755 index 2b1d125a152..00000000000 --- a/generate_vendor.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -# Script to generate vendor archive that contains vendor and Gopkg.toml for a -# given project version -# -set -e - -go_workspace='' -for p in ${GOPATH//:/ }; do - if [[ $PWD/ = $p/* ]]; then - go_workspace=$p - fi -done - -if [ -z $go_workspace ]; then - echo 'Current directory is not in $GOPATH' >&2 - exit 1 -fi - -build_kb() { - rm -f /tmp/kb && \ - GO111MODULE=on go build -o /tmp/kb sigs.k8s.io/kubebuilder/cmd -} - - -# -# generate_vendor takes project version as input and creates vendor archive -# containing Go dependencies for a Kubebuilder project along with the Gopkg.lock -# file. -# -generate_vendor() { - version=$1 - project_dir=${go_workspace}/src/sigs.k8s.io/kubebuilder-test - mkdir -p ${project_dir} - rm -rf ${project_dir}/* - pushd . - cd ${project_dir} - /tmp/kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=true - make - tar -zcvf vendor.v$version.tgz vendor Gopkg.lock && \ - echo "vendor archieve vendor.v$version.tgz is ready." - popd -} - -build_kb && \ -generate_vendor 1 diff --git a/golden_test.sh b/golden_test.sh index b49e2eb81d4..ffe6f958587 100755 --- a/golden_test.sh +++ b/golden_test.sh @@ -23,7 +23,6 @@ export TRACE=1 export GO111MODULE=on fetch_tools -install_go_dep build_kb setup_envs diff --git a/pkg/scaffold/api.go b/pkg/scaffold/api.go index f404ef422e5..1ecad0e616c 100644 --- a/pkg/scaffold/api.go +++ b/pkg/scaffold/api.go @@ -25,8 +25,6 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - controllerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/controller" - crdv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/crd" scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" controllerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/controller" crdv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/crd" @@ -68,7 +66,8 @@ func (s *apiScaffolder) Scaffold() error { switch { case s.config.IsV1(): - return s.scaffoldV1() + return fmt.Errorf("The v1 projects are deprecated since Feb 1, 2020.\n" + + "See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") case s.config.IsV2(): return s.scaffoldV2() default: @@ -84,54 +83,6 @@ func (s *apiScaffolder) newUniverse() *model.Universe { ) } -func (s *apiScaffolder) scaffoldV1() error { - if s.doResource { - fmt.Println(filepath.Join("pkg", "apis", s.resource.GroupPackageName, s.resource.Version, - fmt.Sprintf("%s_types.go", strings.ToLower(s.resource.Kind)))) - fmt.Println(filepath.Join("pkg", "apis", s.resource.GroupPackageName, s.resource.Version, - fmt.Sprintf("%s_types_test.go", strings.ToLower(s.resource.Kind)))) - - if err := machinery.NewScaffold().Execute( - s.newUniverse(), - &crdv1.Register{Resource: s.resource}, - &crdv1.Types{Resource: s.resource}, - &crdv1.VersionSuiteTest{Resource: s.resource}, - &crdv1.TypesTest{Resource: s.resource}, - &crdv1.Doc{Resource: s.resource}, - &crdv1.Group{Resource: s.resource}, - &crdv1.AddToScheme{Resource: s.resource}, - &crdv1.CRDSample{Resource: s.resource}, - ); err != nil { - return fmt.Errorf("error scaffolding APIs: %v", err) - } - } else { - // disable generation of example reconcile body if not scaffolding resource - // because this could result in a fork-bomb of k8s resources where watching a - // deployment, replicaset etc. results in generating deployment which - // end up generating replicaset, pod etc recursively. - s.resource.CreateExampleReconcileBody = false - } - - if s.doController { - fmt.Println(filepath.Join("pkg", "controller", strings.ToLower(s.resource.Kind), - fmt.Sprintf("%s_controller.go", strings.ToLower(s.resource.Kind)))) - fmt.Println(filepath.Join("pkg", "controller", strings.ToLower(s.resource.Kind), - fmt.Sprintf("%s_controller_test.go", strings.ToLower(s.resource.Kind)))) - - if err := machinery.NewScaffold().Execute( - s.newUniverse(), - &controllerv1.Controller{Resource: s.resource}, - &controllerv1.AddController{Resource: s.resource}, - &controllerv1.Test{Resource: s.resource}, - &controllerv1.SuiteTest{Resource: s.resource}, - ); err != nil { - return fmt.Errorf("error scaffolding controller: %v", err) - } - } - - return nil -} - func (s *apiScaffolder) scaffoldV2() error { if s.doResource { // Only save the resource in the config file if it didn't exist diff --git a/pkg/scaffold/init.go b/pkg/scaffold/init.go index 14867b0966a..eb1d71b1ff3 100644 --- a/pkg/scaffold/init.go +++ b/pkg/scaffold/init.go @@ -26,9 +26,6 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/file" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" "sigs.k8s.io/kubebuilder/pkg/scaffold/project" - scaffoldv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1" - managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/manager" - metricsauthv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/metricsauth" scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" certmanagerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/certmanager" managerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/manager" @@ -105,7 +102,8 @@ func (s *initScaffolder) Scaffold() error { switch { case s.config.IsV1(): - return s.scaffoldV1() + return fmt.Errorf("The v1 projects are deprecated since Feb 1, 2020.\n" + + "See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") case s.config.IsV2(): return s.scaffoldV2() default: @@ -113,27 +111,6 @@ func (s *initScaffolder) Scaffold() error { } } -func (s *initScaffolder) scaffoldV1() error { - return machinery.NewScaffold().Execute( - s.newUniverse(), - &project.KustomizeRBAC{}, - &scaffoldv1.KustomizeImagePatch{}, - &metricsauthv1.KustomizePrometheusMetricsPatch{}, - &metricsauthv1.KustomizeAuthProxyPatch{}, - &scaffoldv1.AuthProxyService{}, - &managerv1.Config{Image: ImageName}, - &project.Makefile{Image: ImageName}, - &project.GopkgToml{}, - &managerv1.Dockerfile{}, - &project.Kustomize{}, - &project.KustomizeManager{}, - &managerv1.APIs{BoilerplatePath: s.boilerplatePath}, - &managerv1.Controller{}, - &managerv1.Webhook{}, - &managerv1.Cmd{}, - ) -} - func (s *initScaffolder) scaffoldV2() error { return machinery.NewScaffold().Execute( s.newUniverse(), diff --git a/pkg/scaffold/v1/authproxyservice.go b/pkg/scaffold/v1/authproxyservice.go deleted file mode 100644 index e5d3c86af4b..00000000000 --- a/pkg/scaffold/v1/authproxyservice.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &AuthProxyService{} - -// AuthProxyService scaffolds the config/rbac/auth_proxy_service.yaml file -type AuthProxyService struct { - file.Input -} - -// GetInput implements input.Template -func (f *AuthProxyService) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml") - } - f.TemplateBody = AuthProxyServiceTemplate - return f.Input, nil -} - -const AuthProxyServiceTemplate = `apiVersion: v1 -kind: Service -metadata: - annotations: - prometheus.io/port: "8443" - prometheus.io/scheme: https - prometheus.io/scrape: "true" - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - name: controller-manager-metrics-service - namespace: system -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" -` diff --git a/pkg/scaffold/v1/controller/add.go b/pkg/scaffold/v1/controller/add.go deleted file mode 100644 index 1e1f7885bf7..00000000000 --- a/pkg/scaffold/v1/controller/add.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AddController{} - -// AddController scaffolds adds a new Controller. -type AddController struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *AddController) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "controller", fmt.Sprintf( - "add_%s.go", strings.ToLower(f.Resource.Kind))) - } - f.TemplateBody = addControllerTemplate - return f.Input, nil -} - -const addControllerTemplate = `{{ .Boilerplate }} - -package controller - -import ( - "{{ .Repo }}/pkg/controller/{{ lower .Resource.Kind }}" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, {{ lower .Resource.Kind }}.Add) -} -` diff --git a/pkg/scaffold/v1/controller/controller.go b/pkg/scaffold/v1/controller/controller.go deleted file mode 100644 index 8b18a03feaa..00000000000 --- a/pkg/scaffold/v1/controller/controller.go +++ /dev/null @@ -1,220 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Controller{} - -// Controller scaffolds a Controller for a Resource -type Controller struct { - file.Input - - // Resource is the Resource to make the Controller for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Controller) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "controller", - strings.ToLower(f.Resource.Kind), - strings.ToLower(f.Resource.Kind)+"_controller.go") - } - f.TemplateBody = controllerTemplate - f.Input.IfExistsAction = file.Error - return f.Input, nil -} - -// nolint:lll -const controllerTemplate = `{{ .Boilerplate }} - -package {{ lower .Resource.Kind }} - -import ( -{{ if .Resource.CreateExampleReconcileBody }} "context" - "reflect" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/source" - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) - -var log = logf.Log.WithName("{{ lower .Resource.Kind }}-controller") -{{ else }} "context" - appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) -{{ end -}} - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new {{ .Resource.Kind }} Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &Reconcile{{ .Resource.Kind }}{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("{{ lower .Resource.Kind }}-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to {{ .Resource.Kind }} - err = c.Watch(&source.Kind{Type: &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by {{ .Resource.Kind }} - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &Reconcile{{ .Resource.Kind }}{} - -// Reconcile{{ .Resource.Kind }} reconciles a {{ .Resource.Kind }} object -type Reconcile{{ .Resource.Kind }} struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a {{ .Resource.Kind }} object and makes changes based on the state read -// and what is in the {{ .Resource.Kind }}.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -{{ if .Resource.CreateExampleReconcileBody -}} -// Automatically generate RBAC rules to allow the Controller to read and write Deployments -// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;update;patch -{{ end -}} -// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch -func (r *Reconcile{{ .Resource.Kind }}) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the {{ .Resource.Kind }} instance - instance := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - {{ if .Resource.CreateExampleReconcileBody -}} - // TODO(user): Change this to be the object type created by your controller - // Define the desired Deployment object - deploy := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: instance.Name + "-deployment", - Namespace: {{ if .Resource.Namespaced}}instance.Namespace{{ else }}"default"{{ end }}, - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"deployment": instance.Name + "-deployment"}, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"deployment": instance.Name + "-deployment"}}, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "nginx", - Image: "nginx", - }, - }, - }, - }, - }, - } - if err := controllerutil.SetControllerReference(instance, deploy, r.scheme); err != nil { - return reconcile.Result{}, err - } - - // TODO(user): Change this for the object type created by your controller - // Check if the Deployment already exists - found := &appsv1.Deployment{} - err = r.Get(context.TODO(), types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found) - if err != nil && errors.IsNotFound(err) { - log.Info("Creating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) - err = r.Create(context.TODO(), deploy) - return reconcile.Result{}, err - } else if err != nil { - return reconcile.Result{}, err - } - - // TODO(user): Change this for the object type created by your controller - // Update the found object and write the result back if there are any changes - if !reflect.DeepEqual(deploy.Spec, found.Spec) { - found.Spec = deploy.Spec - log.Info("Updating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) - err = r.Update(context.TODO(), found) - if err != nil { - return reconcile.Result{}, err - } - } - {{ end -}} - - return reconcile.Result{}, nil -} -` diff --git a/pkg/scaffold/v1/controller/controllersuitetest.go b/pkg/scaffold/v1/controller/controllersuitetest.go deleted file mode 100644 index 57d5b152875..00000000000 --- a/pkg/scaffold/v1/controller/controllersuitetest.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &SuiteTest{} - -// SuiteTest scaffolds a SuiteTest -type SuiteTest struct { - file.Input - - // Resource is the Resource to make the Controller for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *SuiteTest) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "controller", - strings.ToLower(f.Resource.Kind), strings.ToLower(f.Resource.Kind)+"_controller_suite_test.go") - } - f.TemplateBody = controllerSuiteTestTemplate - return f.Input, nil -} - -const controllerSuiteTestTemplate = `{{ .Boilerplate }} - -package {{ lower .Resource.Kind }} - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "{{ .Repo }}/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} -` diff --git a/pkg/scaffold/v1/controller/controllertest.go b/pkg/scaffold/v1/controller/controllertest.go deleted file mode 100644 index a675be8fbdf..00000000000 --- a/pkg/scaffold/v1/controller/controllertest.go +++ /dev/null @@ -1,125 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Test{} - -// Test scaffolds a Controller Test -type Test struct { - file.Input - - // Resource is the Resource to make the Controller for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Test) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "controller", - strings.ToLower(f.Resource.Kind), strings.ToLower(f.Resource.Kind)+"_controller_test.go") - } - - f.TemplateBody = controllerTestTemplate - f.Input.IfExistsAction = file.Error - return f.Input, nil -} - -// nolint:lll -const controllerTestTemplate = `{{ .Boilerplate }} - -package {{ lower .Resource.Kind }} - -import ( - "testing" - "time" - "github.com/onsi/gomega" - "golang.org/x/net/context" - {{ if .Resource.CreateExampleReconcileBody -}} - appsv1 "k8s.io/api/apps/v1" - {{ end -}} - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo"{{ if .Resource.Namespaced }}, Namespace: "default"{{end}}}} -{{ if .Resource.CreateExampleReconcileBody }}var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"} -{{ end }} -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{ObjectMeta: metav1.ObjectMeta{Name: "foo"{{ if .Resource.Namespaced }}, Namespace: "default"{{end}}}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the {{ .Resource.Kind }} object and expect the Reconcile{{ if .Resource.CreateExampleReconcileBody }} and Deployment to be created{{ end }} - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) -{{ if .Resource.CreateExampleReconcileBody }} - deploy := &appsv1.Deployment{} - g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout). - Should(gomega.Succeed()) - - // Delete the Deployment and expect Reconcile to be called for Deployment deletion - g.Expect(c.Delete(context.TODO(), deploy)).To(gomega.Succeed()) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout). - Should(gomega.Succeed()) - - // Manually delete Deployment since GC isn't enabled in the test control plane - g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout). - Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found")) -{{ end }} -} -` diff --git a/pkg/scaffold/v1/crd/addtoscheme.go b/pkg/scaffold/v1/crd/addtoscheme.go deleted file mode 100644 index aeaca4d219a..00000000000 --- a/pkg/scaffold/v1/crd/addtoscheme.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "fmt" - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AddToScheme{} - -// AddToScheme scaffolds the code to add the resource to a SchemeBuilder. -type AddToScheme struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *AddToScheme) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", fmt.Sprintf( - "addtoscheme_%s_%s.go", f.Resource.GroupPackageName, f.Resource.Version)) - } - f.TemplateBody = addResourceTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *AddToScheme) Validate() error { - return f.Resource.Validate() -} - -// NB(directxman12): we need that package alias on the API import otherwise imports.Process -// gets wicked (or hella, if you're feeling west-coasty) confused. - -const addResourceTemplate = `{{ .Boilerplate }} - -package apis - -import ( - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, {{ .Resource.ImportAlias }}.SchemeBuilder.AddToScheme) -} -` diff --git a/pkg/scaffold/v1/crd/crd_sample.go b/pkg/scaffold/v1/crd/crd_sample.go deleted file mode 100644 index 4f6f0951b2a..00000000000 --- a/pkg/scaffold/v1/crd/crd_sample.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &CRDSample{} - -// CRDSample scaffolds a manifest for CRD sample. -// nolint:golint -type CRDSample struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *CRDSample) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "samples", fmt.Sprintf( - "%s_%s_%s.yaml", f.Resource.GroupPackageName, f.Resource.Version, strings.ToLower(f.Resource.Kind))) - } - - f.IfExistsAction = file.Error - f.TemplateBody = crdSampleTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *CRDSample) Validate() error { - return f.Resource.Validate() -} - -const crdSampleTemplate = `apiVersion: {{ .Resource.Domain }}/{{ .Resource.Version }} -kind: {{ .Resource.Kind }} -metadata: - labels: - controller-tools.k8s.io: "1.0" - name: {{ lower .Resource.Kind }}-sample -spec: - # Add fields here - foo: bar -` diff --git a/pkg/scaffold/v1/crd/doc.go b/pkg/scaffold/v1/crd/doc.go deleted file mode 100644 index 53a4f2ca1ab..00000000000 --- a/pkg/scaffold/v1/crd/doc.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Doc{} - -// Doc scaffolds the pkg/apis/group/version/doc.go directory -type Doc struct { - file.Input - - // Resource is a resource for the API version - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Doc) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, f.Resource.Version, "doc.go") - } - f.TemplateBody = docGoTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *Doc) Validate() error { - return f.Resource.Validate() -} - -// nolint:lll -const docGoTemplate = `{{ .Boilerplate }} - -// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen={{ .Repo }}/pkg/apis/{{ .Resource.GroupPackageName }} -// +k8s:defaulter-gen=TypeMeta -// +groupName={{ .Resource.Domain }} -package {{ .Resource.Version }} -` diff --git a/pkg/scaffold/v1/crd/group.go b/pkg/scaffold/v1/crd/group.go deleted file mode 100644 index 0c533ef5536..00000000000 --- a/pkg/scaffold/v1/crd/group.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Group{} - -// Group scaffolds the pkg/apis/group/group.go -type Group struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Group) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, "group.go") - } - f.TemplateBody = groupTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *Group) Validate() error { - return f.Resource.Validate() -} - -const groupTemplate = `{{ .Boilerplate }} - -// Package {{ .Resource.GroupPackageName }} contains {{ .Resource.Group }} API versions -package {{ .Resource.GroupPackageName }} -` diff --git a/pkg/scaffold/v1/crd/register.go b/pkg/scaffold/v1/crd/register.go deleted file mode 100644 index 7c068871a54..00000000000 --- a/pkg/scaffold/v1/crd/register.go +++ /dev/null @@ -1,83 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Register{} - -// Register scaffolds the pkg/apis/group/version/register.go file -type Register struct { - file.Input - - // Resource is the resource to scaffold the types_test.go file for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Register) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, f.Resource.Version, "register.go") - } - f.TemplateBody = registerTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *Register) Validate() error { - return f.Resource.Validate() -} - -// nolint:lll -const registerTemplate = `{{ .Boilerplate }} - -// NOTE: Boilerplate only. Ignore this file. - -// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen={{ .Repo }}/pkg/apis/{{ .Resource.GroupPackageName }} -// +k8s:defaulter-gen=TypeMeta -// +groupName={{ .Resource.Domain }} -package {{ .Resource.Version }} - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "{{ .Resource.Domain }}", Version: "{{ .Resource.Version }}"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is required by pkg/client/... - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource is required by pkg/client/listers/... -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} -` diff --git a/pkg/scaffold/v1/crd/types.go b/pkg/scaffold/v1/crd/types.go deleted file mode 100644 index c642c103d1d..00000000000 --- a/pkg/scaffold/v1/crd/types.go +++ /dev/null @@ -1,108 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &Types{} - -// Types scaffolds the pkg/apis/group/version/kind_types.go file to define the schema for an API -type Types struct { - file.Input - - // Resource is the resource to scaffold the types_test.go file for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *Types) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, f.Resource.Version, - fmt.Sprintf("%s_types.go", strings.ToLower(f.Resource.Kind))) - } - f.TemplateBody = typesTemplate - f.IfExistsAction = file.Error - return f.Input, nil -} - -// Validate validates the values -func (f *Types) Validate() error { - return f.Resource.Validate() -} - -const typesTemplate = `{{ .Boilerplate }} - -package {{ .Resource.Version }} - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// {{ .Resource.Kind }}Spec defines the desired state of {{ .Resource.Kind }} -type {{ .Resource.Kind }}Spec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// {{ .Resource.Kind }}Status defines the observed state of {{ .Resource.Kind }} -type {{ .Resource.Kind }}Status struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -{{- if not .Resource.Namespaced }} -// +genclient:nonNamespaced -{{- end }} - -// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API -// +k8s:openapi-gen=true -type {{ .Resource.Kind }} struct { - metav1.TypeMeta ` + "`" + `json:",inline"` + "`" + ` - metav1.ObjectMeta ` + "`" + `json:"metadata,omitempty"` + "`" + ` - - Spec {{ .Resource.Kind }}Spec ` + "`" + `json:"spec,omitempty"` + "`" + ` - Status {{ .Resource.Kind }}Status ` + "`" + `json:"status,omitempty"` + "`" + ` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -{{- if not .Resource.Namespaced }} -// +genclient:nonNamespaced -{{- end }} - -// {{ .Resource.Kind }}List contains a list of {{ .Resource.Kind }} -type {{ .Resource.Kind }}List struct { - metav1.TypeMeta ` + "`" + `json:",inline"` + "`" + ` - metav1.ListMeta ` + "`" + `json:"metadata,omitempty"` + "`" + ` - Items []{{ .Resource.Kind }} ` + "`" + `json:"items"` + "`" + ` -} - -func init() { - SchemeBuilder.Register(&{{ .Resource.Kind }}{}, &{{ .Resource.Kind }}List{}) -} -` diff --git a/pkg/scaffold/v1/crd/typestest.go b/pkg/scaffold/v1/crd/typestest.go deleted file mode 100644 index fc69720acbd..00000000000 --- a/pkg/scaffold/v1/crd/typestest.go +++ /dev/null @@ -1,101 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &TypesTest{} - -// TypesTest scaffolds the pkg/apis/group/version/kind_types_test.go file to test the API schema -type TypesTest struct { - file.Input - - // Resource is the resource to scaffold the types_test.go file for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *TypesTest) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, f.Resource.Version, - fmt.Sprintf("%s_types_test.go", strings.ToLower(f.Resource.Kind))) - } - f.TemplateBody = typesTestTemplate - f.IfExistsAction = file.Error - return f.Input, nil -} - -// Validate validates the values -func (f *TypesTest) Validate() error { - return f.Resource.Validate() -} - -const typesTestTemplate = `{{ .Boilerplate }} - -package {{ .Resource.Version }} - -import ( - "testing" - "github.com/onsi/gomega" - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -func TestStorage{{ .Resource.Kind }}(t *testing.T) { - key := types.NamespacedName{ - Name: "foo", - {{ if .Resource.Namespaced -}} - Namespace: "default", - {{ end -}} - } - created := &{{ .Resource.Kind }}{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - {{ if .Resource.Namespaced -}} - Namespace: "default", - {{ end -}} - }} - g := gomega.NewGomegaWithT(t) - - // Test Create - fetched := &{{ .Resource.Kind }}{} - g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(created)) - - // Test Updating the Labels - updated := fetched.DeepCopy() - updated.Labels = map[string]string{"hello": "world"} - g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(updated)) - - // Test Delete - g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) - g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) -} -` diff --git a/pkg/scaffold/v1/crd/version_suitetest.go b/pkg/scaffold/v1/crd/version_suitetest.go deleted file mode 100644 index 417ca1479f9..00000000000 --- a/pkg/scaffold/v1/crd/version_suitetest.go +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - "fmt" - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &TypesTest{} - -// VersionSuiteTest scaffolds the version_suite_test.go file to setup the versions test -type VersionSuiteTest struct { - file.Input - - // Resource is the resource to scaffold the types_test.go file for - Resource *resource.Resource -} - -// GetInput implements input.Template -func (f *VersionSuiteTest) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", f.Resource.GroupPackageName, f.Resource.Version, - fmt.Sprintf("%s_suite_test.go", f.Resource.Version)) - } - f.TemplateBody = versionSuiteTestTemplate - return f.Input, nil -} - -// Validate validates the values -func (f *VersionSuiteTest) Validate() error { - return f.Resource.Validate() -} - -const versionSuiteTestTemplate = `{{ .Boilerplate }} - -package {{ .Resource.Version }} - -import ( - "log" - "os" - "path/filepath" - "testing" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -var cfg *rest.Config -var c client.Client - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - if err != nil { - log.Fatal(err) - } - - if cfg, err = t.Start(); err != nil { - log.Fatal(err) - } - - if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { - log.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} -` diff --git a/pkg/scaffold/v1/kustomize_image_patch.go b/pkg/scaffold/v1/kustomize_image_patch.go deleted file mode 100644 index 68626d5ca65..00000000000 --- a/pkg/scaffold/v1/kustomize_image_patch.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &KustomizeImagePatch{} - -// KustomizeImagePatch scaffolds the patch file for customizing image URL -// manifest file for manager resource. -type KustomizeImagePatch struct { - file.Input - - // ImageURL to use for controller image in manager's manifest. - ImageURL string -} - -// GetInput implements input.Template -func (f *KustomizeImagePatch) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "default", "manager_image_patch.yaml") - } - if f.ImageURL == "" { - f.ImageURL = "IMAGE_URL" - } - f.TemplateBody = kustomizeImagePatchTemplate - f.Input.IfExistsAction = file.Error - return f.Input, nil -} - -const kustomizeImagePatchTemplate = `apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - # Change the value of image field below to your controller image URL - - image: {{ .ImageURL }} - name: manager -` diff --git a/pkg/scaffold/v1/manager/apis.go b/pkg/scaffold/v1/manager/apis.go deleted file mode 100644 index 1dcef357af6..00000000000 --- a/pkg/scaffold/v1/manager/apis.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &APIs{} - -// APIs scaffolds a apis.go to register types with a Scheme -type APIs struct { - file.Input - // BoilerplatePath is the path to the boilerplate file - BoilerplatePath string - // Comments is a list of comments to add to the apis.go - Comments []string -} - -var deepCopy = strings.Join([]string{ - "//go:generate go run", - "../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go", - "-O zz_generated.deepcopy", - "-i ./..."}, " ") - -// GetInput implements input.Template -func (f *APIs) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "apis", "apis.go") - } - - relPath, err := filepath.Rel(filepath.Dir(f.Path), f.BoilerplatePath) - if err != nil { - return file.Input{}, err - } - if len(f.Comments) == 0 { - f.Comments = append(f.Comments, - "// Generate deepcopy for apis", fmt.Sprintf("%s -h %s", deepCopy, filepath.ToSlash(relPath))) - } - f.TemplateBody = apisTemplate - return f.Input, nil -} - -const apisTemplate = `{{ .Boilerplate }} - -{{ range $line := .Comments -}} -{{ $line }} -{{ end }} -// Package apis contains Kubernetes API groups. -package apis - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// AddToSchemes may be used to add all resources defined in the project to a Scheme -var AddToSchemes runtime.SchemeBuilder - -// AddToScheme adds all Resources to the Scheme -func AddToScheme(s *runtime.Scheme) error { - return AddToSchemes.AddToScheme(s) -} -` diff --git a/pkg/scaffold/v1/manager/cmd.go b/pkg/scaffold/v1/manager/cmd.go deleted file mode 100644 index 4a9a8985209..00000000000 --- a/pkg/scaffold/v1/manager/cmd.go +++ /dev/null @@ -1,110 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Cmd{} - -// Cmd scaffolds a manager.go to run Controllers -type Cmd struct { - file.Input -} - -// GetInput implements input.Template -func (f *Cmd) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("cmd", "manager", "main.go") - } - f.TemplateBody = cmdTemplate - return f.Input, nil -} - -const cmdTemplate = `{{ .Boilerplate }} - -package main - -import ( - "flag" - "os" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "sigs.k8s.io/controller-runtime/pkg/client/config" - "sigs.k8s.io/controller-runtime/pkg/manager" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/runtime/signals" - "{{ .Repo }}/pkg/apis" - "{{ .Repo }}/pkg/controller" - "{{ .Repo }}/pkg/webhook" -) - -func main() { - var metricsAddr string - flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") - flag.Parse() - logf.SetLogger(logf.ZapLogger(false)) - log := logf.Log.WithName("entrypoint") - - // Get a config to talk to the apiserver - log.Info("setting up client for manager") - cfg, err := config.GetConfig() - if err != nil { - log.Error(err, "unable to set up client config") - os.Exit(1) - } - - // Create a new Cmd to provide shared dependencies and start components - log.Info("setting up manager") - mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr}) - if err != nil { - log.Error(err, "unable to set up overall controller manager") - os.Exit(1) - } - - log.Info("Registering Components.") - - // Setup Scheme for all resources - log.Info("setting up scheme") - if err := apis.AddToScheme(mgr.GetScheme()); err != nil { - log.Error(err, "unable add APIs to scheme") - os.Exit(1) - } - - // Setup all Controllers - log.Info("Setting up controller") - if err := controller.AddToManager(mgr); err != nil { - log.Error(err, "unable to register controllers to the manager") - os.Exit(1) - } - - log.Info("setting up webhooks") - if err := webhook.AddToManager(mgr); err != nil { - log.Error(err, "unable to register webhooks to the manager") - os.Exit(1) - } - - // Start the Cmd - log.Info("Starting the Cmd.") - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - log.Error(err, "unable to run the manager") - os.Exit(1) - } -} -` diff --git a/pkg/scaffold/v1/manager/config.go b/pkg/scaffold/v1/manager/config.go deleted file mode 100644 index 968308a1213..00000000000 --- a/pkg/scaffold/v1/manager/config.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Config{} - -// Config scaffolds yaml config for the manager. -type Config struct { - file.Input - // Image is controller manager image name - Image string -} - -// GetInput implements input.Template -func (f *Config) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "manager", "manager.yaml") - } - f.TemplateBody = configTemplate - return f.Input, nil -} - -const configTemplate = `apiVersion: v1 -kind: Namespace -metadata: - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - name: system ---- -apiVersion: v1 -kind: Service -metadata: - name: controller-manager-service - namespace: system - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" -spec: - selector: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - ports: - - port: 443 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" -spec: - selector: - matchLabels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - serviceName: controller-manager-service - replicas: 1 - podManagementPolicy: Parallel - template: - metadata: - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - spec: - containers: - - command: - - /manager - image: {{ .Image }} - name: manager - env: - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: SECRET_NAME - value: $(WEBHOOK_SECRET_NAME) - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - ports: - - containerPort: 9876 - name: webhook-server - protocol: TCP - volumeMounts: - - mountPath: /tmp/cert - name: cert - readOnly: true - terminationGracePeriodSeconds: 10 - volumes: - - name: cert - secret: - defaultMode: 420 - secretName: webhook-server-secret ---- -apiVersion: v1 -kind: Secret -metadata: - name: webhook-server-secret - namespace: system -` diff --git a/pkg/scaffold/v1/manager/controller.go b/pkg/scaffold/v1/manager/controller.go deleted file mode 100644 index 4e125ebe74a..00000000000 --- a/pkg/scaffold/v1/manager/controller.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Controller{} - -// Controller scaffolds a controller.go to add Controllers to a manager.Cmd -type Controller struct { - file.Input -} - -// GetInput implements input.Template -func (f *Controller) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "controller", "controller.go") - } - f.TemplateBody = controllerTemplate - return f.Input, nil -} - -const controllerTemplate = `{{ .Boilerplate }} - -package controller - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -} -` diff --git a/pkg/scaffold/v1/manager/dockerfile.go b/pkg/scaffold/v1/manager/dockerfile.go deleted file mode 100644 index 88819b28607..00000000000 --- a/pkg/scaffold/v1/manager/dockerfile.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Dockerfile{} - -// Dockerfile scaffolds a Dockerfile for building a main -type Dockerfile struct { - file.Input -} - -// GetInput implements input.Template -func (f *Dockerfile) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = "Dockerfile" - } - f.TemplateBody = dockerfileTemplate - return f.Input, nil -} - -const dockerfileTemplate = `# Build the manager binary -FROM golang:1.10.3 as builder - -# Copy in the go src -WORKDIR /go/src/{{ .Repo }} -COPY cmd/ cmd/ -COPY vendor/ vendor/ -COPY pkg/ pkg/ - -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager {{ .Repo }}/cmd/manager - -# Copy the controller-manager into a thin image -FROM ubuntu:latest -WORKDIR / -COPY --from=builder /go/src/{{ .Repo }}/manager . -ENTRYPOINT ["/manager"] -` diff --git a/pkg/scaffold/v1/manager/webhook.go b/pkg/scaffold/v1/manager/webhook.go deleted file mode 100644 index b9a495c7db3..00000000000 --- a/pkg/scaffold/v1/manager/webhook.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package manager - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Webhook{} - -// Webhook scaffolds a webhook.go to add webhook server(s) to a manager.Cmd -type Webhook struct { - file.Input -} - -// GetInput implements input.Template -func (f *Webhook) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", "webhook.go") - } - f.TemplateBody = webhookTemplate - return f.Input, nil -} - -// nolint:lll -const webhookTemplate = `{{ .Boilerplate }} - -package webhook - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -} -` diff --git a/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go b/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go deleted file mode 100644 index 081767c57e3..00000000000 --- a/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package metricsauth - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &KustomizeAuthProxyPatch{} - -// KustomizeAuthProxyPatch scaffolds the patch file for enabling -// prometheus metrics for manager Pod. -type KustomizeAuthProxyPatch struct { - file.Input -} - -// GetInput implements input.Template -func (f *KustomizeAuthProxyPatch) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "default", "manager_auth_proxy_patch.yaml") - } - f.TemplateBody = kustomizeAuthProxyPatchTemplate - f.Input.IfExistsAction = file.Error - return f.Input, nil -} - -const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the -# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: kube-rbac-proxy - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1 - args: - - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8080/" - - "--logtostderr=true" - - "--v=10" - ports: - - containerPort: 8443 - name: https - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" -` diff --git a/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go b/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go deleted file mode 100644 index d5a7e521715..00000000000 --- a/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package metricsauth - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &KustomizePrometheusMetricsPatch{} - -// KustomizePrometheusMetricsPatch scaffolds the patch file for enabling -// prometheus metrics for manager Pod. -type KustomizePrometheusMetricsPatch struct { - file.Input -} - -// GetInput implements input.Template -func (f *KustomizePrometheusMetricsPatch) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("config", "default", "manager_prometheus_metrics_patch.yaml") - } - f.TemplateBody = kustomizePrometheusMetricsPatchTemplate - f.Input.IfExistsAction = file.Error - return f.Input, nil -} - -const kustomizePrometheusMetricsPatchTemplate = `# This patch enables Prometheus scraping for the manager pod. -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - metadata: - annotations: - prometheus.io/scrape: 'true' - spec: - containers: - # Expose the prometheus metrics on default port - - name: manager - ports: - - containerPort: 8080 - name: metrics - protocol: TCP -` diff --git a/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go b/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go deleted file mode 100644 index fc565cce549..00000000000 --- a/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AddAdmissionWebhookBuilderHandler{} - -// AddAdmissionWebhookBuilderHandler scaffolds adds a new admission webhook builder. -type AddAdmissionWebhookBuilderHandler struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource - - Config -} - -// GetInput implements input.Template -func (f *AddAdmissionWebhookBuilderHandler) GetInput() (file.Input, error) { - f.Server = strings.ToLower(f.Server) - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", f.Server), - fmt.Sprintf("add_%s_%s.go", f.Type, strings.ToLower(f.Resource.Kind))) - } - f.TemplateBody = addAdmissionWebhookBuilderHandlerTemplate - return f.Input, nil -} - -const addAdmissionWebhookBuilderHandlerTemplate = `{{ .Boilerplate }} - -package {{ .Server }}server - -import ( - "fmt" - "{{ .Repo }}/pkg/webhook/{{ .Server }}_server/{{ lower .Resource.Kind }}/{{ .Type }}" -) - -func init() { - for k, v := range {{ .Type }}.Builders { - _, found := builderMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in builder map: %v", k)) - } - builderMap[k] = v - } - for k, v := range {{ .Type }}.HandlerMap { - _, found := HandlerMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in handler map: %v", k)) - } - _, found = builderMap[k] - if !found { - log.V(1).Info(fmt.Sprintf( - "can't find webhook builder name %q in builder map", k)) - continue - } - HandlerMap[k] = v - } -} -` diff --git a/pkg/scaffold/v1/webhook/add_server.go b/pkg/scaffold/v1/webhook/add_server.go deleted file mode 100644 index 2bd68447c8a..00000000000 --- a/pkg/scaffold/v1/webhook/add_server.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &AddServer{} - -// AddServer scaffolds adds a new webhook server. -type AddServer struct { - file.Input - - Config -} - -// GetInput implements input.Template -func (f *AddServer) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("add_%s_server.go", f.Server)) - } - f.TemplateBody = addServerTemplate - return f.Input, nil -} - -const addServerTemplate = `{{ .Boilerplate }} - -package webhook - -import ( - server "{{ .Repo }}/pkg/webhook/{{ .Server }}_server" -) - -func init() { - // AddToManagerFuncs is a list of functions to create webhook servers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, server.Add) -} -` diff --git a/pkg/scaffold/v1/webhook/admissionbuilder.go b/pkg/scaffold/v1/webhook/admissionbuilder.go deleted file mode 100644 index bc16e948b09..00000000000 --- a/pkg/scaffold/v1/webhook/admissionbuilder.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AdmissionWebhookBuilder{} - -// AdmissionWebhookBuilder scaffolds adds a new webhook server. -type AdmissionWebhookBuilder struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource - - Config - - BuilderName string - - OperationsParameterString string - - Mutating bool -} - -// GetInput implements input.Template -func (f *AdmissionWebhookBuilder) GetInput() (file.Input, error) { - if f.Type == "mutating" { - f.Mutating = true - } - f.Type = strings.ToLower(f.Type) - f.BuilderName = builderName(f.Config, strings.ToLower(f.Resource.Kind)) - ops := make([]string, len(f.Operations)) - for i, op := range f.Operations { - ops[i] = "admissionregistrationv1beta1." + strings.Title(op) - } - f.OperationsParameterString = strings.Join(ops, ", ") - - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", f.Server), - strings.ToLower(f.Resource.Kind), - f.Type, - fmt.Sprintf("%s_webhook.go", strings.Join(f.Operations, "_"))) - } - f.TemplateBody = admissionWebhookBuilderTemplate - return f.Input, nil -} - -const admissionWebhookBuilderTemplate = `{{ .Boilerplate }} - -package {{ .Type }} - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) - -func init() { - builderName := "{{ .BuilderName }}" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName + ".{{ .Domain }}"). - Path("/" + builderName). -{{ if .Mutating }} Mutating(). -{{ else }} Validating(). -{{ end }} - Operations({{ .OperationsParameterString }}). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{}) -} -` diff --git a/pkg/scaffold/v1/webhook/admissionhandler.go b/pkg/scaffold/v1/webhook/admissionhandler.go deleted file mode 100644 index 6b9b2899847..00000000000 --- a/pkg/scaffold/v1/webhook/admissionhandler.go +++ /dev/null @@ -1,165 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AddAdmissionWebhookBuilderHandler{} - -// AdmissionHandler scaffolds an admission handler -type AdmissionHandler struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource - - Config - - BuilderName string - - OperationsString string - - Mutate bool -} - -// GetInput implements input.Template -func (f *AdmissionHandler) GetInput() (file.Input, error) { - f.Type = strings.ToLower(f.Type) - if f.Type == "mutating" { - f.Mutate = true - } - f.BuilderName = builderName(f.Config, strings.ToLower(f.Resource.Kind)) - ops := make([]string, len(f.Operations)) - for i, op := range f.Operations { - ops[i] = strings.Title(op) - } - f.OperationsString = strings.Join(ops, "") - - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", f.Server), - strings.ToLower(f.Resource.Kind), - f.Type, - fmt.Sprintf("%s_%s_handler.go", strings.ToLower(f.Resource.Kind), strings.Join(f.Operations, "_"))) - } - f.TemplateBody = addAdmissionHandlerTemplate - return f.Input, nil -} - -// nolint:lll -const addAdmissionHandlerTemplate = `{{ .Boilerplate }} - -package {{ .Type }} - -import ( - "context" - "net/http" - - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" - {{ .Resource.ImportAlias }} "{{ .Resource.Package }}" -) - -func init() { - webhookName := "{{ .BuilderName }}" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &{{ .Resource.Kind }}{{ .OperationsString }}Handler{}) -} - -// {{ .Resource.Kind }}{{ .OperationsString }}Handler handles {{ .Resource.Kind }} -type {{ .Resource.Kind }}{{ .OperationsString }}Handler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} -{{ if .Mutate }} -func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) {{ .Type }}{{ .Resource.Kind }}Fn(ctx context.Context, obj *{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}) error { - // TODO(user): implement your admission logic - return nil -} -{{ else }} -func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) {{ .Type }}{{ .Resource.Kind }}Fn(ctx context.Context, obj *{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}) (bool, string, error) { - // TODO(user): implement your admission logic - return true, "allowed to be admitted", nil -} -{{ end }} -var _ admission.Handler = &{{ .Resource.Kind }}{{ .OperationsString }}Handler{} -{{ if .Mutate }} -// Handle handles admission requests. -func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - copy := obj.DeepCopy() - - err = h.{{ .Type }}{{ .Resource.Kind }}Fn(ctx, copy) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.PatchResponse(obj, copy) -} -{{ else }} -// Handle handles admission requests. -func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - - allowed, reason, err := h.{{ .Type }}{{ .Resource.Kind }}Fn(ctx, obj) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.ValidationResponse(allowed, reason) -} -{{ end }} -//var _ inject.Client = &{{ .Resource.Kind }}{{ .OperationsString }}Handler{} -// -//// InjectClient injects the client into the {{ .Resource.Kind }}{{ .OperationsString }}Handler -//func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &{{ .Resource.Kind }}{{ .OperationsString }}Handler{} - -// InjectDecoder injects the decoder into the {{ .Resource.Kind }}{{ .OperationsString }}Handler -func (h *{{ .Resource.Kind }}{{ .OperationsString }}Handler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} -` diff --git a/pkg/scaffold/v1/webhook/admissionwebhooks.go b/pkg/scaffold/v1/webhook/admissionwebhooks.go deleted file mode 100644 index 1208d91ab39..00000000000 --- a/pkg/scaffold/v1/webhook/admissionwebhooks.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - "strings" - - "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/model/resource" -) - -var _ file.Template = &AdmissionWebhooks{} - -// AdmissionWebhooks scaffolds how to construct a webhook server and register webhooks. -type AdmissionWebhooks struct { - file.Input - - // Resource is a resource in the API group - Resource *resource.Resource - - Config -} - -// GetInput implements input.Template -func (f *AdmissionWebhooks) GetInput() (file.Input, error) { - f.Server = strings.ToLower(f.Server) - f.Type = strings.ToLower(f.Type) - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", - fmt.Sprintf("%s_server", f.Server), - strings.ToLower(f.Resource.Kind), - f.Type, "webhooks.go") - } - f.TemplateBody = webhooksTemplate - return f.Input, nil -} - -const webhooksTemplate = `{{ .Boilerplate }} - -package {{ .Type }} - -import ( - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - // Builders contain admission webhook builders - Builders = map[string]*builder.WebhookBuilder{} - // HandlerMap contains admission webhook handlers - HandlerMap = map[string][]admission.Handler{} -) -` diff --git a/pkg/scaffold/v1/webhook/config.go b/pkg/scaffold/v1/webhook/config.go deleted file mode 100644 index dd48bf5682b..00000000000 --- a/pkg/scaffold/v1/webhook/config.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -// Config contains the information required to scaffold files for a webhook. -type Config struct { - // Server is the name of the server. - Server string - // Type is the type of the webhook. - Type string - // Operations that the webhook will intercept, e.g. create, update, delete, connect - Operations []string -} diff --git a/pkg/scaffold/v1/webhook/server.go b/pkg/scaffold/v1/webhook/server.go deleted file mode 100644 index 75b2dcdcae5..00000000000 --- a/pkg/scaffold/v1/webhook/server.go +++ /dev/null @@ -1,120 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/model/file" -) - -var _ file.Template = &Server{} - -// Server scaffolds how to construct a webhook server and register webhooks. -type Server struct { - file.Input - - Config -} - -// GetInput implements input.Template -func (f *Server) GetInput() (file.Input, error) { - if f.Path == "" { - f.Path = filepath.Join("pkg", "webhook", fmt.Sprintf("%s_server", f.Server), "server.go") - } - f.TemplateBody = serverTemplate - return f.Input, nil -} - -const serverTemplate = `{{ .Boilerplate }} - -package {{ .Server }}server - -import ( - "fmt" - "os" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/manager" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/webhook" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - log = logf.Log.WithName("{{ .Server }}_server") - builderMap = map[string]*builder.WebhookBuilder{} - // HandlerMap contains all admission webhook handlers. - HandlerMap = map[string][]admission.Handler{} -) - -// Add adds itself to the manager -func Add(mgr manager.Manager) error { - ns := os.Getenv("POD_NAMESPACE") - if len(ns) == 0 { - ns = "default" - } - secretName := os.Getenv("SECRET_NAME") - if len(secretName) == 0 { - secretName = "webhook-server-secret" - } - - svr, err := webhook.NewServer("foo-admission-server", mgr, webhook.ServerOptions{ - // TODO(user): change the configuration of ServerOptions based on your need. - Port: 9876, - CertDir: "/tmp/cert", - BootstrapOptions: &webhook.BootstrapOptions{ - Secret: &types.NamespacedName{ - Namespace: ns, - Name: secretName, - }, - - Service: &webhook.Service{ - Namespace: ns, - Name: "webhook-server-service", - // Selectors should select the pods that runs this webhook server. - Selectors: map[string]string{ - "control-plane": "controller-manager", - }, - }, - }, - }) - if err != nil { - return err - } - - var webhooks []webhook.Webhook - for k, builder := range builderMap { - handlers, ok := HandlerMap[k] - if !ok { - log.V(1).Info(fmt.Sprintf("can't find handlers for builder: %v", k)) - handlers = []admission.Handler{} - } - wh, err := builder. - Handlers(handlers...). - WithManager(mgr). - Build() - if err != nil { - return err - } - webhooks = append(webhooks, wh) - } - - return svr.Register(webhooks...) -} -` diff --git a/pkg/scaffold/v1/webhook/util.go b/pkg/scaffold/v1/webhook/util.go deleted file mode 100644 index bbd714c8ec1..00000000000 --- a/pkg/scaffold/v1/webhook/util.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "fmt" - "strings" -) - -func builderName(config Config, resource string) string { - opsStr := strings.Join(config.Operations, "-") - return fmt.Sprintf("%s-%s-%s", config.Type, opsStr, resource) -} diff --git a/pkg/scaffold/webhook.go b/pkg/scaffold/webhook.go index da2e29e1ed6..030b525e363 100644 --- a/pkg/scaffold/webhook.go +++ b/pkg/scaffold/webhook.go @@ -25,8 +25,6 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/manager" - webhookv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/webhook" scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" webhookv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/webhook" ) @@ -84,7 +82,8 @@ func (s *webhookScaffolder) Scaffold() error { switch { case s.config.IsV1(): - return s.scaffoldV1() + return fmt.Errorf("The v1 projects are deprecated since Feb 1, 2020.\n" + + "See how to upgrade your project to v2: https://book.kubebuilder.io/migration/guide.html\n") case s.config.IsV2(): return s.scaffoldV2() default: @@ -92,25 +91,6 @@ func (s *webhookScaffolder) Scaffold() error { } } -func (s *webhookScaffolder) scaffoldV1() error { - webhookConfig := webhookv1.Config{Server: s.server, Type: s.webhookType, Operations: s.operations} - - return machinery.NewScaffold().Execute( - model.NewUniverse( - model.WithConfig(s.config), - model.WithBoilerplate(s.boilerplate), - model.WithResource(s.resource), - ), - &managerv1.Webhook{}, - &webhookv1.AdmissionHandler{Resource: s.resource, Config: webhookConfig}, - &webhookv1.AdmissionWebhookBuilder{Resource: s.resource, Config: webhookConfig}, - &webhookv1.AdmissionWebhooks{Resource: s.resource, Config: webhookConfig}, - &webhookv1.AddAdmissionWebhookBuilderHandler{Resource: s.resource, Config: webhookConfig}, - &webhookv1.Server{Config: webhookConfig}, - &webhookv1.AddServer{Config: webhookConfig}, - ) -} - func (s *webhookScaffolder) scaffoldV2() error { if s.config.MultiGroup { fmt.Println(filepath.Join("apis", s.resource.Group, s.resource.Version, diff --git a/scripts/generate_dep_manifest.sh b/scripts/generate_dep_manifest.sh deleted file mode 100755 index 46c47a68d43..00000000000 --- a/scripts/generate_dep_manifest.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -# Copyright 2020 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -# Script to generate Gopkg.toml file with override stanzas -# Script assumes you have run 'dep ensure' on the project and it is -# in compilable state. -# -# Notes about generating override stanza: -# Create a project using Kubebuilder -# Remove all the override stanzas except the k8s one. -# Run 'dep ensure' to update the dependencies and then -# run this script. -# Save the output of the script and copy its content to replace the value -# depManifestOverride variable in cmd/kubebuilder/initproject/dep_manifest.go -# - -######################################################################################################## -# NOTE: It is deprecated since is valid just for version 1 # -######################################################################################################## - -tmp_file="/tmp/dep.txt" -dep status -json|jq '.[]|.ProjectRoot,.Revision, .Version' > $tmp_file -while read name ; do - read revision; read version; - # strip quotes - myver=$(echo "$version" | tr -d '"') - myname=$(echo "$name"|tr -d '"') - if [ "$myname" = "sigs.k8s.io/kubebuilder" ]; then - continue - fi - if [ "$myver" = "branch master" ] || [ -z "$myver" ]; then - printf "\n[[override]]\nname=$name\nrevision=$revision\n" ; - else - printf "\n[[override]]\nname=$name\nversion=$version\n" ; - fi -done < $tmp_file - -cat << EOF - -[[override]] -name = "sigs.k8s.io/kubebuilder" -{{ if eq .Version "unknown" -}} -branch = "master" -{{ else -}} -version = "{{.Version}}" -{{ end }} -EOF diff --git a/test.sh b/test.sh index 2b5be531059..94b2e1decb6 100755 --- a/test.sh +++ b/test.sh @@ -22,12 +22,9 @@ source common.sh export TRACE=1 export GO111MODULE=on -# This test is used by prow and if the dep not be installed by git then it will face the GOBIN issue. -install_dep_by_git - function test_init_project { header_text "performing init project" - kubebuilder init --project-version 1 --domain example.com <<< "n" + kubebuilder init --domain example.com <<< "n" } function test_make_project { @@ -96,17 +93,8 @@ function test_project { project_dir=$1 version=$2 header_text "performing tests in dir $project_dir for project version v$version" - vendor_tarball=$tmp_root/vendor.v$version.tgz old_gopath=$GOPATH - if [[ $version == "1" ]]; then - export GOPATH=$(pwd)/testdata/gopath - download_vendor_archive - fi cd testdata/$project_dir - # v2 uses modules, and thus doesn't have a vendor directory - [[ -e ${vendor_tarball} ]] && tar -zxf $vendor_tarball - make all test # v2 doesn't test on all by default - [[ -e ${vendor_tarball} ]] && rm -rf ./vendor && rm -f Gopkg.lock cd - export GOPATH=$old_gopath } @@ -156,11 +144,6 @@ cd ${go_workspace}/src/sigs.k8s.io/kubebuilder export GO111MODULE=on go test ./cmd/... ./pkg/... -# test project v1 -# auto is roughly equivalent to off in our case, -# since we'll be in a gopath (basically, reset to default) -GO111MODULE=off test_project gopath/src/project 1 - # test project v2 GO111MODULE=on test_project project-v2 2 GO111MODULE=on test_project project-v2-multigroup 2 diff --git a/test/e2e/v1/e2e_suite.go b/test/e2e/v1/e2e_suite.go deleted file mode 100644 index 27a62b30584..00000000000 --- a/test/e2e/v1/e2e_suite.go +++ /dev/null @@ -1,166 +0,0 @@ -/* -Copyright 2019 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "fmt" - "os/exec" - "path/filepath" - "strings" - "time" - - . "github.com/onsi/ginkgo" //nolint:golint - . "github.com/onsi/gomega" //nolint:golint - - "sigs.k8s.io/kubebuilder/test/e2e/utils" -) - -var _ = Describe("kubebuilder", func() { - Context("with v1 scaffolding", func() { - var kbc *utils.KBTestContext - BeforeEach(func() { - var err error - kbc, err = utils.TestContext("GO111MODULE=off") - Expect(err).NotTo(HaveOccurred()) - Expect(kbc.Prepare()).To(Succeed()) - }) - - AfterEach(func() { - By("clean up created API objects during test process") - kbc.CleanupManifests(filepath.Join("config", "default")) - if _, err := kbc.Kubectl.Command( - "delete", "--recursive", - "-f", filepath.Join("config", "crds"), - ); err != nil { - fmt.Fprintf(GinkgoWriter, "error when running kubectl delete during cleaning up crd: %v\n", err) - } - - By("remove container image and work dir") - kbc.Destroy() - }) - - It("should generate a runnable project", func() { - // prepare v1 vendor - By("downloading the vendor tarball") - cmd := exec.Command("wget", - "https://storage.googleapis.com/kubebuilder-vendor/vendor.v1.tgz", - "-O", "/tmp/vendor.v1.tgz") - _, err := kbc.Run(cmd) - Expect(err).Should(Succeed()) - - By("untar the vendor tarball") - cmd = exec.Command("tar", "-zxf", "/tmp/vendor.v1.tgz") - _, err = kbc.Run(cmd) - Expect(err).Should(Succeed()) - - var controllerPodName string - - By("init v1 project") - err = kbc.Init( - "--project-version", "1", - "--domain", kbc.Domain, - "--dep=false") - Expect(err).Should(Succeed()) - - By("creating api definition") - err = kbc.CreateAPI( - "--group", kbc.Group, - "--version", kbc.Version, - "--kind", kbc.Kind, - "--namespaced", - "--resource", - "--controller", - "--make=false") - Expect(err).Should(Succeed()) - - By("creating core-type resource controller") - err = kbc.CreateAPI( - "--group", "apps", - "--version", "v1", - "--kind", "Deployment", - "--namespaced", - "--resource=false", - "--controller", - "--make=false") - Expect(err).Should(Succeed()) - - By("building image") - err = kbc.Make("docker-build", "IMG="+kbc.ImageName) - Expect(err).Should(Succeed()) - - By("loading docker image into kind cluster") - err = kbc.LoadImageToKindCluster() - Expect(err).Should(Succeed()) - - // NOTE: If you want to run the test against a GKE cluster, you will need to grant yourself permission. - // Otherwise, you may see "... is forbidden: attempt to grant extra privileges" - // $ kubectl create clusterrolebinding myname-cluster-admin-binding \ - // --clusterrole=cluster-admin --user=myname@mycompany.com - // https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control - By("deploying controller manager") - err = kbc.Make("deploy") - Expect(err).Should(Succeed()) - - By("validate the controller-manager pod running as expected") - verifyControllerUp := func() error { - // Get pod name - podOutput, err := kbc.Kubectl.Get( - true, - "pods", "-l", "control-plane=controller-manager", - "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}"+ - "{{ \"\\n\" }}{{ end }}{{ end }}", - ) - Expect(err).NotTo(HaveOccurred()) - podNames := utils.GetNonEmptyLines(podOutput) - if len(podNames) != 1 { - return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames)) - } - controllerPodName = podNames[0] - Expect(controllerPodName).Should(ContainSubstring("controller-manager")) - - // Validate pod status - status, err := kbc.Kubectl.Get( - true, - "pods", controllerPodName, "-o", "jsonpath={.status.phase}", - ) - Expect(err).NotTo(HaveOccurred()) - if status != "Running" { - return fmt.Errorf("controller pod in %s status", status) - } - - return nil - } - Eventually(verifyControllerUp, 2*time.Minute, time.Second).Should(Succeed()) - - By("creating an instance of CR") - inputFile := filepath.Join("config", "samples", - fmt.Sprintf("%s_%s_%s.yaml", kbc.Group, kbc.Version, strings.ToLower(kbc.Kind))) - _, err = kbc.Kubectl.Apply(false, "-f", inputFile) - Expect(err).NotTo(HaveOccurred()) - - By("validate the created resource object gets reconciled in controller") - controllerContainerLogs := func() string { - // Check container log to validate that the created resource object gets reconciled in controller - logOutput, err := kbc.Kubectl.Logs(controllerPodName, "-c", "manager") - Expect(err).NotTo(HaveOccurred()) - - return logOutput - } - Eventually(controllerContainerLogs, 2*time.Minute, time.Second).Should(ContainSubstring("Updating")) - }) - }) -}) diff --git a/test/e2e/v1/e2e_test.go b/test/e2e/v1/e2e_test.go deleted file mode 100644 index 646335063f1..00000000000 --- a/test/e2e/v1/e2e_test.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "fmt" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -// Run e2e tests using the Ginkgo runner. -func TestE2E(t *testing.T) { - RegisterFailHandler(Fail) - fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n") - RunSpecs(t, "Kubebuilder e2e suite") -} diff --git a/test_e2e.sh b/test_e2e.sh index 3a97aff50e5..eb431314688 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -23,8 +23,6 @@ export TRACE=1 export GO111MODULE=on fetch_tools -# This test is used by prow and if the dep not be installed by git then it will face the GOBIN issue. -install_dep_by_git install_kind build_kb @@ -40,7 +38,4 @@ function cleanup() { } trap cleanup EXIT - -# The v1 is deprecated -go test ./test/e2e/v1 go test ./test/e2e/v2 diff --git a/testdata/gopath/src/project/.gitignore b/testdata/gopath/src/project/.gitignore deleted file mode 100644 index d97ffc5159b..00000000000 --- a/testdata/gopath/src/project/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ - -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib -bin - -# Test binary, build with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Kubernetes Generated files - skip generated files, except for vendored files - -!vendor/**/zz_generated.* - -# editor and IDE paraphernalia -.idea -*.swp -*.swo -*~ diff --git a/testdata/gopath/src/project/Dockerfile b/testdata/gopath/src/project/Dockerfile deleted file mode 100644 index 62d28876d1d..00000000000 --- a/testdata/gopath/src/project/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# Build the manager binary -FROM golang:1.10.3 as builder - -# Copy in the go src -WORKDIR /go/src/project -COPY cmd/ cmd/ -COPY vendor/ vendor/ -COPY pkg/ pkg/ - -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager project/cmd/manager - -# Copy the controller-manager into a thin image -FROM ubuntu:latest -WORKDIR / -COPY --from=builder /go/src/project/manager . -ENTRYPOINT ["/manager"] diff --git a/testdata/gopath/src/project/Gopkg.toml b/testdata/gopath/src/project/Gopkg.toml deleted file mode 100644 index 8ee09333625..00000000000 --- a/testdata/gopath/src/project/Gopkg.toml +++ /dev/null @@ -1,37 +0,0 @@ -required = [ - "github.com/emicklei/go-restful", - "github.com/onsi/ginkgo", # for test framework - "github.com/onsi/gomega", # for test matchers - "k8s.io/client-go/plugin/pkg/client/auth/gcp", # for development against gcp - "k8s.io/code-generator/cmd/client-gen", # for go generate - "k8s.io/code-generator/cmd/deepcopy-gen", # for go generate - "sigs.k8s.io/controller-tools/cmd/controller-gen", # for crd/rbac generation - "sigs.k8s.io/controller-runtime/pkg/client/config", - "sigs.k8s.io/controller-runtime/pkg/controller", - "sigs.k8s.io/controller-runtime/pkg/handler", - "sigs.k8s.io/controller-runtime/pkg/manager", - "sigs.k8s.io/controller-runtime/pkg/runtime/signals", - "sigs.k8s.io/controller-runtime/pkg/source", - "sigs.k8s.io/testing_frameworks/integration", # for integration testing - "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1", - ] - -[prune] - go-tests = true - - -# STANZAS BELOW ARE GENERATED AND MAY BE WRITTEN - DO NOT MODIFY BELOW THIS LINE. - -[[constraint]] - name="sigs.k8s.io/controller-runtime" - version="v0.1.8" - -[[constraint]] - name="sigs.k8s.io/controller-tools" - version="v0.1.1" - -# For dependency below: Refer to issue https://github.com/golang/dep/issues/1799 -[[override]] -name = "gopkg.in/fsnotify.v1" -source = "https://github.com/fsnotify/fsnotify.git" -version="v1.4.7" diff --git a/testdata/gopath/src/project/Makefile b/testdata/gopath/src/project/Makefile deleted file mode 100644 index d81a7b1cf7c..00000000000 --- a/testdata/gopath/src/project/Makefile +++ /dev/null @@ -1,55 +0,0 @@ - -# Image URL to use all building/pushing image targets -IMG ?= controller:latest - -all: test manager - -# Run tests -test: generate fmt vet manifests - go test ./pkg/... ./cmd/... -coverprofile cover.out - -# Build manager binary -manager: generate fmt vet - go build -o bin/manager project/cmd/manager - -# Run against the configured Kubernetes cluster in ~/.kube/config -run: generate fmt vet - go run ./cmd/manager/main.go - -# Install CRDs into a cluster -install: manifests - kubectl apply -f config/crds - -# Deploy controller in the configured Kubernetes cluster in ~/.kube/config -deploy: manifests - kubectl apply -f config/crds - kustomize build config/default | kubectl apply -f - - -# Generate manifests e.g. CRD, RBAC etc. -manifests: - go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all - -# Run go fmt against code -fmt: - go fmt ./pkg/... ./cmd/... - -# Run go vet against code -vet: - go vet ./pkg/... ./cmd/... - -# Generate code -generate: -ifndef GOPATH - $(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH) -endif - go generate ./pkg/... ./cmd/... - -# Build the docker image -docker-build: test - docker build . -t ${IMG} - @echo "updating kustomize image patch file for manager resource" - sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml - -# Push the docker image -docker-push: - docker push ${IMG} diff --git a/testdata/gopath/src/project/PROJECT b/testdata/gopath/src/project/PROJECT deleted file mode 100644 index 9ee326caba7..00000000000 --- a/testdata/gopath/src/project/PROJECT +++ /dev/null @@ -1,3 +0,0 @@ -domain: testproject.org -repo: project -version: "1" diff --git a/testdata/gopath/src/project/cmd/manager/main.go b/testdata/gopath/src/project/cmd/manager/main.go deleted file mode 100644 index a7a610b25db..00000000000 --- a/testdata/gopath/src/project/cmd/manager/main.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "flag" - "os" - - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "sigs.k8s.io/controller-runtime/pkg/client/config" - "sigs.k8s.io/controller-runtime/pkg/manager" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/runtime/signals" - - "project/pkg/apis" - "project/pkg/controller" - "project/pkg/webhook" -) - -func main() { - var metricsAddr string - flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") - flag.Parse() - logf.SetLogger(logf.ZapLogger(false)) - log := logf.Log.WithName("entrypoint") - - // Get a config to talk to the apiserver - log.Info("setting up client for manager") - cfg, err := config.GetConfig() - if err != nil { - log.Error(err, "unable to set up client config") - os.Exit(1) - } - - // Create a new Cmd to provide shared dependencies and start components - log.Info("setting up manager") - mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr}) - if err != nil { - log.Error(err, "unable to set up overall controller manager") - os.Exit(1) - } - - log.Info("Registering Components.") - - // Setup Scheme for all resources - log.Info("setting up scheme") - if err := apis.AddToScheme(mgr.GetScheme()); err != nil { - log.Error(err, "unable add APIs to scheme") - os.Exit(1) - } - - // Setup all Controllers - log.Info("Setting up controller") - if err := controller.AddToManager(mgr); err != nil { - log.Error(err, "unable to register controllers to the manager") - os.Exit(1) - } - - log.Info("setting up webhooks") - if err := webhook.AddToManager(mgr); err != nil { - log.Error(err, "unable to register webhooks to the manager") - os.Exit(1) - } - - // Start the Cmd - log.Info("Starting the Cmd.") - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - log.Error(err, "unable to run the manager") - os.Exit(1) - } -} diff --git a/testdata/gopath/src/project/config/crds/creatures_v2alpha1_kraken.yaml b/testdata/gopath/src/project/config/crds/creatures_v2alpha1_kraken.yaml deleted file mode 100644 index ad84aabbcec..00000000000 --- a/testdata/gopath/src/project/config/crds/creatures_v2alpha1_kraken.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: null - labels: - controller-tools.k8s.io: "1.0" - name: krakens.creatures.testproject.org -spec: - group: creatures.testproject.org - names: - kind: Kraken - plural: krakens - scope: Cluster - validation: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - type: object - status: - type: object - version: v2alpha1 -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/gopath/src/project/config/crds/crew_v1_firstmate.yaml b/testdata/gopath/src/project/config/crds/crew_v1_firstmate.yaml deleted file mode 100644 index 69ed750c41c..00000000000 --- a/testdata/gopath/src/project/config/crds/crew_v1_firstmate.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: null - labels: - controller-tools.k8s.io: "1.0" - name: firstmates.crew.testproject.org -spec: - group: crew.testproject.org - names: - kind: FirstMate - plural: firstmates - scope: Namespaced - validation: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - type: object - status: - type: object - version: v1 -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/gopath/src/project/config/crds/policy_v1beta1_healthcheckpolicy.yaml b/testdata/gopath/src/project/config/crds/policy_v1beta1_healthcheckpolicy.yaml deleted file mode 100644 index 7a89740f599..00000000000 --- a/testdata/gopath/src/project/config/crds/policy_v1beta1_healthcheckpolicy.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: null - labels: - controller-tools.k8s.io: "1.0" - name: healthcheckpolicies.policy.testproject.org -spec: - group: policy.testproject.org - names: - kind: HealthCheckPolicy - plural: healthcheckpolicies - scope: Cluster - validation: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - type: object - status: - type: object - version: v1beta1 -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/gopath/src/project/config/crds/ship_v1beta1_frigate.yaml b/testdata/gopath/src/project/config/crds/ship_v1beta1_frigate.yaml deleted file mode 100644 index 6f3e1c24f19..00000000000 --- a/testdata/gopath/src/project/config/crds/ship_v1beta1_frigate.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: null - labels: - controller-tools.k8s.io: "1.0" - name: frigates.ship.testproject.org -spec: - group: ship.testproject.org - names: - kind: Frigate - plural: frigates - scope: Namespaced - validation: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - type: object - status: - type: object - version: v1beta1 -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/gopath/src/project/config/default/kustomization.yaml b/testdata/gopath/src/project/config/default/kustomization.yaml deleted file mode 100644 index 4e7fa75e2f1..00000000000 --- a/testdata/gopath/src/project/config/default/kustomization.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Adds namespace to all resources. -namespace: project-system - -# Value of this field is prepended to the -# names of all resources, e.g. a deployment named -# "wordpress" becomes "alices-wordpress". -# Note that it should also match with the prefix (text before '-') of the namespace -# field above. -namePrefix: project- - -# Labels to add to all resources and selectors. -#commonLabels: -# someName: someValue - -bases: -- ../rbac -- ../manager - -patchesStrategicMerge: -- manager_image_patch.yaml - # Protect the /metrics endpoint by putting it behind auth. - # Only one of manager_auth_proxy_patch.yaml and - # manager_prometheus_metrics_patch.yaml should be enabled. -- manager_auth_proxy_patch.yaml - # If you want your controller-manager to expose the /metrics - # endpoint w/o any authn/z, uncomment the following line and - # comment manager_auth_proxy_patch.yaml. - # Only one of manager_auth_proxy_patch.yaml and - # manager_prometheus_metrics_patch.yaml should be enabled. -#- manager_prometheus_metrics_patch.yaml - -vars: -- name: WEBHOOK_SECRET_NAME - objref: - kind: Secret - name: webhook-server-secret - apiVersion: v1 diff --git a/testdata/gopath/src/project/config/default/manager_auth_proxy_patch.yaml b/testdata/gopath/src/project/config/default/manager_auth_proxy_patch.yaml deleted file mode 100644 index e4fc7e9cf67..00000000000 --- a/testdata/gopath/src/project/config/default/manager_auth_proxy_patch.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# This patch inject a sidecar container which is a HTTP proxy for the -# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: kube-rbac-proxy - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.4.1 - args: - - "--secure-listen-address=0.0.0.0:8443" - - "--upstream=http://127.0.0.1:8080/" - - "--logtostderr=true" - - "--v=10" - ports: - - containerPort: 8443 - name: https - - name: manager - args: - - "--metrics-addr=127.0.0.1:8080" diff --git a/testdata/gopath/src/project/config/default/manager_image_patch.yaml b/testdata/gopath/src/project/config/default/manager_image_patch.yaml deleted file mode 100644 index fcbf39dc6a5..00000000000 --- a/testdata/gopath/src/project/config/default/manager_image_patch.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - # Change the value of image field below to your controller image URL - - image: IMAGE_URL - name: manager diff --git a/testdata/gopath/src/project/config/default/manager_prometheus_metrics_patch.yaml b/testdata/gopath/src/project/config/default/manager_prometheus_metrics_patch.yaml deleted file mode 100644 index 96fdcdac9d9..00000000000 --- a/testdata/gopath/src/project/config/default/manager_prometheus_metrics_patch.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# This patch enables Prometheus scraping for the manager pod. -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system -spec: - template: - metadata: - annotations: - prometheus.io/scrape: 'true' - spec: - containers: - # Expose the prometheus metrics on default port - - name: manager - ports: - - containerPort: 8080 - name: metrics - protocol: TCP diff --git a/testdata/gopath/src/project/config/manager/kustomization.yaml b/testdata/gopath/src/project/config/manager/kustomization.yaml deleted file mode 100644 index 5c5f0b84cba..00000000000 --- a/testdata/gopath/src/project/config/manager/kustomization.yaml +++ /dev/null @@ -1,2 +0,0 @@ -resources: -- manager.yaml diff --git a/testdata/gopath/src/project/config/manager/manager.yaml b/testdata/gopath/src/project/config/manager/manager.yaml deleted file mode 100644 index 2e57718d1dc..00000000000 --- a/testdata/gopath/src/project/config/manager/manager.yaml +++ /dev/null @@ -1,84 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - name: system ---- -apiVersion: v1 -kind: Service -metadata: - name: controller-manager-service - namespace: system - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" -spec: - selector: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - ports: - - port: 443 ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: controller-manager - namespace: system - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" -spec: - selector: - matchLabels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - serviceName: controller-manager-service - replicas: 1 - podManagementPolicy: Parallel - template: - metadata: - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - spec: - containers: - - command: - - /manager - image: controller:latest - name: manager - env: - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: SECRET_NAME - value: $(WEBHOOK_SECRET_NAME) - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - ports: - - containerPort: 9876 - name: webhook-server - protocol: TCP - volumeMounts: - - mountPath: /tmp/cert - name: cert - readOnly: true - terminationGracePeriodSeconds: 10 - volumes: - - name: cert - secret: - defaultMode: 420 - secretName: webhook-server-secret ---- -apiVersion: v1 -kind: Secret -metadata: - name: webhook-server-secret - namespace: system diff --git a/testdata/gopath/src/project/config/rbac/auth_proxy_role.yaml b/testdata/gopath/src/project/config/rbac/auth_proxy_role.yaml deleted file mode 100644 index 618f5e4177c..00000000000 --- a/testdata/gopath/src/project/config/rbac/auth_proxy_role.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: proxy-role -rules: -- apiGroups: ["authentication.k8s.io"] - resources: - - tokenreviews - verbs: ["create"] -- apiGroups: ["authorization.k8s.io"] - resources: - - subjectaccessreviews - verbs: ["create"] diff --git a/testdata/gopath/src/project/config/rbac/auth_proxy_role_binding.yaml b/testdata/gopath/src/project/config/rbac/auth_proxy_role_binding.yaml deleted file mode 100644 index 48ed1e4b85c..00000000000 --- a/testdata/gopath/src/project/config/rbac/auth_proxy_role_binding.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: proxy-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: proxy-role -subjects: -- kind: ServiceAccount - name: default - namespace: system diff --git a/testdata/gopath/src/project/config/rbac/auth_proxy_service.yaml b/testdata/gopath/src/project/config/rbac/auth_proxy_service.yaml deleted file mode 100644 index 027073f9528..00000000000 --- a/testdata/gopath/src/project/config/rbac/auth_proxy_service.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - annotations: - prometheus.io/port: "8443" - prometheus.io/scheme: https - prometheus.io/scrape: "true" - labels: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" - name: controller-manager-metrics-service - namespace: system -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager - controller-tools.k8s.io: "1.0" diff --git a/testdata/gopath/src/project/config/rbac/kustomization.yaml b/testdata/gopath/src/project/config/rbac/kustomization.yaml deleted file mode 100644 index 8c6d6a5b93c..00000000000 --- a/testdata/gopath/src/project/config/rbac/kustomization.yaml +++ /dev/null @@ -1,9 +0,0 @@ -resources: -- rbac_role.yaml -- rbac_role_binding.yaml - # Comment the following 3 lines if you want to disable - # the auth proxy (https://github.com/brancz/kube-rbac-proxy) - # which protects your /metrics endpoint. -- auth_proxy_service.yaml -- auth_proxy_role.yaml -- auth_proxy_role_binding.yaml diff --git a/testdata/gopath/src/project/config/rbac/rbac_role.yaml b/testdata/gopath/src/project/config/rbac/rbac_role.yaml deleted file mode 100644 index b56f2f6bd1c..00000000000 --- a/testdata/gopath/src/project/config/rbac/rbac_role.yaml +++ /dev/null @@ -1,163 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - creationTimestamp: null - name: manager-role -rules: -- apiGroups: - - apps - resources: - - deployments - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - apps - resources: - - deployments/status - verbs: - - get - - update - - patch -- apiGroups: - - crew.testproject.org - resources: - - firstmates - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - crew.testproject.org - resources: - - firstmates/status - verbs: - - get - - update - - patch -- apiGroups: - - ship.testproject.org - resources: - - frigates - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - ship.testproject.org - resources: - - frigates/status - verbs: - - get - - update - - patch -- apiGroups: - - policy.testproject.org - resources: - - healthcheckpolicies - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - policy.testproject.org - resources: - - healthcheckpolicies/status - verbs: - - get - - update - - patch -- apiGroups: - - creatures.testproject.org - resources: - - krakens - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - creatures.testproject.org - resources: - - krakens/status - verbs: - - get - - update - - patch -- apiGroups: - - "" - resources: - - namespaces - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - "" - resources: - - namespaces/status - verbs: - - get - - update - - patch -- apiGroups: - - admissionregistration.k8s.io - resources: - - mutatingwebhookconfigurations - - validatingwebhookconfigurations - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - "" - resources: - - secrets - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - "" - resources: - - services - verbs: - - get - - list - - watch - - create - - update - - patch - - delete diff --git a/testdata/gopath/src/project/config/rbac/rbac_role_binding.yaml b/testdata/gopath/src/project/config/rbac/rbac_role_binding.yaml deleted file mode 100644 index c1033e23fb9..00000000000 --- a/testdata/gopath/src/project/config/rbac/rbac_role_binding.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - creationTimestamp: null - name: manager-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: manager-role -subjects: -- kind: ServiceAccount - name: default - namespace: system diff --git a/testdata/gopath/src/project/config/samples/creatures_v2alpha1_kraken.yaml b/testdata/gopath/src/project/config/samples/creatures_v2alpha1_kraken.yaml deleted file mode 100644 index 68712b3319b..00000000000 --- a/testdata/gopath/src/project/config/samples/creatures_v2alpha1_kraken.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: creatures.testproject.org/v2alpha1 -kind: Kraken -metadata: - labels: - controller-tools.k8s.io: "1.0" - name: kraken-sample -spec: - # Add fields here - foo: bar diff --git a/testdata/gopath/src/project/config/samples/crew_v1_firstmate.yaml b/testdata/gopath/src/project/config/samples/crew_v1_firstmate.yaml deleted file mode 100644 index 45ebf31f208..00000000000 --- a/testdata/gopath/src/project/config/samples/crew_v1_firstmate.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: crew.testproject.org/v1 -kind: FirstMate -metadata: - labels: - controller-tools.k8s.io: "1.0" - name: firstmate-sample -spec: - # Add fields here - foo: bar diff --git a/testdata/gopath/src/project/config/samples/policy_v1beta1_healthcheckpolicy.yaml b/testdata/gopath/src/project/config/samples/policy_v1beta1_healthcheckpolicy.yaml deleted file mode 100644 index 880a99ed369..00000000000 --- a/testdata/gopath/src/project/config/samples/policy_v1beta1_healthcheckpolicy.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: policy.testproject.org/v1beta1 -kind: HealthCheckPolicy -metadata: - labels: - controller-tools.k8s.io: "1.0" - name: healthcheckpolicy-sample -spec: - # Add fields here - foo: bar diff --git a/testdata/gopath/src/project/config/samples/ship_v1beta1_frigate.yaml b/testdata/gopath/src/project/config/samples/ship_v1beta1_frigate.yaml deleted file mode 100644 index 796f468e814..00000000000 --- a/testdata/gopath/src/project/config/samples/ship_v1beta1_frigate.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: ship.testproject.org/v1beta1 -kind: Frigate -metadata: - labels: - controller-tools.k8s.io: "1.0" - name: frigate-sample -spec: - # Add fields here - foo: bar diff --git a/testdata/gopath/src/project/hack/boilerplate.go.txt b/testdata/gopath/src/project/hack/boilerplate.go.txt deleted file mode 100644 index b75c7954b88..00000000000 --- a/testdata/gopath/src/project/hack/boilerplate.go.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ \ No newline at end of file diff --git a/testdata/gopath/src/project/pkg/apis/addtoscheme_creatures_v2alpha1.go b/testdata/gopath/src/project/pkg/apis/addtoscheme_creatures_v2alpha1.go deleted file mode 100644 index 0c01bcdf9e4..00000000000 --- a/testdata/gopath/src/project/pkg/apis/addtoscheme_creatures_v2alpha1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - creaturesv2alpha1 "project/pkg/apis/creatures/v2alpha1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, creaturesv2alpha1.SchemeBuilder.AddToScheme) -} diff --git a/testdata/gopath/src/project/pkg/apis/addtoscheme_crew_v1.go b/testdata/gopath/src/project/pkg/apis/addtoscheme_crew_v1.go deleted file mode 100644 index b83c0cd11f6..00000000000 --- a/testdata/gopath/src/project/pkg/apis/addtoscheme_crew_v1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - crewv1 "project/pkg/apis/crew/v1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, crewv1.SchemeBuilder.AddToScheme) -} diff --git a/testdata/gopath/src/project/pkg/apis/addtoscheme_policy_v1beta1.go b/testdata/gopath/src/project/pkg/apis/addtoscheme_policy_v1beta1.go deleted file mode 100644 index a7d2b230ed2..00000000000 --- a/testdata/gopath/src/project/pkg/apis/addtoscheme_policy_v1beta1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - policyv1beta1 "project/pkg/apis/policy/v1beta1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, policyv1beta1.SchemeBuilder.AddToScheme) -} diff --git a/testdata/gopath/src/project/pkg/apis/addtoscheme_ship_v1beta1.go b/testdata/gopath/src/project/pkg/apis/addtoscheme_ship_v1beta1.go deleted file mode 100644 index dcd014d0c77..00000000000 --- a/testdata/gopath/src/project/pkg/apis/addtoscheme_ship_v1beta1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - shipv1beta1 "project/pkg/apis/ship/v1beta1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, shipv1beta1.SchemeBuilder.AddToScheme) -} diff --git a/testdata/gopath/src/project/pkg/apis/apis.go b/testdata/gopath/src/project/pkg/apis/apis.go deleted file mode 100644 index 8bb3fd6643b..00000000000 --- a/testdata/gopath/src/project/pkg/apis/apis.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Generate deepcopy for apis -//go:generate go run ../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../hack/boilerplate.go.txt - -// Package apis contains Kubernetes API groups. -package apis - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// AddToSchemes may be used to add all resources defined in the project to a Scheme -var AddToSchemes runtime.SchemeBuilder - -// AddToScheme adds all Resources to the Scheme -func AddToScheme(s *runtime.Scheme) error { - return AddToSchemes.AddToScheme(s) -} diff --git a/testdata/gopath/src/project/pkg/apis/creatures/group.go b/testdata/gopath/src/project/pkg/apis/creatures/group.go deleted file mode 100644 index b4339573585..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/group.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package creatures contains creatures API versions -package creatures diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/doc.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/doc.go deleted file mode 100644 index 4800ffa9025..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v2alpha1 contains API Schema definitions for the creatures v2alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/creatures -// +k8s:defaulter-gen=TypeMeta -// +groupName=creatures.testproject.org -package v2alpha1 diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types.go deleted file mode 100644 index 0dd4d0720b0..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v2alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// KrakenSpec defines the desired state of Kraken -type KrakenSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// KrakenStatus defines the observed state of Kraken -type KrakenStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +genclient:nonNamespaced - -// Kraken is the Schema for the krakens API -// +k8s:openapi-gen=true -type Kraken struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec KrakenSpec `json:"spec,omitempty"` - Status KrakenStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +genclient:nonNamespaced - -// KrakenList contains a list of Kraken -type KrakenList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Kraken `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Kraken{}, &KrakenList{}) -} diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types_test.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types_test.go deleted file mode 100644 index 9accf54f238..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/kraken_types_test.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v2alpha1 - -import ( - "testing" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -func TestStorageKraken(t *testing.T) { - key := types.NamespacedName{ - Name: "foo", - } - created := &Kraken{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - }} - g := gomega.NewGomegaWithT(t) - - // Test Create - fetched := &Kraken{} - g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(created)) - - // Test Updating the Labels - updated := fetched.DeepCopy() - updated.Labels = map[string]string{"hello": "world"} - g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(updated)) - - // Test Delete - g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) - g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) -} diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/register.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/register.go deleted file mode 100644 index 15bdef7e056..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/register.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v2alpha1 contains API Schema definitions for the creatures v2alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/creatures -// +k8s:defaulter-gen=TypeMeta -// +groupName=creatures.testproject.org -package v2alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "creatures.testproject.org", Version: "v2alpha1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is required by pkg/client/... - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource is required by pkg/client/listers/... -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/v2alpha1_suite_test.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/v2alpha1_suite_test.go deleted file mode 100644 index ded62b47924..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/v2alpha1_suite_test.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v2alpha1 - -import ( - "log" - "os" - "path/filepath" - "testing" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -var cfg *rest.Config -var c client.Client - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - if err != nil { - log.Fatal(err) - } - - if cfg, err = t.Start(); err != nil { - log.Fatal(err) - } - - if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { - log.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} diff --git a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/zz_generated.deepcopy.go b/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/zz_generated.deepcopy.go deleted file mode 100644 index edb428209de..00000000000 --- a/testdata/gopath/src/project/pkg/apis/creatures/v2alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,117 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by main. DO NOT EDIT. - -package v2alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Kraken) DeepCopyInto(out *Kraken) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kraken. -func (in *Kraken) DeepCopy() *Kraken { - if in == nil { - return nil - } - out := new(Kraken) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Kraken) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenList) DeepCopyInto(out *KrakenList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Kraken, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenList. -func (in *KrakenList) DeepCopy() *KrakenList { - if in == nil { - return nil - } - out := new(KrakenList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *KrakenList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenSpec) DeepCopyInto(out *KrakenSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenSpec. -func (in *KrakenSpec) DeepCopy() *KrakenSpec { - if in == nil { - return nil - } - out := new(KrakenSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenStatus) DeepCopyInto(out *KrakenStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenStatus. -func (in *KrakenStatus) DeepCopy() *KrakenStatus { - if in == nil { - return nil - } - out := new(KrakenStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/gopath/src/project/pkg/apis/crew/group.go b/testdata/gopath/src/project/pkg/apis/crew/group.go deleted file mode 100644 index 22e79fd0bc2..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/group.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package crew contains crew API versions -package crew diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/doc.go b/testdata/gopath/src/project/pkg/apis/crew/v1/doc.go deleted file mode 100644 index 602e9b64b36..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1 contains API Schema definitions for the crew v1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/crew -// +k8s:defaulter-gen=TypeMeta -// +groupName=crew.testproject.org -package v1 diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types.go b/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types.go deleted file mode 100644 index d8dd6005ad4..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// FirstMateSpec defines the desired state of FirstMate -type FirstMateSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// FirstMateStatus defines the observed state of FirstMate -type FirstMateStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// FirstMate is the Schema for the firstmates API -// +k8s:openapi-gen=true -type FirstMate struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec FirstMateSpec `json:"spec,omitempty"` - Status FirstMateStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// FirstMateList contains a list of FirstMate -type FirstMateList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []FirstMate `json:"items"` -} - -func init() { - SchemeBuilder.Register(&FirstMate{}, &FirstMateList{}) -} diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types_test.go b/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types_test.go deleted file mode 100644 index 03812d3c92c..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/firstmate_types_test.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "testing" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -func TestStorageFirstMate(t *testing.T) { - key := types.NamespacedName{ - Name: "foo", - Namespace: "default", - } - created := &FirstMate{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "default", - }} - g := gomega.NewGomegaWithT(t) - - // Test Create - fetched := &FirstMate{} - g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(created)) - - // Test Updating the Labels - updated := fetched.DeepCopy() - updated.Labels = map[string]string{"hello": "world"} - g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(updated)) - - // Test Delete - g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) - g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) -} diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/register.go b/testdata/gopath/src/project/pkg/apis/crew/v1/register.go deleted file mode 100644 index 352c06dd363..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/register.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1 contains API Schema definitions for the crew v1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/crew -// +k8s:defaulter-gen=TypeMeta -// +groupName=crew.testproject.org -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "crew.testproject.org", Version: "v1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is required by pkg/client/... - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource is required by pkg/client/listers/... -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/v1_suite_test.go b/testdata/gopath/src/project/pkg/apis/crew/v1/v1_suite_test.go deleted file mode 100644 index 719dc7c2119..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/v1_suite_test.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - "log" - "os" - "path/filepath" - "testing" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -var cfg *rest.Config -var c client.Client - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - if err != nil { - log.Fatal(err) - } - - if cfg, err = t.Start(); err != nil { - log.Fatal(err) - } - - if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { - log.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} diff --git a/testdata/gopath/src/project/pkg/apis/crew/v1/zz_generated.deepcopy.go b/testdata/gopath/src/project/pkg/apis/crew/v1/zz_generated.deepcopy.go deleted file mode 100644 index 2e734a09fa2..00000000000 --- a/testdata/gopath/src/project/pkg/apis/crew/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,117 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMate) DeepCopyInto(out *FirstMate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMate. -func (in *FirstMate) DeepCopy() *FirstMate { - if in == nil { - return nil - } - out := new(FirstMate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FirstMate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateList) DeepCopyInto(out *FirstMateList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FirstMate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateList. -func (in *FirstMateList) DeepCopy() *FirstMateList { - if in == nil { - return nil - } - out := new(FirstMateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FirstMateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateSpec) DeepCopyInto(out *FirstMateSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateSpec. -func (in *FirstMateSpec) DeepCopy() *FirstMateSpec { - if in == nil { - return nil - } - out := new(FirstMateSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateStatus) DeepCopyInto(out *FirstMateStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateStatus. -func (in *FirstMateStatus) DeepCopy() *FirstMateStatus { - if in == nil { - return nil - } - out := new(FirstMateStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/gopath/src/project/pkg/apis/policy/group.go b/testdata/gopath/src/project/pkg/apis/policy/group.go deleted file mode 100644 index de777a89f10..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/group.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package policy contains policy API versions -package policy diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/doc.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/doc.go deleted file mode 100644 index d4866313037..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1beta1 contains API Schema definitions for the policy v1beta1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/policy -// +k8s:defaulter-gen=TypeMeta -// +groupName=policy.testproject.org -package v1beta1 diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go deleted file mode 100644 index 1c47b1974c3..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// HealthCheckPolicySpec defines the desired state of HealthCheckPolicy -type HealthCheckPolicySpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// HealthCheckPolicyStatus defines the observed state of HealthCheckPolicy -type HealthCheckPolicyStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +genclient:nonNamespaced - -// HealthCheckPolicy is the Schema for the healthcheckpolicies API -// +k8s:openapi-gen=true -type HealthCheckPolicy struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec HealthCheckPolicySpec `json:"spec,omitempty"` - Status HealthCheckPolicyStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +genclient:nonNamespaced - -// HealthCheckPolicyList contains a list of HealthCheckPolicy -type HealthCheckPolicyList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []HealthCheckPolicy `json:"items"` -} - -func init() { - SchemeBuilder.Register(&HealthCheckPolicy{}, &HealthCheckPolicyList{}) -} diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types_test.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types_test.go deleted file mode 100644 index 9fb78b19f16..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/healthcheckpolicy_types_test.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - "testing" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -func TestStorageHealthCheckPolicy(t *testing.T) { - key := types.NamespacedName{ - Name: "foo", - } - created := &HealthCheckPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - }} - g := gomega.NewGomegaWithT(t) - - // Test Create - fetched := &HealthCheckPolicy{} - g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(created)) - - // Test Updating the Labels - updated := fetched.DeepCopy() - updated.Labels = map[string]string{"hello": "world"} - g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(updated)) - - // Test Delete - g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) - g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) -} diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/register.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/register.go deleted file mode 100644 index 109d9628097..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/register.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1beta1 contains API Schema definitions for the policy v1beta1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/policy -// +k8s:defaulter-gen=TypeMeta -// +groupName=policy.testproject.org -package v1beta1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "policy.testproject.org", Version: "v1beta1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is required by pkg/client/... - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource is required by pkg/client/listers/... -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/v1beta1_suite_test.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/v1beta1_suite_test.go deleted file mode 100644 index 192b395f666..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/v1beta1_suite_test.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - "log" - "os" - "path/filepath" - "testing" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -var cfg *rest.Config -var c client.Client - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - if err != nil { - log.Fatal(err) - } - - if cfg, err = t.Start(); err != nil { - log.Fatal(err) - } - - if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { - log.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} diff --git a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/zz_generated.deepcopy.go b/testdata/gopath/src/project/pkg/apis/policy/v1beta1/zz_generated.deepcopy.go deleted file mode 100644 index fece4b6af82..00000000000 --- a/testdata/gopath/src/project/pkg/apis/policy/v1beta1/zz_generated.deepcopy.go +++ /dev/null @@ -1,117 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by main. DO NOT EDIT. - -package v1beta1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicy) DeepCopyInto(out *HealthCheckPolicy) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicy. -func (in *HealthCheckPolicy) DeepCopy() *HealthCheckPolicy { - if in == nil { - return nil - } - out := new(HealthCheckPolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *HealthCheckPolicy) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicyList) DeepCopyInto(out *HealthCheckPolicyList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]HealthCheckPolicy, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicyList. -func (in *HealthCheckPolicyList) DeepCopy() *HealthCheckPolicyList { - if in == nil { - return nil - } - out := new(HealthCheckPolicyList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *HealthCheckPolicyList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicySpec) DeepCopyInto(out *HealthCheckPolicySpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicySpec. -func (in *HealthCheckPolicySpec) DeepCopy() *HealthCheckPolicySpec { - if in == nil { - return nil - } - out := new(HealthCheckPolicySpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicyStatus) DeepCopyInto(out *HealthCheckPolicyStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicyStatus. -func (in *HealthCheckPolicyStatus) DeepCopy() *HealthCheckPolicyStatus { - if in == nil { - return nil - } - out := new(HealthCheckPolicyStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/gopath/src/project/pkg/apis/ship/group.go b/testdata/gopath/src/project/pkg/apis/ship/group.go deleted file mode 100644 index 236da88a1da..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/group.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package ship contains ship API versions -package ship diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/doc.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/doc.go deleted file mode 100644 index 4749c7ea562..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1beta1 contains API Schema definitions for the ship v1beta1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/ship -// +k8s:defaulter-gen=TypeMeta -// +groupName=ship.testproject.org -package v1beta1 diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types.go deleted file mode 100644 index 3fe41e2c70a..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// FrigateSpec defines the desired state of Frigate -type FrigateSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// FrigateStatus defines the observed state of Frigate -type FrigateStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Frigate is the Schema for the frigates API -// +k8s:openapi-gen=true -type Frigate struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec FrigateSpec `json:"spec,omitempty"` - Status FrigateStatus `json:"status,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// FrigateList contains a list of Frigate -type FrigateList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Frigate `json:"items"` -} - -func init() { - SchemeBuilder.Register(&Frigate{}, &FrigateList{}) -} diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types_test.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types_test.go deleted file mode 100644 index fe285a59e60..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/frigate_types_test.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - "testing" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" -) - -func TestStorageFrigate(t *testing.T) { - key := types.NamespacedName{ - Name: "foo", - Namespace: "default", - } - created := &Frigate{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo", - Namespace: "default", - }} - g := gomega.NewGomegaWithT(t) - - // Test Create - fetched := &Frigate{} - g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(created)) - - // Test Updating the Labels - updated := fetched.DeepCopy() - updated.Labels = map[string]string{"hello": "world"} - g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed()) - - g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed()) - g.Expect(fetched).To(gomega.Equal(updated)) - - // Test Delete - g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed()) - g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed()) -} diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/register.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/register.go deleted file mode 100644 index 3ad8ae993a8..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/register.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1beta1 contains API Schema definitions for the ship v1beta1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=project/pkg/apis/ship -// +k8s:defaulter-gen=TypeMeta -// +groupName=ship.testproject.org -package v1beta1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "ship.testproject.org", Version: "v1beta1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - // AddToScheme is required by pkg/client/... - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource is required by pkg/client/listers/... -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/v1beta1_suite_test.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/v1beta1_suite_test.go deleted file mode 100644 index 192b395f666..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/v1beta1_suite_test.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import ( - "log" - "os" - "path/filepath" - "testing" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -var cfg *rest.Config -var c client.Client - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "config", "crds")}, - } - - err := SchemeBuilder.AddToScheme(scheme.Scheme) - if err != nil { - log.Fatal(err) - } - - if cfg, err = t.Start(); err != nil { - log.Fatal(err) - } - - if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil { - log.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} diff --git a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/zz_generated.deepcopy.go b/testdata/gopath/src/project/pkg/apis/ship/v1beta1/zz_generated.deepcopy.go deleted file mode 100644 index d5fc144cf3e..00000000000 --- a/testdata/gopath/src/project/pkg/apis/ship/v1beta1/zz_generated.deepcopy.go +++ /dev/null @@ -1,117 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by main. DO NOT EDIT. - -package v1beta1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Frigate) DeepCopyInto(out *Frigate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Frigate. -func (in *Frigate) DeepCopy() *Frigate { - if in == nil { - return nil - } - out := new(Frigate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Frigate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateList) DeepCopyInto(out *FrigateList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Frigate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateList. -func (in *FrigateList) DeepCopy() *FrigateList { - if in == nil { - return nil - } - out := new(FrigateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FrigateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateSpec) DeepCopyInto(out *FrigateSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateSpec. -func (in *FrigateSpec) DeepCopy() *FrigateSpec { - if in == nil { - return nil - } - out := new(FrigateSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateStatus) DeepCopyInto(out *FrigateStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateStatus. -func (in *FrigateStatus) DeepCopy() *FrigateStatus { - if in == nil { - return nil - } - out := new(FrigateStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/gopath/src/project/pkg/controller/add_firstmate.go b/testdata/gopath/src/project/pkg/controller/add_firstmate.go deleted file mode 100644 index 49c5c1cbdaa..00000000000 --- a/testdata/gopath/src/project/pkg/controller/add_firstmate.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "project/pkg/controller/firstmate" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, firstmate.Add) -} diff --git a/testdata/gopath/src/project/pkg/controller/add_frigate.go b/testdata/gopath/src/project/pkg/controller/add_frigate.go deleted file mode 100644 index d311549d15f..00000000000 --- a/testdata/gopath/src/project/pkg/controller/add_frigate.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "project/pkg/controller/frigate" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, frigate.Add) -} diff --git a/testdata/gopath/src/project/pkg/controller/add_healthcheckpolicy.go b/testdata/gopath/src/project/pkg/controller/add_healthcheckpolicy.go deleted file mode 100644 index a716b47c785..00000000000 --- a/testdata/gopath/src/project/pkg/controller/add_healthcheckpolicy.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "project/pkg/controller/healthcheckpolicy" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, healthcheckpolicy.Add) -} diff --git a/testdata/gopath/src/project/pkg/controller/add_kraken.go b/testdata/gopath/src/project/pkg/controller/add_kraken.go deleted file mode 100644 index 0d7f880e6a7..00000000000 --- a/testdata/gopath/src/project/pkg/controller/add_kraken.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "project/pkg/controller/kraken" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, kraken.Add) -} diff --git a/testdata/gopath/src/project/pkg/controller/add_namespace.go b/testdata/gopath/src/project/pkg/controller/add_namespace.go deleted file mode 100644 index 5a78fef4aae..00000000000 --- a/testdata/gopath/src/project/pkg/controller/add_namespace.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "project/pkg/controller/namespace" -) - -func init() { - // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, namespace.Add) -} diff --git a/testdata/gopath/src/project/pkg/controller/controller.go b/testdata/gopath/src/project/pkg/controller/controller.go deleted file mode 100644 index 4fc3d84211a..00000000000 --- a/testdata/gopath/src/project/pkg/controller/controller.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -} diff --git a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller.go b/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller.go deleted file mode 100644 index 951dcf23888..00000000000 --- a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller.go +++ /dev/null @@ -1,168 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package firstmate - -import ( - "context" - "reflect" - - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/source" - - crewv1 "project/pkg/apis/crew/v1" -) - -var log = logf.Log.WithName("firstmate-controller") - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new FirstMate Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileFirstMate{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("firstmate-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to FirstMate - err = c.Watch(&source.Kind{Type: &crewv1.FirstMate{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by FirstMate - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &crewv1.FirstMate{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &ReconcileFirstMate{} - -// ReconcileFirstMate reconciles a FirstMate object -type ReconcileFirstMate struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a FirstMate object and makes changes based on the state read -// and what is in the FirstMate.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -// Automatically generate RBAC rules to allow the Controller to read and write Deployments -// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=crew.testproject.org,resources=firstmates,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=crew.testproject.org,resources=firstmates/status,verbs=get;update;patch -func (r *ReconcileFirstMate) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the FirstMate instance - instance := &crewv1.FirstMate{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - // TODO(user): Change this to be the object type created by your controller - // Define the desired Deployment object - deploy := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: instance.Name + "-deployment", - Namespace: instance.Namespace, - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"deployment": instance.Name + "-deployment"}, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"deployment": instance.Name + "-deployment"}}, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "nginx", - Image: "nginx", - }, - }, - }, - }, - }, - } - if err := controllerutil.SetControllerReference(instance, deploy, r.scheme); err != nil { - return reconcile.Result{}, err - } - - // TODO(user): Change this for the object type created by your controller - // Check if the Deployment already exists - found := &appsv1.Deployment{} - err = r.Get(context.TODO(), types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found) - if err != nil && errors.IsNotFound(err) { - log.Info("Creating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) - err = r.Create(context.TODO(), deploy) - return reconcile.Result{}, err - } else if err != nil { - return reconcile.Result{}, err - } - - // TODO(user): Change this for the object type created by your controller - // Update the found object and write the result back if there are any changes - if !reflect.DeepEqual(deploy.Spec, found.Spec) { - found.Spec = deploy.Spec - log.Info("Updating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) - err = r.Update(context.TODO(), found) - if err != nil { - return reconcile.Result{}, err - } - } - return reconcile.Result{}, nil -} diff --git a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_suite_test.go b/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_suite_test.go deleted file mode 100644 index 6b5f661a5e9..00000000000 --- a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_suite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package firstmate - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "project/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} diff --git a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_test.go b/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_test.go deleted file mode 100644 index 6e7d191ce3a..00000000000 --- a/testdata/gopath/src/project/pkg/controller/firstmate/firstmate_controller_test.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package firstmate - -import ( - "testing" - "time" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - appsv1 "k8s.io/api/apps/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - crewv1 "project/pkg/apis/crew/v1" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo", Namespace: "default"}} -var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"} - -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &crewv1.FirstMate{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the FirstMate object and expect the Reconcile and Deployment to be created - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - - deploy := &appsv1.Deployment{} - g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout). - Should(gomega.Succeed()) - - // Delete the Deployment and expect Reconcile to be called for Deployment deletion - g.Expect(c.Delete(context.TODO(), deploy)).To(gomega.Succeed()) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - g.Eventually(func() error { return c.Get(context.TODO(), depKey, deploy) }, timeout). - Should(gomega.Succeed()) - - // Manually delete Deployment since GC isn't enabled in the test control plane - g.Eventually(func() error { return c.Delete(context.TODO(), deploy) }, timeout). - Should(gomega.MatchError("deployments.apps \"foo-deployment\" not found")) - -} diff --git a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller.go b/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller.go deleted file mode 100644 index 87b8a867df1..00000000000 --- a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package frigate - -import ( - "context" - - appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" - - shipv1beta1 "project/pkg/apis/ship/v1beta1" -) - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new Frigate Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileFrigate{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("frigate-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to Frigate - err = c.Watch(&source.Kind{Type: &shipv1beta1.Frigate{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by Frigate - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &shipv1beta1.Frigate{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &ReconcileFrigate{} - -// ReconcileFrigate reconciles a Frigate object -type ReconcileFrigate struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a Frigate object and makes changes based on the state read -// and what is in the Frigate.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -// +kubebuilder:rbac:groups=ship.testproject.org,resources=frigates,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=ship.testproject.org,resources=frigates/status,verbs=get;update;patch -func (r *ReconcileFrigate) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the Frigate instance - instance := &shipv1beta1.Frigate{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - return reconcile.Result{}, nil -} diff --git a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_suite_test.go b/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_suite_test.go deleted file mode 100644 index 3598e5b2fd1..00000000000 --- a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_suite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package frigate - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "project/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} diff --git a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_test.go b/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_test.go deleted file mode 100644 index 5beae0fc4a1..00000000000 --- a/testdata/gopath/src/project/pkg/controller/frigate/frigate_controller_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package frigate - -import ( - "testing" - "time" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - shipv1beta1 "project/pkg/apis/ship/v1beta1" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo", Namespace: "default"}} - -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &shipv1beta1.Frigate{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the Frigate object and expect the Reconcile - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - -} diff --git a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go b/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go deleted file mode 100644 index 78fb4b0d389..00000000000 --- a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package healthcheckpolicy - -import ( - "context" - - appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" - - policyv1beta1 "project/pkg/apis/policy/v1beta1" -) - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new HealthCheckPolicy Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileHealthCheckPolicy{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("healthcheckpolicy-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to HealthCheckPolicy - err = c.Watch(&source.Kind{Type: &policyv1beta1.HealthCheckPolicy{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by HealthCheckPolicy - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &policyv1beta1.HealthCheckPolicy{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &ReconcileHealthCheckPolicy{} - -// ReconcileHealthCheckPolicy reconciles a HealthCheckPolicy object -type ReconcileHealthCheckPolicy struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a HealthCheckPolicy object and makes changes based on the state read -// and what is in the HealthCheckPolicy.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -// +kubebuilder:rbac:groups=policy.testproject.org,resources=healthcheckpolicies,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=policy.testproject.org,resources=healthcheckpolicies/status,verbs=get;update;patch -func (r *ReconcileHealthCheckPolicy) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the HealthCheckPolicy instance - instance := &policyv1beta1.HealthCheckPolicy{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - return reconcile.Result{}, nil -} diff --git a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_suite_test.go b/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_suite_test.go deleted file mode 100644 index 70e428c06e7..00000000000 --- a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_suite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package healthcheckpolicy - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "project/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} diff --git a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_test.go b/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_test.go deleted file mode 100644 index c475be2ea04..00000000000 --- a/testdata/gopath/src/project/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package healthcheckpolicy - -import ( - "testing" - "time" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - policyv1beta1 "project/pkg/apis/policy/v1beta1" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo"}} - -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &policyv1beta1.HealthCheckPolicy{ObjectMeta: metav1.ObjectMeta{Name: "foo"}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the HealthCheckPolicy object and expect the Reconcile - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - -} diff --git a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller.go b/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller.go deleted file mode 100644 index dd69a13d84d..00000000000 --- a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package kraken - -import ( - "context" - - appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" - - creaturesv2alpha1 "project/pkg/apis/creatures/v2alpha1" -) - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new Kraken Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileKraken{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("kraken-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to Kraken - err = c.Watch(&source.Kind{Type: &creaturesv2alpha1.Kraken{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by Kraken - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &creaturesv2alpha1.Kraken{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &ReconcileKraken{} - -// ReconcileKraken reconciles a Kraken object -type ReconcileKraken struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a Kraken object and makes changes based on the state read -// and what is in the Kraken.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -// +kubebuilder:rbac:groups=creatures.testproject.org,resources=krakens,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=creatures.testproject.org,resources=krakens/status,verbs=get;update;patch -func (r *ReconcileKraken) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the Kraken instance - instance := &creaturesv2alpha1.Kraken{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - return reconcile.Result{}, nil -} diff --git a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_suite_test.go b/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_suite_test.go deleted file mode 100644 index 3061742bba5..00000000000 --- a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_suite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package kraken - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "project/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} diff --git a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_test.go b/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_test.go deleted file mode 100644 index 5453238f3ea..00000000000 --- a/testdata/gopath/src/project/pkg/controller/kraken/kraken_controller_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package kraken - -import ( - "testing" - "time" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - creaturesv2alpha1 "project/pkg/apis/creatures/v2alpha1" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo"}} - -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &creaturesv2alpha1.Kraken{ObjectMeta: metav1.ObjectMeta{Name: "foo"}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the Kraken object and expect the Reconcile - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - -} diff --git a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller.go b/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller.go deleted file mode 100644 index 91be9177255..00000000000 --- a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller.go +++ /dev/null @@ -1,106 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package namespace - -import ( - "context" - - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" -) - -/** -* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller -* business logic. Delete these comments after modifying this file.* - */ - -// Add creates a new Namespace Controller and adds it to the Manager with default RBAC. -// The Manager will set fields on the Controller and Start it when the Manager is Started. -func Add(mgr manager.Manager) error { - return add(mgr, newReconciler(mgr)) -} - -// newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager) reconcile.Reconciler { - return &ReconcileNamespace{Client: mgr.GetClient(), scheme: mgr.GetScheme()} -} - -// add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { - // Create a new controller - c, err := controller.New("namespace-controller", mgr, controller.Options{Reconciler: r}) - if err != nil { - return err - } - - // Watch for changes to Namespace - err = c.Watch(&source.Kind{Type: &corev1.Namespace{}}, &handler.EnqueueRequestForObject{}) - if err != nil { - return err - } - - // TODO(user): Modify this to be the types you create - // Uncomment watch a Deployment created by Namespace - change this for objects you create - err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ - IsController: true, - OwnerType: &corev1.Namespace{}, - }) - if err != nil { - return err - } - - return nil -} - -var _ reconcile.Reconciler = &ReconcileNamespace{} - -// ReconcileNamespace reconciles a Namespace object -type ReconcileNamespace struct { - client.Client - scheme *runtime.Scheme -} - -// Reconcile reads that state of the cluster for a Namespace object and makes changes based on the state read -// and what is in the Namespace.Spec -// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes -// a Deployment as an example -// +kubebuilder:rbac:groups=core,resources=namespaces,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=core,resources=namespaces/status,verbs=get;update;patch -func (r *ReconcileNamespace) Reconcile(request reconcile.Request) (reconcile.Result, error) { - // Fetch the Namespace instance - instance := &corev1.Namespace{} - err := r.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - if errors.IsNotFound(err) { - // Object not found, return. Created objects are automatically garbage collected. - // For additional cleanup logic use finalizers. - return reconcile.Result{}, nil - } - // Error reading the object - requeue the request. - return reconcile.Result{}, err - } - - return reconcile.Result{}, nil -} diff --git a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_suite_test.go b/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_suite_test.go deleted file mode 100644 index e4443287f49..00000000000 --- a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_suite_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package namespace - -import ( - stdlog "log" - "os" - "path/filepath" - "sync" - "testing" - - "github.com/onsi/gomega" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/envtest" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - "project/pkg/apis" -) - -var cfg *rest.Config - -func TestMain(m *testing.M) { - t := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")}, - } - apis.AddToScheme(scheme.Scheme) - - var err error - if cfg, err = t.Start(); err != nil { - stdlog.Fatal(err) - } - - code := m.Run() - t.Stop() - os.Exit(code) -} - -// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and -// writes the request to requests after Reconcile is finished. -func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { - requests := make(chan reconcile.Request) - fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { - result, err := inner.Reconcile(req) - requests <- req - return result, err - }) - return fn, requests -} - -// StartTestManager adds recFn -func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { - stop := make(chan struct{}) - wg := &sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) - }() - return stop, wg -} diff --git a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_test.go b/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_test.go deleted file mode 100644 index 6badd00fe0a..00000000000 --- a/testdata/gopath/src/project/pkg/controller/namespace/namespace_controller_test.go +++ /dev/null @@ -1,72 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package namespace - -import ( - "testing" - "time" - - "github.com/onsi/gomega" - "golang.org/x/net/context" - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" -) - -var c client.Client - -var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: "foo"}} - -const timeout = time.Second * 5 - -func TestReconcile(t *testing.T) { - g := gomega.NewGomegaWithT(t) - instance := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "foo"}} - - // Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a - // channel when it is finished. - mgr, err := manager.New(cfg, manager.Options{}) - g.Expect(err).NotTo(gomega.HaveOccurred()) - c = mgr.GetClient() - - recFn, requests := SetupTestReconcile(newReconciler(mgr)) - g.Expect(add(mgr, recFn)).To(gomega.Succeed()) - - stopMgr, mgrStopped := StartTestManager(mgr, g) - - defer func() { - close(stopMgr) - mgrStopped.Wait() - }() - - // Create the Namespace object and expect the Reconcile - err = c.Create(context.TODO(), instance) - // The instance object may not be a valid object because it might be missing some required fields. - // Please modify the instance object by adding required fields and then remove the following if statement. - if apierrors.IsInvalid(err) { - t.Logf("failed to create object, got an invalid object error: %v", err) - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - defer c.Delete(context.TODO(), instance) - g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest))) - -} diff --git a/testdata/gopath/src/project/pkg/webhook/add_default_server.go b/testdata/gopath/src/project/pkg/webhook/add_default_server.go deleted file mode 100644 index 6d5e2193423..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/add_default_server.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - server "project/pkg/webhook/default_server" -) - -func init() { - // AddToManagerFuncs is a list of functions to create webhook servers and add them to a manager. - AddToManagerFuncs = append(AddToManagerFuncs, server.Add) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_firstmate.go b/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_firstmate.go deleted file mode 100644 index d5b92d06a66..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_firstmate.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package defaultserver - -import ( - "fmt" - - "project/pkg/webhook/default_server/firstmate/mutating" -) - -func init() { - for k, v := range mutating.Builders { - _, found := builderMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in builder map: %v", k)) - } - builderMap[k] = v - } - for k, v := range mutating.HandlerMap { - _, found := HandlerMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in handler map: %v", k)) - } - _, found = builderMap[k] - if !found { - log.V(1).Info(fmt.Sprintf( - "can't find webhook builder name %q in builder map", k)) - continue - } - HandlerMap[k] = v - } -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_namespace.go b/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_namespace.go deleted file mode 100644 index 763a137be21..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/add_mutating_namespace.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package defaultserver - -import ( - "fmt" - - "project/pkg/webhook/default_server/namespace/mutating" -) - -func init() { - for k, v := range mutating.Builders { - _, found := builderMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in builder map: %v", k)) - } - builderMap[k] = v - } - for k, v := range mutating.HandlerMap { - _, found := HandlerMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in handler map: %v", k)) - } - _, found = builderMap[k] - if !found { - log.V(1).Info(fmt.Sprintf( - "can't find webhook builder name %q in builder map", k)) - continue - } - HandlerMap[k] = v - } -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_frigate.go b/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_frigate.go deleted file mode 100644 index 0b8073a3c10..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_frigate.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package defaultserver - -import ( - "fmt" - - "project/pkg/webhook/default_server/frigate/validating" -) - -func init() { - for k, v := range validating.Builders { - _, found := builderMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in builder map: %v", k)) - } - builderMap[k] = v - } - for k, v := range validating.HandlerMap { - _, found := HandlerMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in handler map: %v", k)) - } - _, found = builderMap[k] - if !found { - log.V(1).Info(fmt.Sprintf( - "can't find webhook builder name %q in builder map", k)) - continue - } - HandlerMap[k] = v - } -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_kraken.go b/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_kraken.go deleted file mode 100644 index 65bd75d1423..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/add_validating_kraken.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package defaultserver - -import ( - "fmt" - - "project/pkg/webhook/default_server/kraken/validating" -) - -func init() { - for k, v := range validating.Builders { - _, found := builderMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in builder map: %v", k)) - } - builderMap[k] = v - } - for k, v := range validating.HandlerMap { - _, found := HandlerMap[k] - if found { - log.V(1).Info(fmt.Sprintf( - "conflicting webhook builder names in handler map: %v", k)) - } - _, found = builderMap[k] - if !found { - log.V(1).Info(fmt.Sprintf( - "can't find webhook builder name %q in builder map", k)) - continue - } - HandlerMap[k] = v - } -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/create_update_webhook.go b/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/create_update_webhook.go deleted file mode 100644 index b226ca78e3f..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/create_update_webhook.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" - - crewv1 "project/pkg/apis/crew/v1" -) - -func init() { - builderName := "mutating-create-update-firstmate" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName+".testproject.org"). - Path("/"+builderName). - Mutating(). - Operations(admissionregistrationv1beta1.Create, admissionregistrationv1beta1.Update). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&crewv1.FirstMate{}) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/delete_webhook.go b/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/delete_webhook.go deleted file mode 100644 index e6b4bb3bb2f..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/delete_webhook.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" - - crewv1 "project/pkg/apis/crew/v1" -) - -func init() { - builderName := "mutating-delete-firstmate" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName + ".testproject.org"). - Path("/" + builderName). - Mutating(). - Operations(admissionregistrationv1beta1.Delete). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&crewv1.FirstMate{}) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_create_update_handler.go b/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_create_update_handler.go deleted file mode 100644 index bb9275df4e3..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_create_update_handler.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - "context" - "net/http" - - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" - - crewv1 "project/pkg/apis/crew/v1" -) - -func init() { - webhookName := "mutating-create-update-firstmate" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &FirstMateCreateUpdateHandler{}) -} - -// FirstMateCreateUpdateHandler handles FirstMate -type FirstMateCreateUpdateHandler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} - -func (h *FirstMateCreateUpdateHandler) mutatingFirstMateFn(ctx context.Context, obj *crewv1.FirstMate) error { - // TODO(user): implement your admission logic - return nil -} - -var _ admission.Handler = &FirstMateCreateUpdateHandler{} - -// Handle handles admission requests. -func (h *FirstMateCreateUpdateHandler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &crewv1.FirstMate{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - copy := obj.DeepCopy() - - err = h.mutatingFirstMateFn(ctx, copy) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.PatchResponse(obj, copy) -} - -//var _ inject.Client = &FirstMateCreateUpdateHandler{} -// -//// InjectClient injects the client into the FirstMateCreateUpdateHandler -//func (h *FirstMateCreateUpdateHandler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &FirstMateCreateUpdateHandler{} - -// InjectDecoder injects the decoder into the FirstMateCreateUpdateHandler -func (h *FirstMateCreateUpdateHandler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_delete_handler.go b/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_delete_handler.go deleted file mode 100644 index 7147f369e59..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/firstmate_delete_handler.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - "context" - "net/http" - - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" - - crewv1 "project/pkg/apis/crew/v1" -) - -func init() { - webhookName := "mutating-delete-firstmate" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &FirstMateDeleteHandler{}) -} - -// FirstMateDeleteHandler handles FirstMate -type FirstMateDeleteHandler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} - -func (h *FirstMateDeleteHandler) mutatingFirstMateFn(ctx context.Context, obj *crewv1.FirstMate) error { - // TODO(user): implement your admission logic - return nil -} - -var _ admission.Handler = &FirstMateDeleteHandler{} - -// Handle handles admission requests. -func (h *FirstMateDeleteHandler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &crewv1.FirstMate{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - copy := obj.DeepCopy() - - err = h.mutatingFirstMateFn(ctx, copy) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.PatchResponse(obj, copy) -} - -//var _ inject.Client = &FirstMateDeleteHandler{} -// -//// InjectClient injects the client into the FirstMateDeleteHandler -//func (h *FirstMateDeleteHandler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &FirstMateDeleteHandler{} - -// InjectDecoder injects the decoder into the FirstMateDeleteHandler -func (h *FirstMateDeleteHandler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/webhooks.go b/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/webhooks.go deleted file mode 100644 index bf37f7ab4f2..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/firstmate/mutating/webhooks.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - // Builders contain admission webhook builders - Builders = map[string]*builder.WebhookBuilder{} - // HandlerMap contains admission webhook handlers - HandlerMap = map[string][]admission.Handler{} -) diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go b/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go deleted file mode 100644 index 62352ac15b3..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/frigate_update_handler.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - "context" - "net/http" - - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" - - shipv1beta1 "project/pkg/apis/ship/v1beta1" -) - -func init() { - webhookName := "validating-update-frigate" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &FrigateUpdateHandler{}) -} - -// FrigateUpdateHandler handles Frigate -type FrigateUpdateHandler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} - -func (h *FrigateUpdateHandler) validatingFrigateFn(ctx context.Context, obj *shipv1beta1.Frigate) (bool, string, error) { - // TODO(user): implement your admission logic - return true, "allowed to be admitted", nil -} - -var _ admission.Handler = &FrigateUpdateHandler{} - -// Handle handles admission requests. -func (h *FrigateUpdateHandler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &shipv1beta1.Frigate{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - - allowed, reason, err := h.validatingFrigateFn(ctx, obj) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.ValidationResponse(allowed, reason) -} - -//var _ inject.Client = &FrigateUpdateHandler{} -// -//// InjectClient injects the client into the FrigateUpdateHandler -//func (h *FrigateUpdateHandler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &FrigateUpdateHandler{} - -// InjectDecoder injects the decoder into the FrigateUpdateHandler -func (h *FrigateUpdateHandler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/update_webhook.go b/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/update_webhook.go deleted file mode 100644 index e0187628ed1..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/update_webhook.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" - - shipv1beta1 "project/pkg/apis/ship/v1beta1" -) - -func init() { - builderName := "validating-update-frigate" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName + ".testproject.org"). - Path("/" + builderName). - Validating(). - Operations(admissionregistrationv1beta1.Update). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&shipv1beta1.Frigate{}) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/webhooks.go b/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/webhooks.go deleted file mode 100644 index ac19d661388..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/frigate/validating/webhooks.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - // Builders contain admission webhook builders - Builders = map[string]*builder.WebhookBuilder{} - // HandlerMap contains admission webhook handlers - HandlerMap = map[string][]admission.Handler{} -) diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/create_webhook.go b/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/create_webhook.go deleted file mode 100644 index e895ad1c767..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/create_webhook.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" - - creaturesv2alpha1 "project/pkg/apis/creatures/v2alpha1" -) - -func init() { - builderName := "validating-create-kraken" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName + ".testproject.org"). - Path("/" + builderName). - Validating(). - Operations(admissionregistrationv1beta1.Create). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&creaturesv2alpha1.Kraken{}) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/kraken_create_handler.go b/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/kraken_create_handler.go deleted file mode 100644 index 743bddbf68d..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/kraken_create_handler.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - "context" - "net/http" - - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" - - creaturesv2alpha1 "project/pkg/apis/creatures/v2alpha1" -) - -func init() { - webhookName := "validating-create-kraken" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &KrakenCreateHandler{}) -} - -// KrakenCreateHandler handles Kraken -type KrakenCreateHandler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} - -func (h *KrakenCreateHandler) validatingKrakenFn(ctx context.Context, obj *creaturesv2alpha1.Kraken) (bool, string, error) { - // TODO(user): implement your admission logic - return true, "allowed to be admitted", nil -} - -var _ admission.Handler = &KrakenCreateHandler{} - -// Handle handles admission requests. -func (h *KrakenCreateHandler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &creaturesv2alpha1.Kraken{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - - allowed, reason, err := h.validatingKrakenFn(ctx, obj) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.ValidationResponse(allowed, reason) -} - -//var _ inject.Client = &KrakenCreateHandler{} -// -//// InjectClient injects the client into the KrakenCreateHandler -//func (h *KrakenCreateHandler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &KrakenCreateHandler{} - -// InjectDecoder injects the decoder into the KrakenCreateHandler -func (h *KrakenCreateHandler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/webhooks.go b/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/webhooks.go deleted file mode 100644 index ac19d661388..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/kraken/validating/webhooks.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package validating - -import ( - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - // Builders contain admission webhook builders - Builders = map[string]*builder.WebhookBuilder{} - // HandlerMap contains admission webhook handlers - HandlerMap = map[string][]admission.Handler{} -) diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/namespace_update_handler.go b/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/namespace_update_handler.go deleted file mode 100644 index be800d3a957..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/namespace_update_handler.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - "context" - "net/http" - - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/runtime/inject" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types" -) - -func init() { - webhookName := "mutating-update-namespace" - if HandlerMap[webhookName] == nil { - HandlerMap[webhookName] = []admission.Handler{} - } - HandlerMap[webhookName] = append(HandlerMap[webhookName], &NamespaceUpdateHandler{}) -} - -// NamespaceUpdateHandler handles Namespace -type NamespaceUpdateHandler struct { - // To use the client, you need to do the following: - // - uncomment it - // - import sigs.k8s.io/controller-runtime/pkg/client - // - uncomment the InjectClient method at the bottom of this file. - // Client client.Client - - // Decoder decodes objects - Decoder types.Decoder -} - -func (h *NamespaceUpdateHandler) mutatingNamespaceFn(ctx context.Context, obj *corev1.Namespace) error { - // TODO(user): implement your admission logic - return nil -} - -var _ admission.Handler = &NamespaceUpdateHandler{} - -// Handle handles admission requests. -func (h *NamespaceUpdateHandler) Handle(ctx context.Context, req types.Request) types.Response { - obj := &corev1.Namespace{} - - err := h.Decoder.Decode(req, obj) - if err != nil { - return admission.ErrorResponse(http.StatusBadRequest, err) - } - copy := obj.DeepCopy() - - err = h.mutatingNamespaceFn(ctx, copy) - if err != nil { - return admission.ErrorResponse(http.StatusInternalServerError, err) - } - return admission.PatchResponse(obj, copy) -} - -//var _ inject.Client = &NamespaceUpdateHandler{} -// -//// InjectClient injects the client into the NamespaceUpdateHandler -//func (h *NamespaceUpdateHandler) InjectClient(c client.Client) error { -// h.Client = c -// return nil -//} - -var _ inject.Decoder = &NamespaceUpdateHandler{} - -// InjectDecoder injects the decoder into the NamespaceUpdateHandler -func (h *NamespaceUpdateHandler) InjectDecoder(d types.Decoder) error { - h.Decoder = d - return nil -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/update_webhook.go b/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/update_webhook.go deleted file mode 100644 index 84331cc975c..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/update_webhook.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -func init() { - builderName := "mutating-update-namespace" - Builders[builderName] = builder. - NewWebhookBuilder(). - Name(builderName + ".testproject.org"). - Path("/" + builderName). - Mutating(). - Operations(admissionregistrationv1beta1.Update). - FailurePolicy(admissionregistrationv1beta1.Fail). - ForType(&corev1.Namespace{}) -} diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/webhooks.go b/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/webhooks.go deleted file mode 100644 index bf37f7ab4f2..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/namespace/mutating/webhooks.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mutating - -import ( - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - // Builders contain admission webhook builders - Builders = map[string]*builder.WebhookBuilder{} - // HandlerMap contains admission webhook handlers - HandlerMap = map[string][]admission.Handler{} -) diff --git a/testdata/gopath/src/project/pkg/webhook/default_server/server.go b/testdata/gopath/src/project/pkg/webhook/default_server/server.go deleted file mode 100644 index 242ebb8221e..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/default_server/server.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package defaultserver - -import ( - "fmt" - "os" - - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/manager" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/webhook" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder" -) - -var ( - log = logf.Log.WithName("default_server") - builderMap = map[string]*builder.WebhookBuilder{} - // HandlerMap contains all admission webhook handlers. - HandlerMap = map[string][]admission.Handler{} -) - -// Add adds itself to the manager -func Add(mgr manager.Manager) error { - ns := os.Getenv("POD_NAMESPACE") - if len(ns) == 0 { - ns = "default" - } - secretName := os.Getenv("SECRET_NAME") - if len(secretName) == 0 { - secretName = "webhook-server-secret" - } - - svr, err := webhook.NewServer("foo-admission-server", mgr, webhook.ServerOptions{ - // TODO(user): change the configuration of ServerOptions based on your need. - Port: 9876, - CertDir: "/tmp/cert", - BootstrapOptions: &webhook.BootstrapOptions{ - Secret: &types.NamespacedName{ - Namespace: ns, - Name: secretName, - }, - - Service: &webhook.Service{ - Namespace: ns, - Name: "webhook-server-service", - // Selectors should select the pods that runs this webhook server. - Selectors: map[string]string{ - "control-plane": "controller-manager", - }, - }, - }, - }) - if err != nil { - return err - } - - var webhooks []webhook.Webhook - for k, builder := range builderMap { - handlers, ok := HandlerMap[k] - if !ok { - log.V(1).Info(fmt.Sprintf("can't find handlers for builder: %v", k)) - handlers = []admission.Handler{} - } - wh, err := builder. - Handlers(handlers...). - WithManager(mgr). - Build() - if err != nil { - return err - } - webhooks = append(webhooks, wh) - } - - return svr.Register(webhooks...) -} diff --git a/testdata/gopath/src/project/pkg/webhook/webhook.go b/testdata/gopath/src/project/pkg/webhook/webhook.go deleted file mode 100644 index 646d6d5f953..00000000000 --- a/testdata/gopath/src/project/pkg/webhook/webhook.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package webhook - -import ( - "sigs.k8s.io/controller-runtime/pkg/manager" -) - -// AddToManagerFuncs is a list of functions to add all Controllers to the Manager -var AddToManagerFuncs []func(manager.Manager) error - -// AddToManager adds all Controllers to the Manager -// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete -func AddToManager(m manager.Manager) error { - for _, f := range AddToManagerFuncs { - if err := f(m); err != nil { - return err - } - } - return nil -} diff --git a/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go deleted file mode 100644 index be62a68e8c3..00000000000 --- a/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Captain) DeepCopyInto(out *Captain) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Captain. -func (in *Captain) DeepCopy() *Captain { - if in == nil { - return nil - } - out := new(Captain) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Captain) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainList) DeepCopyInto(out *CaptainList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Captain, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainList. -func (in *CaptainList) DeepCopy() *CaptainList { - if in == nil { - return nil - } - out := new(CaptainList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CaptainList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainSpec) DeepCopyInto(out *CaptainSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainSpec. -func (in *CaptainSpec) DeepCopy() *CaptainSpec { - if in == nil { - return nil - } - out := new(CaptainSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainStatus) DeepCopyInto(out *CaptainStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainStatus. -func (in *CaptainStatus) DeepCopy() *CaptainStatus { - if in == nil { - return nil - } - out := new(CaptainStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go deleted file mode 100644 index 95ae2daa6bb..00000000000 --- a/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicy) DeepCopyInto(out *HealthCheckPolicy) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicy. -func (in *HealthCheckPolicy) DeepCopy() *HealthCheckPolicy { - if in == nil { - return nil - } - out := new(HealthCheckPolicy) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *HealthCheckPolicy) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicyList) DeepCopyInto(out *HealthCheckPolicyList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]HealthCheckPolicy, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicyList. -func (in *HealthCheckPolicyList) DeepCopy() *HealthCheckPolicyList { - if in == nil { - return nil - } - out := new(HealthCheckPolicyList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *HealthCheckPolicyList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicySpec) DeepCopyInto(out *HealthCheckPolicySpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicySpec. -func (in *HealthCheckPolicySpec) DeepCopy() *HealthCheckPolicySpec { - if in == nil { - return nil - } - out := new(HealthCheckPolicySpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPolicyStatus) DeepCopyInto(out *HealthCheckPolicyStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPolicyStatus. -func (in *HealthCheckPolicyStatus) DeepCopy() *HealthCheckPolicyStatus { - if in == nil { - return nil - } - out := new(HealthCheckPolicyStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go deleted file mode 100644 index 9ef217c7947..00000000000 --- a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1beta1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Kraken) DeepCopyInto(out *Kraken) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kraken. -func (in *Kraken) DeepCopy() *Kraken { - if in == nil { - return nil - } - out := new(Kraken) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Kraken) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenList) DeepCopyInto(out *KrakenList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Kraken, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenList. -func (in *KrakenList) DeepCopy() *KrakenList { - if in == nil { - return nil - } - out := new(KrakenList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *KrakenList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenSpec) DeepCopyInto(out *KrakenSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenSpec. -func (in *KrakenSpec) DeepCopy() *KrakenSpec { - if in == nil { - return nil - } - out := new(KrakenSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KrakenStatus) DeepCopyInto(out *KrakenStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KrakenStatus. -func (in *KrakenStatus) DeepCopy() *KrakenStatus { - if in == nil { - return nil - } - out := new(KrakenStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go deleted file mode 100644 index b6960c5d93b..00000000000 --- a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1beta2 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Leviathan) DeepCopyInto(out *Leviathan) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Leviathan. -func (in *Leviathan) DeepCopy() *Leviathan { - if in == nil { - return nil - } - out := new(Leviathan) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Leviathan) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LeviathanList) DeepCopyInto(out *LeviathanList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Leviathan, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeviathanList. -func (in *LeviathanList) DeepCopy() *LeviathanList { - if in == nil { - return nil - } - out := new(LeviathanList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *LeviathanList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LeviathanSpec) DeepCopyInto(out *LeviathanSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeviathanSpec. -func (in *LeviathanSpec) DeepCopy() *LeviathanSpec { - if in == nil { - return nil - } - out := new(LeviathanSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *LeviathanStatus) DeepCopyInto(out *LeviathanStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LeviathanStatus. -func (in *LeviathanStatus) DeepCopy() *LeviathanStatus { - if in == nil { - return nil - } - out := new(LeviathanStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go deleted file mode 100644 index 8adc54549f2..00000000000 --- a/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Destroyer) DeepCopyInto(out *Destroyer) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Destroyer. -func (in *Destroyer) DeepCopy() *Destroyer { - if in == nil { - return nil - } - out := new(Destroyer) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Destroyer) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DestroyerList) DeepCopyInto(out *DestroyerList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Destroyer, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DestroyerList. -func (in *DestroyerList) DeepCopy() *DestroyerList { - if in == nil { - return nil - } - out := new(DestroyerList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DestroyerList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DestroyerSpec) DeepCopyInto(out *DestroyerSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DestroyerSpec. -func (in *DestroyerSpec) DeepCopy() *DestroyerSpec { - if in == nil { - return nil - } - out := new(DestroyerSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DestroyerStatus) DeepCopyInto(out *DestroyerStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DestroyerStatus. -func (in *DestroyerStatus) DeepCopy() *DestroyerStatus { - if in == nil { - return nil - } - out := new(DestroyerStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go deleted file mode 100644 index 5da84c8d477..00000000000 --- a/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1beta1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Frigate) DeepCopyInto(out *Frigate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Frigate. -func (in *Frigate) DeepCopy() *Frigate { - if in == nil { - return nil - } - out := new(Frigate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Frigate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateList) DeepCopyInto(out *FrigateList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Frigate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateList. -func (in *FrigateList) DeepCopy() *FrigateList { - if in == nil { - return nil - } - out := new(FrigateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FrigateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateSpec) DeepCopyInto(out *FrigateSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateSpec. -func (in *FrigateSpec) DeepCopy() *FrigateSpec { - if in == nil { - return nil - } - out := new(FrigateSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FrigateStatus) DeepCopyInto(out *FrigateStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FrigateStatus. -func (in *FrigateStatus) DeepCopy() *FrigateStatus { - if in == nil { - return nil - } - out := new(FrigateStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go deleted file mode 100644 index f730e043751..00000000000 --- a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,114 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v2alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Cruiser) DeepCopyInto(out *Cruiser) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cruiser. -func (in *Cruiser) DeepCopy() *Cruiser { - if in == nil { - return nil - } - out := new(Cruiser) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Cruiser) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CruiserList) DeepCopyInto(out *CruiserList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Cruiser, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CruiserList. -func (in *CruiserList) DeepCopy() *CruiserList { - if in == nil { - return nil - } - out := new(CruiserList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CruiserList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CruiserSpec) DeepCopyInto(out *CruiserSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CruiserSpec. -func (in *CruiserSpec) DeepCopy() *CruiserSpec { - if in == nil { - return nil - } - out := new(CruiserSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CruiserStatus) DeepCopyInto(out *CruiserStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CruiserStatus. -func (in *CruiserStatus) DeepCopy() *CruiserStatus { - if in == nil { - return nil - } - out := new(CruiserStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2-multigroup/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v2-multigroup/config/crd/bases/crew.testproject.org_captains.yaml deleted file mode 100644 index 40ea8fdb5b5..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/crew.testproject.org_captains.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: captains.crew.testproject.org -spec: - group: crew.testproject.org - names: - kind: Captain - listKind: CaptainList - plural: captains - singular: captain - scope: Namespaced - validation: - openAPIV3Schema: - description: Captain is the Schema for the captains API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CaptainSpec defines the desired state of Captain - properties: - foo: - description: Foo is an example field of Captain. Edit Captain_types.go - to remove/update - type: string - type: object - status: - description: CaptainStatus defines the observed state of Captain - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml b/testdata/project-v2-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml deleted file mode 100644 index 1d7b988f6b8..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: healthcheckpolicies.foo.policy.testproject.org -spec: - group: foo.policy.testproject.org - names: - kind: HealthCheckPolicy - listKind: HealthCheckPolicyList - plural: healthcheckpolicies - singular: healthcheckpolicy - scope: Namespaced - validation: - openAPIV3Schema: - description: HealthCheckPolicy is the Schema for the healthcheckpolicies API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: HealthCheckPolicySpec defines the desired state of HealthCheckPolicy - properties: - foo: - description: Foo is an example field of HealthCheckPolicy. Edit HealthCheckPolicy_types.go - to remove/update - type: string - type: object - status: - description: HealthCheckPolicyStatus defines the observed state of HealthCheckPolicy - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml b/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml deleted file mode 100644 index e365ff64b10..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: krakens.sea-creatures.testproject.org -spec: - group: sea-creatures.testproject.org - names: - kind: Kraken - listKind: KrakenList - plural: krakens - singular: kraken - scope: Namespaced - validation: - openAPIV3Schema: - description: Kraken is the Schema for the krakens API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KrakenSpec defines the desired state of Kraken - properties: - foo: - description: Foo is an example field of Kraken. Edit Kraken_types.go - to remove/update - type: string - type: object - status: - description: KrakenStatus defines the observed state of Kraken - type: object - type: object - version: v1beta1 - versions: - - name: v1beta1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml b/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml deleted file mode 100644 index 0e7d34867cd..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: leviathans.sea-creatures.testproject.org -spec: - group: sea-creatures.testproject.org - names: - kind: Leviathan - listKind: LeviathanList - plural: leviathans - singular: leviathan - scope: Namespaced - validation: - openAPIV3Schema: - description: Leviathan is the Schema for the leviathans API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: LeviathanSpec defines the desired state of Leviathan - properties: - foo: - description: Foo is an example field of Leviathan. Edit Leviathan_types.go - to remove/update - type: string - type: object - status: - description: LeviathanStatus defines the observed state of Leviathan - type: object - type: object - version: v1beta2 - versions: - - name: v1beta2 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml b/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml deleted file mode 100644 index 701af96a4d8..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: cruisers.ship.testproject.org -spec: - group: ship.testproject.org - names: - kind: Cruiser - listKind: CruiserList - plural: cruisers - singular: cruiser - scope: Cluster - validation: - openAPIV3Schema: - description: Cruiser is the Schema for the cruisers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CruiserSpec defines the desired state of Cruiser - properties: - foo: - description: Foo is an example field of Cruiser. Edit Cruiser_types.go - to remove/update - type: string - type: object - status: - description: CruiserStatus defines the observed state of Cruiser - type: object - type: object - version: v2alpha1 - versions: - - name: v2alpha1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml b/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml deleted file mode 100644 index 082e7b19739..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: destroyers.ship.testproject.org -spec: - group: ship.testproject.org - names: - kind: Destroyer - listKind: DestroyerList - plural: destroyers - singular: destroyer - scope: Cluster - validation: - openAPIV3Schema: - description: Destroyer is the Schema for the destroyers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: DestroyerSpec defines the desired state of Destroyer - properties: - foo: - description: Foo is an example field of Destroyer. Edit Destroyer_types.go - to remove/update - type: string - type: object - status: - description: DestroyerStatus defines the observed state of Destroyer - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml b/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml deleted file mode 100644 index 4b305cdcb70..00000000000 --- a/testdata/project-v2-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: frigates.ship.testproject.org -spec: - group: ship.testproject.org - names: - kind: Frigate - listKind: FrigateList - plural: frigates - singular: frigate - scope: Namespaced - validation: - openAPIV3Schema: - description: Frigate is the Schema for the frigates API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: FrigateSpec defines the desired state of Frigate - properties: - foo: - description: Foo is an example field of Frigate. Edit Frigate_types.go - to remove/update - type: string - type: object - status: - description: FrigateStatus defines the observed state of Frigate - type: object - type: object - version: v1beta1 - versions: - - name: v1beta1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2-multigroup/config/rbac/role.yaml b/testdata/project-v2-multigroup/config/rbac/role.yaml deleted file mode 100644 index d1cb5d78124..00000000000 --- a/testdata/project-v2-multigroup/config/rbac/role.yaml +++ /dev/null @@ -1,148 +0,0 @@ - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - creationTimestamp: null - name: manager-role -rules: -- apiGroups: - - crew.testproject.org - resources: - - captains - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - crew.testproject.org - resources: - - captains/status - verbs: - - get - - patch - - update -- apiGroups: - - foo.policy.testproject.org - resources: - - healthcheckpolicies - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - foo.policy.testproject.org - resources: - - healthcheckpolicies/status - verbs: - - get - - patch - - update -- apiGroups: - - sea-creatures.testproject.org - resources: - - krakens - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - sea-creatures.testproject.org - resources: - - krakens/status - verbs: - - get - - patch - - update -- apiGroups: - - sea-creatures.testproject.org - resources: - - leviathans - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - sea-creatures.testproject.org - resources: - - leviathans/status - verbs: - - get - - patch - - update -- apiGroups: - - ship.testproject.org - resources: - - cruisers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - ship.testproject.org - resources: - - cruisers/status - verbs: - - get - - patch - - update -- apiGroups: - - ship.testproject.org - resources: - - destroyers - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - ship.testproject.org - resources: - - destroyers/status - verbs: - - get - - patch - - update -- apiGroups: - - ship.testproject.org - resources: - - frigates - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - ship.testproject.org - resources: - - frigates/status - verbs: - - get - - patch - - update diff --git a/testdata/project-v2-multigroup/config/webhook/manifests.yaml b/testdata/project-v2-multigroup/config/webhook/manifests.yaml deleted file mode 100644 index 07e89cfcf3b..00000000000 --- a/testdata/project-v2-multigroup/config/webhook/manifests.yaml +++ /dev/null @@ -1,52 +0,0 @@ - ---- -apiVersion: admissionregistration.k8s.io/v1beta1 -kind: MutatingWebhookConfiguration -metadata: - creationTimestamp: null - name: mutating-webhook-configuration -webhooks: -- clientConfig: - caBundle: Cg== - service: - name: webhook-service - namespace: system - path: /mutate-crew-testproject-org-v1-captain - failurePolicy: Fail - name: mcaptain.kb.io - rules: - - apiGroups: - - crew.testproject.org - apiVersions: - - v1 - operations: - - CREATE - - UPDATE - resources: - - captains - ---- -apiVersion: admissionregistration.k8s.io/v1beta1 -kind: ValidatingWebhookConfiguration -metadata: - creationTimestamp: null - name: validating-webhook-configuration -webhooks: -- clientConfig: - caBundle: Cg== - service: - name: webhook-service - namespace: system - path: /validate-crew-testproject-org-v1-captain - failurePolicy: Fail - name: vcaptain.kb.io - rules: - - apiGroups: - - crew.testproject.org - apiVersions: - - v1 - operations: - - CREATE - - UPDATE - resources: - - captains diff --git a/testdata/project-v2-multigroup/go.mod b/testdata/project-v2-multigroup/go.mod index 8fa29ce39a0..d7b390a0106 100644 --- a/testdata/project-v2-multigroup/go.mod +++ b/testdata/project-v2-multigroup/go.mod @@ -3,9 +3,6 @@ module sigs.k8s.io/kubebuilder/testdata/project-v2-multigroup go 1.13 require ( - github.com/go-logr/logr v0.1.0 - github.com/onsi/ginkgo v1.8.0 - github.com/onsi/gomega v1.5.0 k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655 k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90 sigs.k8s.io/controller-runtime v0.4.0 diff --git a/testdata/project-v2/api/v1/zz_generated.deepcopy.go b/testdata/project-v2/api/v1/zz_generated.deepcopy.go deleted file mode 100644 index 7015b52ea8e..00000000000 --- a/testdata/project-v2/api/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,292 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2020 The Kubernetes authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1 - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Admiral) DeepCopyInto(out *Admiral) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Admiral. -func (in *Admiral) DeepCopy() *Admiral { - if in == nil { - return nil - } - out := new(Admiral) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Admiral) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdmiralList) DeepCopyInto(out *AdmiralList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Admiral, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdmiralList. -func (in *AdmiralList) DeepCopy() *AdmiralList { - if in == nil { - return nil - } - out := new(AdmiralList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *AdmiralList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdmiralSpec) DeepCopyInto(out *AdmiralSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdmiralSpec. -func (in *AdmiralSpec) DeepCopy() *AdmiralSpec { - if in == nil { - return nil - } - out := new(AdmiralSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdmiralStatus) DeepCopyInto(out *AdmiralStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdmiralStatus. -func (in *AdmiralStatus) DeepCopy() *AdmiralStatus { - if in == nil { - return nil - } - out := new(AdmiralStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Captain) DeepCopyInto(out *Captain) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Captain. -func (in *Captain) DeepCopy() *Captain { - if in == nil { - return nil - } - out := new(Captain) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Captain) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainList) DeepCopyInto(out *CaptainList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Captain, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainList. -func (in *CaptainList) DeepCopy() *CaptainList { - if in == nil { - return nil - } - out := new(CaptainList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CaptainList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainSpec) DeepCopyInto(out *CaptainSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainSpec. -func (in *CaptainSpec) DeepCopy() *CaptainSpec { - if in == nil { - return nil - } - out := new(CaptainSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CaptainStatus) DeepCopyInto(out *CaptainStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CaptainStatus. -func (in *CaptainStatus) DeepCopy() *CaptainStatus { - if in == nil { - return nil - } - out := new(CaptainStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMate) DeepCopyInto(out *FirstMate) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMate. -func (in *FirstMate) DeepCopy() *FirstMate { - if in == nil { - return nil - } - out := new(FirstMate) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FirstMate) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateList) DeepCopyInto(out *FirstMateList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FirstMate, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateList. -func (in *FirstMateList) DeepCopy() *FirstMateList { - if in == nil { - return nil - } - out := new(FirstMateList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FirstMateList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateSpec) DeepCopyInto(out *FirstMateSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateSpec. -func (in *FirstMateSpec) DeepCopy() *FirstMateSpec { - if in == nil { - return nil - } - out := new(FirstMateSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FirstMateStatus) DeepCopyInto(out *FirstMateStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FirstMateStatus. -func (in *FirstMateStatus) DeepCopy() *FirstMateStatus { - if in == nil { - return nil - } - out := new(FirstMateStatus) - in.DeepCopyInto(out) - return out -} diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml deleted file mode 100644 index 48a261077c8..00000000000 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: admirals.crew.testproject.org -spec: - group: crew.testproject.org - names: - kind: Admiral - listKind: AdmiralList - plural: admirals - singular: admiral - scope: Cluster - validation: - openAPIV3Schema: - description: Admiral is the Schema for the admirals API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: AdmiralSpec defines the desired state of Admiral - properties: - foo: - description: Foo is an example field of Admiral. Edit Admiral_types.go - to remove/update - type: string - type: object - status: - description: AdmiralStatus defines the observed state of Admiral - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml deleted file mode 100644 index 40ea8fdb5b5..00000000000 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: captains.crew.testproject.org -spec: - group: crew.testproject.org - names: - kind: Captain - listKind: CaptainList - plural: captains - singular: captain - scope: Namespaced - validation: - openAPIV3Schema: - description: Captain is the Schema for the captains API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CaptainSpec defines the desired state of Captain - properties: - foo: - description: Foo is an example field of Captain. Edit Captain_types.go - to remove/update - type: string - type: object - status: - description: CaptainStatus defines the observed state of Captain - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml deleted file mode 100644 index a96ca7cdc6f..00000000000 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml +++ /dev/null @@ -1,56 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.4 - creationTimestamp: null - name: firstmates.crew.testproject.org -spec: - group: crew.testproject.org - names: - kind: FirstMate - listKind: FirstMateList - plural: firstmates - singular: firstmate - scope: Namespaced - validation: - openAPIV3Schema: - description: FirstMate is the Schema for the firstmates API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: FirstMateSpec defines the desired state of FirstMate - properties: - foo: - description: Foo is an example field of FirstMate. Edit FirstMate_types.go - to remove/update - type: string - type: object - status: - description: FirstMateStatus defines the observed state of FirstMate - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/testdata/project-v2/config/rbac/role.yaml b/testdata/project-v2/config/rbac/role.yaml deleted file mode 100644 index a1cd43c89d2..00000000000 --- a/testdata/project-v2/config/rbac/role.yaml +++ /dev/null @@ -1,68 +0,0 @@ - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - creationTimestamp: null - name: manager-role -rules: -- apiGroups: - - crew.testproject.org - resources: - - admirals - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - crew.testproject.org - resources: - - admirals/status - verbs: - - get - - patch - - update -- apiGroups: - - crew.testproject.org - resources: - - captains - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - crew.testproject.org - resources: - - captains/status - verbs: - - get - - patch - - update -- apiGroups: - - crew.testproject.org - resources: - - firstmates - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - crew.testproject.org - resources: - - firstmates/status - verbs: - - get - - patch - - update diff --git a/testdata/project-v2/config/webhook/manifests.yaml b/testdata/project-v2/config/webhook/manifests.yaml deleted file mode 100644 index 07e89cfcf3b..00000000000 --- a/testdata/project-v2/config/webhook/manifests.yaml +++ /dev/null @@ -1,52 +0,0 @@ - ---- -apiVersion: admissionregistration.k8s.io/v1beta1 -kind: MutatingWebhookConfiguration -metadata: - creationTimestamp: null - name: mutating-webhook-configuration -webhooks: -- clientConfig: - caBundle: Cg== - service: - name: webhook-service - namespace: system - path: /mutate-crew-testproject-org-v1-captain - failurePolicy: Fail - name: mcaptain.kb.io - rules: - - apiGroups: - - crew.testproject.org - apiVersions: - - v1 - operations: - - CREATE - - UPDATE - resources: - - captains - ---- -apiVersion: admissionregistration.k8s.io/v1beta1 -kind: ValidatingWebhookConfiguration -metadata: - creationTimestamp: null - name: validating-webhook-configuration -webhooks: -- clientConfig: - caBundle: Cg== - service: - name: webhook-service - namespace: system - path: /validate-crew-testproject-org-v1-captain - failurePolicy: Fail - name: vcaptain.kb.io - rules: - - apiGroups: - - crew.testproject.org - apiVersions: - - v1 - operations: - - CREATE - - UPDATE - resources: - - captains diff --git a/testdata/project-v2/go.mod b/testdata/project-v2/go.mod index b0ec7fd68da..438e39e33ee 100644 --- a/testdata/project-v2/go.mod +++ b/testdata/project-v2/go.mod @@ -3,9 +3,6 @@ module sigs.k8s.io/kubebuilder/testdata/project-v2 go 1.13 require ( - github.com/go-logr/logr v0.1.0 - github.com/onsi/ginkgo v1.8.0 - github.com/onsi/gomega v1.5.0 k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655 k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90 sigs.k8s.io/controller-runtime v0.4.0