Skip to content

Commit

Permalink
chore: remove the duplicate sdk generation step and add DeepCopy() fu…
Browse files Browse the repository at this point in the history
…ncs for objects nested in upstream
  • Loading branch information
pmalek committed Sep 11, 2024
1 parent 383f443 commit e2ea160
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ management:
docVersion: 0.0.1
speakeasyVersion: 1.395.1
generationVersion: 2.415.0
releaseVersion: 0.0.10
configChecksum: 9af03c8a70d2f582b3eaf303f0b9cc73
releaseVersion: 0.0.11
configChecksum: 960eed39d63bfb5d5a60adbf86f56c5c
features:
go:
additionalDependencies: 0.1.0
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
go:
version: 0.0.10
version: 0.0.11
additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false
clientServerStatusCodesAsErrors: true
Expand Down
46 changes: 28 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,18 @@ KUBEBUILDER_GENERATE_CODE_MARKER = +kubebuilder:object:generate=true

.PHONY: generate.deepcopy
generate.deepcopy: controller-gen
# Generate deepcopy/runtime.Object implementations for a particular file
$(CONTROLLER_GEN) object paths=./models/components/

# NOTE: We call speakeasy twice to generate DeepCopy() for the types that need it.
# The generation is called twice because we want to generate the zz_generated.deepcopy.go
# file for the types that need DeepCopy() to be generated but to not include
# the related code markers in the generated sdk source code or docs.
# NOTE: add more types that need to have DeepCopy() generated.
.PHONY: generate.sdk
generate.sdk:
yq --inplace '.components.schemas.CreateControlPlaneRequest.description += "\n$(KUBEBUILDER_GENERATE_CODE_MARKER)"' $(OPENAPI_FILE)
yq --inplace '.components.schemas.CreateServiceWithoutParents.description += "\n$(KUBEBUILDER_GENERATE_CODE_MARKER)"' $(OPENAPI_FILE)
yq --inplace '.components.schemas.RouteWithoutParents.description += "\n$(KUBEBUILDER_GENERATE_CODE_MARKER)"' $(OPENAPI_FILE)

speakeasy generate sdk --lang go --out . --schema ./$(OPENAPI_FILE)
git checkout -- $(SPEAKEASY_DIR)/gen.lock $(SPEAKEASY_DIR)/gen.yaml sdk.go

$(SED) -i 's#\(type CreateControlPlaneRequest struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/createcontrolplanerequest.go
$(SED) -i 's#\(type RouteWithoutParents struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type RouteWithoutParentsDestinations struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/routewithoutparents.go
$(SED) -i 's#\(type Destinations struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type Sources struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type Route struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type RouteService struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/route.go
$(SED) -i 's#\(type RouteWithoutParentsSources struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
Expand All @@ -74,9 +63,22 @@ generate.sdk:
models/components/upstream.go
$(SED) -i 's#\(type Healthchecks struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Active struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Passive struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type UpstreamHealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Healthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type UpstreamUnhealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go
$(SED) -i 's#\(type Unhealthy struct\)#// $(KUBEBUILDER_GENERATE_CODE_MARKER)\n\1#g' \
models/components/upstream.go

$(CONTROLLER_GEN) object paths=./models/components/
go mod tidy
$(MAKE) generate.deepcopy

git checkout -- $(OPENAPI_FILE) \
$(shell git ls-files models/components/route*.go) \
$(shell git ls-files docs/models/components/route*.md) \
Expand All @@ -85,5 +87,13 @@ generate.sdk:
$(shell git ls-files models/components/upstream*.go) \
$(shell git ls-files docs/models/components/upstream*.md) \
$(shell git ls-files docs/models/components/healthchecks*.md)

# NOTE: SDK generation consists of adding the kubebuilder code marker and generating
# DeepCopy() for the types that need it and then using speakeasy to generate
# the final sdk code.
# NOTE: add more types that need to have DeepCopy() generated.
.PHONY: generate.sdk
generate.sdk:
$(MAKE) generate.deepcopy
speakeasy generate sdk --lang go --out . --schema ./$(OPENAPI_FILE)
go mod tidy
222 changes: 222 additions & 0 deletions models/components/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,68 @@ package components

