Skip to content

Commit

Permalink
chore: generate applyconfigurations for APIs (SSA)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Nov 11, 2023
1 parent 07b61c1 commit a2d9cc9
Show file tree
Hide file tree
Showing 41 changed files with 1,028 additions and 36 deletions.
27 changes: 24 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ 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)
Expand Down Expand Up @@ -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/[email protected]

# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions api/accurate/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +kubebuilder:object:generate=true
// +groupName=accurate.cybozu.com
package v1
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions api/accurate/v2alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +kubebuilder:object:generate=true
// +groupName=accurate.cybozu.com
package v2alpha1
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/accurate-controller/sub/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/sub_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/sub_cut.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/sub_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/sub_graft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/sub_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-accurate/sub/util.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/namespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/subnamespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/subnamespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit a2d9cc9

Please sign in to comment.