From 3f0cb499e5fb8b106255219e0bdd101917a5f05b Mon Sep 17 00:00:00 2001 From: Erik Godding Boye Date: Sat, 11 Nov 2023 13:06:34 +0100 Subject: [PATCH] chore: generate applyconfigurations for APIs (SSA) --- Makefile | 29 ++- PROJECT | 2 +- api/{ => accurate}/v1/conversion_test.go | 2 +- api/accurate/v1/doc.go | 3 + api/{ => accurate}/v1/groupversion_info.go | 8 +- .../v1/subnamespace_conversion.go | 10 +- .../v1/subnamespace_conversion_test.go | 2 +- api/{ => accurate}/v1/subnamespace_types.go | 0 .../v1/zz_generated.deepcopy.go | 0 api/accurate/v2alpha1/doc.go | 3 + .../v2alpha1/groupversion_info.go | 8 +- .../v2alpha1/subnamespace_conversion.go | 0 .../v2alpha1/subnamespace_types.go | 1 + .../v2alpha1/zz_generated.deepcopy.go | 0 cmd/accurate-controller/sub/run.go | 2 +- cmd/kubectl-accurate/sub/sub_create.go | 2 +- cmd/kubectl-accurate/sub/sub_cut.go | 2 +- cmd/kubectl-accurate/sub/sub_delete.go | 2 +- cmd/kubectl-accurate/sub/sub_graft.go | 2 +- cmd/kubectl-accurate/sub/sub_move.go | 2 +- cmd/kubectl-accurate/sub/util.go | 2 +- controllers/namespace_controller.go | 2 +- controllers/namespace_controller_test.go | 2 +- controllers/subnamespace_controller.go | 2 +- controllers/subnamespace_controller_test.go | 2 +- controllers/suite_test.go | 2 +- e2e/e2e_test.go | 2 +- go.mod | 2 +- hooks/subnamespace.go | 2 +- hooks/subnamespace_test.go | 2 +- hooks/suite_test.go | 2 +- .../accurate/v2alpha1/subnamespace.go | 203 ++++++++++++++++++ .../accurate/v2alpha1/subnamespacespec.go | 44 ++++ .../accurate/v2alpha1/subnamespacestatus.go | 38 ++++ .../applyconfigurations/internal/internal.go | 46 ++++ internal/applyconfigurations/utils.go | 25 +++ 36 files changed, 419 insertions(+), 39 deletions(-) rename api/{ => accurate}/v1/conversion_test.go (93%) create mode 100644 api/accurate/v1/doc.go rename api/{ => accurate}/v1/groupversion_info.go (58%) rename api/{ => accurate}/v1/subnamespace_conversion.go (93%) rename api/{ => accurate}/v1/subnamespace_conversion_test.go (95%) rename api/{ => accurate}/v1/subnamespace_types.go (100%) rename api/{ => accurate}/v1/zz_generated.deepcopy.go (100%) create mode 100644 api/accurate/v2alpha1/doc.go rename api/{ => accurate}/v2alpha1/groupversion_info.go (58%) rename api/{ => accurate}/v2alpha1/subnamespace_conversion.go (100%) rename api/{ => accurate}/v2alpha1/subnamespace_types.go (99%) rename api/{ => accurate}/v2alpha1/zz_generated.deepcopy.go (100%) create mode 100644 internal/applyconfigurations/accurate/v2alpha1/subnamespace.go create mode 100644 internal/applyconfigurations/accurate/v2alpha1/subnamespacespec.go create mode 100644 internal/applyconfigurations/accurate/v2alpha1/subnamespacestatus.go create mode 100644 internal/applyconfigurations/internal/internal.go create mode 100644 internal/applyconfigurations/utils.go diff --git a/Makefile b/Makefile index 002e15e..1738f27 100644 --- a/Makefile +++ b/Makefile @@ -44,17 +44,31 @@ help: ## Display this help. .PHONY: manifests manifests: setup ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. - controller-gen $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases + controller-gen $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="{./api/..., ./controllers/...}" output:crd:artifacts:config=config/crd/bases kustomize build config/kustomize-to-helm/overlays/crds | yq e "." -p yaml - > charts/accurate/crds/accurate.cybozu.com_subnamespaces.yaml kustomize build config/kustomize-to-helm/overlays/templates | yq e "." -p yaml - > charts/accurate/templates/generated/generated.yaml .PHONY: generate -generate: setup ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. - controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." +generate: setup generate-applyconfigurations ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. + controller-gen object:headerFile="hack/boilerplate.go.txt" paths="{./api/...}" + +GO_MODULE = $(shell go list -m) +API_DIRS = $(shell find api -mindepth 2 -type d | sed "s|^|$(shell go list -m)/|" | paste -sd ",") +AC_PKG = internal/applyconfigurations +.PHONY: generate-applyconfigurations +generate-applyconfigurations: applyconfiguration-gen ## Generate applyconfigurations to support typesafe SSA. + rm -rf $(AC_PKG) + @echo ">> generating $(AC_PKG)..." + $(APPLYCONFIGURATION_GEN) \ + --go-header-file hack/boilerplate.go.txt \ + --input-dirs "$(API_DIRS)" \ + --output-package "$(GO_MODULE)/$(AC_PKG)" \ + --trim-path-prefix "$(GO_MODULE)" \ + --output-base "." .PHONY: apidoc apidoc: setup $(wildcard api/*/*_types.go) - crd-to-markdown --links docs/links.csv -f api/v1/subnamespace_types.go -n SubNamespace > docs/crd_subnamespace.md + crd-to-markdown --links docs/links.csv -f api/accurate/v1/subnamespace_types.go -n SubNamespace > docs/crd_subnamespace.md .PHONY: book book: setup @@ -106,6 +120,13 @@ $(SETUP_ENVTEST): # see https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest +APPLYCONFIGURATION_GEN := $(shell pwd)/bin/applyconfiguration-gen +.PHONY: applyconfiguration-gen +applyconfiguration-gen: $(APPLYCONFIGURATION_GEN) ## Download applyconfiguration-gen locally if necessary +$(APPLYCONFIGURATION_GEN): + # see https://github.com/kubernetes/code-generator/tree/master/cmd/applyconfiguration-gen + GOBIN=$(shell pwd)/bin go install k8s.io/code-generator/cmd/applyconfiguration-gen@v0.28.3 + # go-get-tool will 'go get' any package $2 and install it to $1. PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) define go-get-tool diff --git a/PROJECT b/PROJECT index cb43a03..eadcb5c 100644 --- a/PROJECT +++ b/PROJECT @@ -11,7 +11,7 @@ resources: domain: cybozu.com group: accurate kind: SubNamespace - path: github.com/cybozu-go/accurate/api/v1 + path: github.com/cybozu-go/accurate/api/accurate/v1 version: v1 webhooks: defaulting: true diff --git a/api/v1/conversion_test.go b/api/accurate/v1/conversion_test.go similarity index 93% rename from api/v1/conversion_test.go rename to api/accurate/v1/conversion_test.go index 7596a9a..54d4362 100644 --- a/api/v1/conversion_test.go +++ b/api/accurate/v1/conversion_test.go @@ -3,7 +3,7 @@ package v1 import ( "testing" - accuratev2alpha1 "github.com/cybozu-go/accurate/api/v2alpha1" + accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" utilconversion "github.com/cybozu-go/accurate/internal/util/conversion" fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" diff --git a/api/accurate/v1/doc.go b/api/accurate/v1/doc.go new file mode 100644 index 0000000..ca9de1b --- /dev/null +++ b/api/accurate/v1/doc.go @@ -0,0 +1,3 @@ +// +kubebuilder:object:generate=true +// +groupName=accurate.cybozu.com +package v1 diff --git a/api/v1/groupversion_info.go b/api/accurate/v1/groupversion_info.go similarity index 58% rename from api/v1/groupversion_info.go rename to api/accurate/v1/groupversion_info.go index f476dc1..ce2afac 100644 --- a/api/v1/groupversion_info.go +++ b/api/accurate/v1/groupversion_info.go @@ -1,6 +1,4 @@ // Package v1 contains API Schema definitions for the accurate v1 API group -// +kubebuilder:object:generate=true -// +groupName=accurate.cybozu.com package v1 import ( @@ -9,11 +7,11 @@ import ( ) var ( - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "accurate.cybozu.com", Version: "v1"} + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "accurate.cybozu.com", Version: "v1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme diff --git a/api/v1/subnamespace_conversion.go b/api/accurate/v1/subnamespace_conversion.go similarity index 93% rename from api/v1/subnamespace_conversion.go rename to api/accurate/v1/subnamespace_conversion.go index 76780d6..8162e96 100644 --- a/api/v1/subnamespace_conversion.go +++ b/api/accurate/v1/subnamespace_conversion.go @@ -5,7 +5,7 @@ import ( "fmt" "strconv" - accuratev2alpha1 "github.com/cybozu-go/accurate/api/v2alpha1" + accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/api/meta" @@ -20,8 +20,8 @@ func (src *SubNamespace) ConvertTo(dstRaw conversion.Hub) error { dst := dstRaw.(*accuratev2alpha1.SubNamespace) logger := getConversionLogger(src).WithValues( - "source", GroupVersion.Version, - "destination", GroupVersion.Version, + "source", SchemeGroupVersion.Version, + "destination", SchemeGroupVersion.Version, ) logger.V(5).Info("converting") @@ -57,8 +57,8 @@ func (dst *SubNamespace) ConvertFrom(srcRaw conversion.Hub) error { src := srcRaw.(*accuratev2alpha1.SubNamespace) logger := getConversionLogger(src).WithValues( - "source", GroupVersion.Version, - "destination", GroupVersion.Version, + "source", SchemeGroupVersion.Version, + "destination", SchemeGroupVersion.Version, ) logger.V(5).Info("converting") diff --git a/api/v1/subnamespace_conversion_test.go b/api/accurate/v1/subnamespace_conversion_test.go similarity index 95% rename from api/v1/subnamespace_conversion_test.go rename to api/accurate/v1/subnamespace_conversion_test.go index 55715b6..86810ee 100644 --- a/api/v1/subnamespace_conversion_test.go +++ b/api/accurate/v1/subnamespace_conversion_test.go @@ -3,7 +3,7 @@ package v1 import ( "testing" - accuratev2alpha1 "github.com/cybozu-go/accurate/api/v2alpha1" + accuratev2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kstatus "sigs.k8s.io/cli-utils/pkg/kstatus/status" ) diff --git a/api/v1/subnamespace_types.go b/api/accurate/v1/subnamespace_types.go similarity index 100% rename from api/v1/subnamespace_types.go rename to api/accurate/v1/subnamespace_types.go diff --git a/api/v1/zz_generated.deepcopy.go b/api/accurate/v1/zz_generated.deepcopy.go similarity index 100% rename from api/v1/zz_generated.deepcopy.go rename to api/accurate/v1/zz_generated.deepcopy.go diff --git a/api/accurate/v2alpha1/doc.go b/api/accurate/v2alpha1/doc.go new file mode 100644 index 0000000..5a49f71 --- /dev/null +++ b/api/accurate/v2alpha1/doc.go @@ -0,0 +1,3 @@ +// +kubebuilder:object:generate=true +// +groupName=accurate.cybozu.com +package v2alpha1 diff --git a/api/v2alpha1/groupversion_info.go b/api/accurate/v2alpha1/groupversion_info.go similarity index 58% rename from api/v2alpha1/groupversion_info.go rename to api/accurate/v2alpha1/groupversion_info.go index 7a34e5d..119dbe2 100644 --- a/api/v2alpha1/groupversion_info.go +++ b/api/accurate/v2alpha1/groupversion_info.go @@ -1,6 +1,4 @@ // Package v2alpha1 contains API Schema definitions for the accurate v2alpha1 API group -// +kubebuilder:object:generate=true -// +groupName=accurate.cybozu.com package v2alpha1 import ( @@ -9,11 +7,11 @@ import ( ) var ( - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "accurate.cybozu.com", Version: "v2alpha1"} + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "accurate.cybozu.com", Version: "v2alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} // AddToScheme adds the types in this group-version to the given scheme. AddToScheme = SchemeBuilder.AddToScheme diff --git a/api/v2alpha1/subnamespace_conversion.go b/api/accurate/v2alpha1/subnamespace_conversion.go similarity index 100% rename from api/v2alpha1/subnamespace_conversion.go rename to api/accurate/v2alpha1/subnamespace_conversion.go diff --git a/api/v2alpha1/subnamespace_types.go b/api/accurate/v2alpha1/subnamespace_types.go similarity index 99% rename from api/v2alpha1/subnamespace_types.go rename to api/accurate/v2alpha1/subnamespace_types.go index e899a2e..b6fe285 100644 --- a/api/v2alpha1/subnamespace_types.go +++ b/api/accurate/v2alpha1/subnamespace_types.go @@ -35,6 +35,7 @@ type SubNamespaceSpec struct { //+kubebuilder:unservedversion //+kubebuilder:object:root=true //+kubebuilder:subresource:status +//+genclient // SubNamespace is the Schema for the subnamespaces API type SubNamespace struct { diff --git a/api/v2alpha1/zz_generated.deepcopy.go b/api/accurate/v2alpha1/zz_generated.deepcopy.go similarity index 100% rename from api/v2alpha1/zz_generated.deepcopy.go rename to api/accurate/v2alpha1/zz_generated.deepcopy.go diff --git a/cmd/accurate-controller/sub/run.go b/cmd/accurate-controller/sub/run.go index 4fb5822..a2025b3 100644 --- a/cmd/accurate-controller/sub/run.go +++ b/cmd/accurate-controller/sub/run.go @@ -8,7 +8,7 @@ import ( // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/controllers" "github.com/cybozu-go/accurate/hooks" "github.com/cybozu-go/accurate/pkg/config" diff --git a/cmd/kubectl-accurate/sub/sub_create.go b/cmd/kubectl-accurate/sub/sub_create.go index 2a77628..a5b24fd 100644 --- a/cmd/kubectl-accurate/sub/sub_create.go +++ b/cmd/kubectl-accurate/sub/sub_create.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/cmd/kubectl-accurate/sub/sub_cut.go b/cmd/kubectl-accurate/sub/sub_cut.go index 4f5f26e..198a37a 100644 --- a/cmd/kubectl-accurate/sub/sub_cut.go +++ b/cmd/kubectl-accurate/sub/sub_cut.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" diff --git a/cmd/kubectl-accurate/sub/sub_delete.go b/cmd/kubectl-accurate/sub/sub_delete.go index d09ed23..4d42e2f 100644 --- a/cmd/kubectl-accurate/sub/sub_delete.go +++ b/cmd/kubectl-accurate/sub/sub_delete.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" diff --git a/cmd/kubectl-accurate/sub/sub_graft.go b/cmd/kubectl-accurate/sub/sub_graft.go index 5a8801a..4306e00 100644 --- a/cmd/kubectl-accurate/sub/sub_graft.go +++ b/cmd/kubectl-accurate/sub/sub_graft.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" diff --git a/cmd/kubectl-accurate/sub/sub_move.go b/cmd/kubectl-accurate/sub/sub_move.go index 045868a..6351d86 100644 --- a/cmd/kubectl-accurate/sub/sub_move.go +++ b/cmd/kubectl-accurate/sub/sub_move.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" diff --git a/cmd/kubectl-accurate/sub/util.go b/cmd/kubectl-accurate/sub/util.go index aab10a7..134a803 100644 --- a/cmd/kubectl-accurate/sub/util.go +++ b/cmd/kubectl-accurate/sub/util.go @@ -1,7 +1,7 @@ package sub import ( - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" clientgoscheme "k8s.io/client-go/kubernetes/scheme" diff --git a/controllers/namespace_controller.go b/controllers/namespace_controller.go index e2dac7c..b761e0b 100644 --- a/controllers/namespace_controller.go +++ b/controllers/namespace_controller.go @@ -6,7 +6,7 @@ import ( "path" "reflect" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" diff --git a/controllers/namespace_controller_test.go b/controllers/namespace_controller_test.go index 53a5809..01772e0 100644 --- a/controllers/namespace_controller_test.go +++ b/controllers/namespace_controller_test.go @@ -5,7 +5,7 @@ import ( "errors" "time" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" "github.com/cybozu-go/accurate/pkg/indexing" . "github.com/onsi/ginkgo/v2" diff --git a/controllers/subnamespace_controller.go b/controllers/subnamespace_controller.go index a04923c..db5e6fc 100644 --- a/controllers/subnamespace_controller.go +++ b/controllers/subnamespace_controller.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/controllers/subnamespace_controller_test.go b/controllers/subnamespace_controller_test.go index dcd364e..21b7c01 100644 --- a/controllers/subnamespace_controller_test.go +++ b/controllers/subnamespace_controller_test.go @@ -4,7 +4,7 @@ import ( "context" "time" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/controllers/suite_test.go b/controllers/suite_test.go index afc9fa3..ef54451 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -18,7 +18,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/config" "github.com/cybozu-go/accurate/pkg/constants" "github.com/cybozu-go/accurate/pkg/feature" diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index e092c80..bc03f16 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -6,7 +6,7 @@ import ( "errors" "os" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/go.mod b/go.mod index af32fde..d9bb2a5 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( k8s.io/klog/v2 v2.100.1 sigs.k8s.io/cli-utils v0.35.0 sigs.k8s.io/controller-runtime v0.16.2 + sigs.k8s.io/structured-merge-diff/v4 v4.3.0 sigs.k8s.io/yaml v1.3.0 ) @@ -87,5 +88,4 @@ require ( sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect ) diff --git a/hooks/subnamespace.go b/hooks/subnamespace.go index 460c942..3525f43 100644 --- a/hooks/subnamespace.go +++ b/hooks/subnamespace.go @@ -7,7 +7,7 @@ import ( "net/http" "regexp" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/config" "github.com/cybozu-go/accurate/pkg/constants" admissionv1 "k8s.io/api/admission/v1" diff --git a/hooks/subnamespace_test.go b/hooks/subnamespace_test.go index 0e3a7a4..97a5b0f 100644 --- a/hooks/subnamespace_test.go +++ b/hooks/subnamespace_test.go @@ -3,7 +3,7 @@ package hooks import ( "context" - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/constants" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/hooks/suite_test.go b/hooks/suite_test.go index 10e6e20..37a1365 100644 --- a/hooks/suite_test.go +++ b/hooks/suite_test.go @@ -14,7 +14,7 @@ import ( admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports - accuratev1 "github.com/cybozu-go/accurate/api/v1" + accuratev1 "github.com/cybozu-go/accurate/api/accurate/v1" "github.com/cybozu-go/accurate/pkg/config" "github.com/cybozu-go/accurate/pkg/indexing" "k8s.io/apimachinery/pkg/runtime" diff --git a/internal/applyconfigurations/accurate/v2alpha1/subnamespace.go b/internal/applyconfigurations/accurate/v2alpha1/subnamespace.go new file mode 100644 index 0000000..74ebd52 --- /dev/null +++ b/internal/applyconfigurations/accurate/v2alpha1/subnamespace.go @@ -0,0 +1,203 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v2alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// SubNamespaceApplyConfiguration represents an declarative configuration of the SubNamespace type for use +// with apply. +type SubNamespaceApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Spec *SubNamespaceSpecApplyConfiguration `json:"spec,omitempty"` + Status *SubNamespaceStatusApplyConfiguration `json:"status,omitempty"` +} + +// SubNamespace constructs an declarative configuration of the SubNamespace type for use with +// apply. +func SubNamespace(name, namespace string) *SubNamespaceApplyConfiguration { + b := &SubNamespaceApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("SubNamespace") + b.WithAPIVersion("accurate.cybozu.com/v2alpha1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithKind(value string) *SubNamespaceApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithAPIVersion(value string) *SubNamespaceApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithName(value string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithGenerateName(value string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithNamespace(value string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithUID(value types.UID) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithResourceVersion(value string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithGeneration(value int64) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithCreationTimestamp(value metav1.Time) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *SubNamespaceApplyConfiguration) WithLabels(entries map[string]string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *SubNamespaceApplyConfiguration) WithAnnotations(entries map[string]string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *SubNamespaceApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *SubNamespaceApplyConfiguration) WithFinalizers(values ...string) *SubNamespaceApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *SubNamespaceApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithSpec sets the Spec field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Spec field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithSpec(value *SubNamespaceSpecApplyConfiguration) *SubNamespaceApplyConfiguration { + b.Spec = value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *SubNamespaceApplyConfiguration) WithStatus(value *SubNamespaceStatusApplyConfiguration) *SubNamespaceApplyConfiguration { + b.Status = value + return b +} diff --git a/internal/applyconfigurations/accurate/v2alpha1/subnamespacespec.go b/internal/applyconfigurations/accurate/v2alpha1/subnamespacespec.go new file mode 100644 index 0000000..af15de6 --- /dev/null +++ b/internal/applyconfigurations/accurate/v2alpha1/subnamespacespec.go @@ -0,0 +1,44 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v2alpha1 + +// SubNamespaceSpecApplyConfiguration represents an declarative configuration of the SubNamespaceSpec type for use +// with apply. +type SubNamespaceSpecApplyConfiguration struct { + Labels map[string]string `json:"labels,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` +} + +// SubNamespaceSpecApplyConfiguration constructs an declarative configuration of the SubNamespaceSpec type for use with +// apply. +func SubNamespaceSpec() *SubNamespaceSpecApplyConfiguration { + return &SubNamespaceSpecApplyConfiguration{} +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *SubNamespaceSpecApplyConfiguration) WithLabels(entries map[string]string) *SubNamespaceSpecApplyConfiguration { + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *SubNamespaceSpecApplyConfiguration) WithAnnotations(entries map[string]string) *SubNamespaceSpecApplyConfiguration { + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} diff --git a/internal/applyconfigurations/accurate/v2alpha1/subnamespacestatus.go b/internal/applyconfigurations/accurate/v2alpha1/subnamespacestatus.go new file mode 100644 index 0000000..fe9fd6e --- /dev/null +++ b/internal/applyconfigurations/accurate/v2alpha1/subnamespacestatus.go @@ -0,0 +1,38 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v2alpha1 + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// SubNamespaceStatusApplyConfiguration represents an declarative configuration of the SubNamespaceStatus type for use +// with apply. +type SubNamespaceStatusApplyConfiguration struct { + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` + Conditions []v1.Condition `json:"conditions,omitempty"` +} + +// SubNamespaceStatusApplyConfiguration constructs an declarative configuration of the SubNamespaceStatus type for use with +// apply. +func SubNamespaceStatus() *SubNamespaceStatusApplyConfiguration { + return &SubNamespaceStatusApplyConfiguration{} +} + +// WithObservedGeneration sets the ObservedGeneration field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObservedGeneration field is set to the value of the last call. +func (b *SubNamespaceStatusApplyConfiguration) WithObservedGeneration(value int64) *SubNamespaceStatusApplyConfiguration { + b.ObservedGeneration = &value + return b +} + +// WithConditions adds the given value to the Conditions field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Conditions field. +func (b *SubNamespaceStatusApplyConfiguration) WithConditions(values ...v1.Condition) *SubNamespaceStatusApplyConfiguration { + for i := range values { + b.Conditions = append(b.Conditions, values[i]) + } + return b +} diff --git a/internal/applyconfigurations/internal/internal.go b/internal/applyconfigurations/internal/internal.go new file mode 100644 index 0000000..47f29e5 --- /dev/null +++ b/internal/applyconfigurations/internal/internal.go @@ -0,0 +1,46 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package internal + +import ( + "fmt" + "sync" + + typed "sigs.k8s.io/structured-merge-diff/v4/typed" +) + +func Parser() *typed.Parser { + parserOnce.Do(func() { + var err error + parser, err = typed.NewParser(schemaYAML) + if err != nil { + panic(fmt.Sprintf("Failed to parse schema: %v", err)) + } + }) + return parser +} + +var parserOnce sync.Once +var parser *typed.Parser +var schemaYAML = typed.YAMLObject(`types: +- name: __untyped_atomic_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic +- name: __untyped_deduced_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_deduced_ + elementRelationship: separable +`) diff --git a/internal/applyconfigurations/utils.go b/internal/applyconfigurations/utils.go new file mode 100644 index 0000000..12c4ea3 --- /dev/null +++ b/internal/applyconfigurations/utils.go @@ -0,0 +1,25 @@ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package applyconfigurations + +import ( + v2alpha1 "github.com/cybozu-go/accurate/api/accurate/v2alpha1" + accuratev2alpha1 "github.com/cybozu-go/accurate/internal/applyconfigurations/accurate/v2alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" +) + +// ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no +// apply configuration type exists for the given GroupVersionKind. +func ForKind(kind schema.GroupVersionKind) interface{} { + switch kind { + // Group=accurate.cybozu.com, Version=v2alpha1 + case v2alpha1.SchemeGroupVersion.WithKind("SubNamespace"): + return &accuratev2alpha1.SubNamespaceApplyConfiguration{} + case v2alpha1.SchemeGroupVersion.WithKind("SubNamespaceSpec"): + return &accuratev2alpha1.SubNamespaceSpecApplyConfiguration{} + case v2alpha1.SchemeGroupVersion.WithKind("SubNamespaceStatus"): + return &accuratev2alpha1.SubNamespaceStatusApplyConfiguration{} + + } + return nil +}