import ()

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Active) DeepCopyInto(out *Active) {
*out = *in
if in.Concurrency != nil {
in, out := &in.Concurrency, &out.Concurrency
*out = new(int64)
**out = **in
}
if in.Headers != nil {
in, out := &in.Headers, &out.Headers
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Healthy != nil {
in, out := &in.Healthy, &out.Healthy
*out = new(Healthy)
(*in).DeepCopyInto(*out)
}
if in.HTTPPath != nil {
in, out := &in.HTTPPath, &out.HTTPPath
*out = new(string)
**out = **in
}
if in.HTTPSSni != nil {
in, out := &in.HTTPSSni, &out.HTTPSSni
*out = new(string)
**out = **in
}
if in.HTTPSVerifyCertificate != nil {
in, out := &in.HTTPSVerifyCertificate, &out.HTTPSVerifyCertificate
*out = new(bool)
**out = **in
}
if in.Timeout != nil {
in, out := &in.Timeout, &out.Timeout
*out = new(float64)
**out = **in
}
if in.Type != nil {
in, out := &in.Type, &out.Type
*out = new(Type)
**out = **in
}
if in.Unhealthy != nil {
in, out := &in.Unhealthy, &out.Unhealthy
*out = new(Unhealthy)
(*in).DeepCopyInto(*out)
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Active.
func (in *Active) DeepCopy() *Active {
if in == nil {
return nil
}
out := new(Active)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CreateControlPlaneRequest) DeepCopyInto(out *CreateControlPlaneRequest) {
*out = *in
Expand Down Expand Up @@ -108,6 +170,66 @@ func (in *Healthchecks) DeepCopy() *Healthchecks {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Healthy) DeepCopyInto(out *Healthy) {
*out = *in
if in.HTTPStatuses != nil {
in, out := &in.HTTPStatuses, &out.HTTPStatuses
*out = make([]int64, len(*in))
copy(*out, *in)
}
if in.Interval != nil {
in, out := &in.Interval, &out.Interval
*out = new(float64)
**out = **in
}
if in.Successes != nil {
in, out := &in.Successes, &out.Successes
*out = new(int64)
**out = **in
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Healthy.
func (in *Healthy) DeepCopy() *Healthy {
if in == nil {
return nil
}
out := new(Healthy)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Passive) DeepCopyInto(out *Passive) {
*out = *in
if in.Healthy != nil {
in, out := &in.Healthy, &out.Healthy
*out = new(UpstreamHealthy)
(*in).DeepCopyInto(*out)
}
if in.Type != nil {
in, out := &in.Type, &out.Type
*out = new(UpstreamType)
**out = **in
}
if in.Unhealthy != nil {
in, out := &in.Unhealthy, &out.Unhealthy
*out = new(UpstreamUnhealthy)
(*in).DeepCopyInto(*out)
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Passive.
func (in *Passive) DeepCopy() *Passive {
if in == nil {
return nil
}
out := new(Passive)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Route) DeepCopyInto(out *Route) {
*out = *in
Expand Down Expand Up @@ -546,6 +668,46 @@ func (in *Sources) DeepCopy() *Sources {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Unhealthy) DeepCopyInto(out *Unhealthy) {
*out = *in
if in.HTTPFailures != nil {
in, out := &in.HTTPFailures, &out.HTTPFailures
*out = new(int64)
**out = **in
}
if in.HTTPStatuses != nil {
in, out := &in.HTTPStatuses, &out.HTTPStatuses
*out = make([]int64, len(*in))
copy(*out, *in)
}
if in.Interval != nil {
in, out := &in.Interval, &out.Interval
*out = new(float64)
**out = **in
}
if in.TCPFailures != nil {
in, out := &in.TCPFailures, &out.TCPFailures
*out = new(int64)
**out = **in
}
if in.Timeouts != nil {
in, out := &in.Timeouts, &out.Timeouts
*out = new(int64)
**out = **in
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Unhealthy.
func (in *Unhealthy) DeepCopy() *Unhealthy {
if in == nil {
return nil
}
out := new(Unhealthy)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *UpstreamClientCertificate) DeepCopyInto(out *UpstreamClientCertificate) {
*out = *in
Expand All @@ -565,3 +727,63 @@ func (in *UpstreamClientCertificate) DeepCopy() *UpstreamClientCertificate {
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *UpstreamHealthy) DeepCopyInto(out *UpstreamHealthy) {
*out = *in
if in.HTTPStatuses != nil {
in, out := &in.HTTPStatuses, &out.HTTPStatuses
*out = make([]int64, len(*in))
copy(*out, *in)
}
if in.Successes != nil {
in, out := &in.Successes, &out.Successes
*out = new(int64)
**out = **in
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpstreamHealthy.
func (in *UpstreamHealthy) DeepCopy() *UpstreamHealthy {
if in == nil {
return nil
}
out := new(UpstreamHealthy)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *UpstreamUnhealthy) DeepCopyInto(out *UpstreamUnhealthy) {
*out = *in
if in.HTTPFailures != nil {
in, out := &in.HTTPFailures, &out.HTTPFailures
*out = new(int64)
**out = **in
}
if in.HTTPStatuses != nil {
in, out := &in.HTTPStatuses, &out.HTTPStatuses
*out = make([]int64, len(*in))
copy(*out, *in)
}
if in.TCPFailures != nil {
in, out := &in.TCPFailures, &out.TCPFailures
*out = new(int64)
**out = **in
}
if in.Timeouts != nil {
in, out := &in.Timeouts, &out.Timeouts
*out = new(int64)
**out = **in
}
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpstreamUnhealthy.
func (in *UpstreamUnhealthy) DeepCopy() *UpstreamUnhealthy {
if in == nil {
return nil
}
out := new(UpstreamUnhealthy)
in.DeepCopyInto(out)
return out
}
4 changes: 2 additions & 2 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ func New(opts ...SDKOption) *SDK {
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "0.0.1",
SDKVersion: "0.0.10",
SDKVersion: "0.0.11",
GenVersion: "2.415.0",
UserAgent: "speakeasy-sdk/go 0.0.10 2.415.0 0.0.1 github.com/Kong/sdk-konnect-go",
UserAgent: "speakeasy-sdk/go 0.0.11 2.415.0 0.0.1 github.com/Kong/sdk-konnect-go",
Hooks: hooks.New(),
},
}
Expand Down

0 comments on commit e2ea160

Please sign in to comment.