Skip to content

Commit

Permalink
chore(*) generate DeepCopy interfaces (#2222)
Browse files Browse the repository at this point in the history
Enable DeepCopy interface generation for Kubernetes resources. This takes
advantage of the fact that if a type already implementes the DeepCopy
interface, deepcopy-gen will use it. This means that we can wrap the
raw protbuf message fields in a type that supports the interface and
then generate everything else.

This updates #2130.

Signed-off-by: James Peach <james.peach@konghq.com>
(cherry picked from commit fb4d537)

# Conflicts:
#	mk/generate.mk
  • Loading branch information
jpeach authored and mergify-bot committed Jul 5, 2021
1 parent d37c2c7 commit 6a225c8
Show file tree
Hide file tree
Showing 46 changed files with 1,417 additions and 1,466 deletions.
13 changes: 13 additions & 0 deletions mk/generate.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ clean/proto: ## Dev: Remove auto-generated Protobuf files
find $(PROTO_DIR) -name '*.pb.validate.go' -delete

.PHONY: generate
<<<<<<< HEAD
generate: clean/proto protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 protoc/plugins ## Dev: Run code generators
=======
generate: ## Dev: Run code generators
generate: clean/proto protoc/pkg/config/app/kumactl/v1alpha1 protoc/pkg/test/apis/sample/v1alpha1 protoc/plugins resources/mesh generate/deepcopy

.PHONY: resources/mesh
resources/mesh:
$(GO_RUN) ./tools/resource-gen.go -package mesh > pkg/core/resources/apis/mesh/resources.go
>>>>>>> fb4d537c (chore(*) generate DeepCopy interfaces (#2222))

.PHONY: protoc/pkg/config/app/kumactl/v1alpha1
protoc/pkg/config/app/kumactl/v1alpha1:
Expand Down Expand Up @@ -58,3 +67,7 @@ generate/envoy-imports:
echo 'import (' >> ${ENVOY_IMPORTS}
go list github.com/envoyproxy/go-control-plane/... | grep "github.com/envoyproxy/go-control-plane/envoy/" | awk '{printf "\t_ \"%s\"\n", $$1}' >> ${ENVOY_IMPORTS}
echo ')' >> ${ENVOY_IMPORTS}

.PHONY: generate/deepcopy
generate/deepcopy:
$(MAKE) -C pkg/plugins/resources/k8s/native generate
2 changes: 1 addition & 1 deletion pkg/plugins/resources/k8s/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ vet:

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt,year=$$(date +%Y) paths=./api/...

# Build the docker image
docker-build: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ package v1alpha1

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.

// CircuitBreaker defines the desired state of CircuitBreaker
type CircuitBreakerSpec = map[string]interface{}
"github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/pkg/model"
)

// CircuitBreaker is the Schema for the circuitbreaker API
// CircuitBreaker is the Schema for the circuitbreaker API.
//
// +kubebuilder:object:root=true
type CircuitBreaker struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Mesh string `json:"mesh,omitempty"`

Spec CircuitBreakerSpec `json:"spec,omitempty"`
Spec model.RawMessage `json:"spec,omitempty"`
}

// CircuitBreakerList contains a list of CircuitBreaker
// CircuitBreakerList contains a list of CircuitBreaker.
//
// +kubebuilder:object:root=true
type CircuitBreakerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DataplaneInsightStatus defines the observed state of Dataplane
type DataplaneInsightStatus = map[string]interface{}
"github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/pkg/model"
)

// DataplaneInsight is the Schema for the Dataplane Insights API
// DataplaneInsight is the Schema for the Dataplane Insights API.
//
// +kubebuilder:object:root=true
type DataplaneInsight struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Mesh string `json:"mesh,omitempty"`
Status DataplaneInsightStatus `json:"status,omitempty"`
Mesh string `json:"mesh,omitempty"`
Status model.RawMessage `json:"status,omitempty"`
}

// DataplaneInsightList contains a list of Dataplane
// DataplaneInsightList contains a list of Dataplane.
//
// +kubebuilder:object:root=true
type DataplaneInsightList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down

This file was deleted.

17 changes: 10 additions & 7 deletions pkg/plugins/resources/k8s/native/api/v1alpha1/dataplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DataplaneSpec defines the desired state of Dataplane
type DataplaneSpec = map[string]interface{}
"github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/pkg/model"
)

// Dataplane is the Schema for the Dataplane API
// Dataplane is the Schema for the Dataplane API.
//
// +kubebuilder:object:root=true
type Dataplane struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Mesh string `json:"mesh,omitempty"`
Spec DataplaneSpec `json:"spec,omitempty"`
Mesh string `json:"mesh,omitempty"`
Spec model.RawMessage `json:"spec,omitempty"`
}

// DataplaneList contains a list of Dataplane
// DataplaneList contains a list of Dataplane.
//
// +kubebuilder:object:root=true
type DataplaneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ExternalServiceSpec defines the desired state of ExternalService
type ExternalServiceSpec = map[string]interface{}
"github.com/kumahq/kuma/pkg/plugins/resources/k8s/native/pkg/model"
)

// ExternalService is the Schema for the Dataplane API
// ExternalService is the Schema for the ExternalService API.
//
// +kubebuilder:object:root=true
type ExternalService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Mesh string `json:"mesh,omitempty"`
Spec ExternalServiceSpec `json:"spec,omitempty"`
Mesh string `json:"mesh,omitempty"`
Spec model.RawMessage `json:"spec,omitempty"`
}

// ExternalServiceList contains a list of Dataplane
// ExternalServiceList contains a list of ExternalServices.
//
// +kubebuilder:object:root=true
type ExternalServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Loading

0 comments on commit 6a225c8

Please sign in to comment.