Skip to content

Commit d924fdf

Browse files
authored
fix: create a new map when deep copy (#35)
Signed-off-by: Nic <qianyong@api7.ai>
1 parent 0a345d4 commit d924fdf

7 files changed

Lines changed: 167 additions & 154 deletions

File tree

.github/workflows/e2e-test-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323
branches:
2424
- master
2525
pull_request:
26+
types: [opened, synchronize, reopened, ready_for_review, labeled]
2627
branches:
2728
- master
2829
- release/1.8

pkg/kube/apisix/apis/config/v2/types.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,6 @@ type ApisixRoutePlugin struct {
176176
SecretRef string `json:"secretRef" yaml:"secretRef"`
177177
}
178178

179-
func (in *ApisixRoutePlugin) DeepCopyInto(out *ApisixRoutePlugin) {
180-
*out = *in
181-
out.Config = ApisixRoutePluginConfig{}
182-
in.Config.DeepCopyInto(&out.Config)
183-
}
184-
185179
// ApisixRoutePluginConfig is the configuration for
186180
// any plugins.
187181
type ApisixRoutePluginConfig map[string]interface{}
@@ -191,12 +185,12 @@ func (p ApisixRoutePluginConfig) DeepCopyInto(out *ApisixRoutePluginConfig) {
191185
_ = json.Unmarshal(b, out)
192186
}
193187

194-
func (p *ApisixRoutePluginConfig) DeepCopy() *ApisixRoutePluginConfig {
188+
func (p ApisixRoutePluginConfig) DeepCopy() ApisixRoutePluginConfig {
195189
if p == nil {
196190
return nil
197191
}
198-
out := new(ApisixRoutePluginConfig)
199-
p.DeepCopyInto(out)
192+
out := make(ApisixRoutePluginConfig)
193+
p.DeepCopyInto(&out)
200194
return out
201195
}
202196

@@ -692,14 +686,6 @@ type Plugin struct {
692686
ConfigSet ConfigSet `json:"config_set,omitempty" yaml:"config_set,omitempty"`
693687
}
694688

695-
func (in *Plugin) DeepCopyInto(out *Plugin) {
696-
*out = *in
697-
out.Config = Config{}
698-
out.ConfigSet = ConfigSet{}
699-
in.Config.DeepCopyInto(&out.Config)
700-
in.ConfigSet.DeepCopyInto(&out.ConfigSet)
701-
}
702-
703689
type ConfigSet []interface{}
704690

705691
func (p ConfigSet) DeepCopyInto(out *ConfigSet) {
@@ -723,12 +709,12 @@ func (p Config) DeepCopyInto(out *Config) {
723709
_ = json.Unmarshal(b, out)
724710
}
725711

726-
func (p *Config) DeepCopy() *Config {
712+
func (p Config) DeepCopy() Config {
727713
if p == nil {
728714
return nil
729715
}
730-
out := new(Config)
731-
p.DeepCopyInto(out)
716+
out := make(Config)
717+
p.DeepCopyInto(&out)
732718
return out
733719
}
734720

pkg/kube/apisix/apis/config/v2/zz_generated.deepcopy.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/providers/ingress/translation/translator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (t *translator) translateIngressV1(ing *networkingv1.Ingress, skipVerify bo
271271
route.Priority = _regexPriority
272272
}
273273
if len(ingress.Plugins) > 0 {
274-
route.Plugins = *(ingress.Plugins.DeepCopy())
274+
route.Plugins = ingress.Plugins.DeepCopy()
275275
}
276276

277277
if ingress.PluginConfigName != "" {
@@ -376,7 +376,7 @@ func (t *translator) translateIngressV1beta1(ing *networkingv1beta1.Ingress, ski
376376
route.Priority = _regexPriority
377377
}
378378
if len(ingress.Plugins) > 0 {
379-
route.Plugins = *(ingress.Plugins.DeepCopy())
379+
route.Plugins = ingress.Plugins.DeepCopy()
380380
}
381381
if ingress.Upstream.Retry > 0 {
382382
retry := ingress.Upstream.Retry

pkg/types/apisix/v1/plugin_types.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ type RewriteConfig struct {
142142
Headers Headers `json:"headers,omitempty"`
143143
}
144144

145-
func (in *RewriteConfig) DeepCopyInto(out *RewriteConfig) {
146-
*out = *in
147-
out.Headers = Headers{}
148-
if in.RewriteTargetRegex != nil {
149-
in, out := &in.RewriteTargetRegex, &out.RewriteTargetRegex
150-
*out = make([]string, len(*in))
151-
copy(*out, *in)
152-
}
153-
in.Headers.DeepCopyInto(&out.Headers)
154-
}
155-
156145
// ResponseRewriteConfig is the rule config for response-rewrite plugin.
157146
// +k8s:deepcopy-gen=true
158147
type ResponseRewriteConfig struct {
@@ -164,32 +153,6 @@ type ResponseRewriteConfig struct {
164153
Filters []map[string]string `json:"filters,omitempty"`
165154
}
166155

167-
func (in *ResponseRewriteConfig) DeepCopyInto(out *ResponseRewriteConfig) {
168-
*out = *in
169-
out.Headers = Headers{}
170-
in.Headers.DeepCopyInto(&out.Headers)
171-
if in.LuaRestyExpr != nil {
172-
in, out := &in.LuaRestyExpr, &out.LuaRestyExpr
173-
*out = make([]expr.Expr, len(*in))
174-
for i := range *in {
175-
(*in)[i].DeepCopyInto(&(*out)[i])
176-
}
177-
}
178-
if in.Filters != nil {
179-
in, out := &in.Filters, &out.Filters
180-
*out = make([]map[string]string, len(*in))
181-
for i := range *in {
182-
if (*in)[i] != nil {
183-
in, out := &(*in)[i], &(*out)[i]
184-
*out = make(map[string]string, len(*in))
185-
for key, val := range *in {
186-
(*out)[key] = val
187-
}
188-
}
189-
}
190-
}
191-
}
192-
193156
// RedirectConfig is the rule config for redirect plugin.
194157
// +k8s:deepcopy-gen=true
195158
type RedirectConfig struct {
@@ -231,12 +194,12 @@ func (p *Headers) DeepCopyInto(out *Headers) {
231194
_ = json.Unmarshal(b, out)
232195
}
233196

234-
func (p *Headers) DeepCopy() *Headers {
197+
func (p Headers) DeepCopy() Headers {
235198
if p == nil {
236199
return nil
237200
}
238-
out := new(Headers)
239-
p.DeepCopyInto(out)
201+
out := make(Headers)
202+
p.DeepCopyInto(&out)
240203
return out
241204
}
242205

pkg/types/apisix/v1/types.go

Lines changed: 3 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -123,51 +123,6 @@ type Route struct {
123123
FilterFunc string `json:"filter_func,omitempty" yaml:"filter_func,omitempty"`
124124
}
125125

126-
func (in *Route) DeepCopyInto(out *Route) {
127-
*out = *in
128-
out.Plugins = Plugins{}
129-
in.Metadata.DeepCopyInto(&out.Metadata)
130-
if in.Hosts != nil {
131-
in, out := &in.Hosts, &out.Hosts
132-
*out = make([]string, len(*in))
133-
copy(*out, *in)
134-
}
135-
if in.Timeout != nil {
136-
in, out := &in.Timeout, &out.Timeout
137-
*out = new(UpstreamTimeout)
138-
**out = **in
139-
}
140-
if in.Vars != nil {
141-
in, out := &in.Vars, &out.Vars
142-
*out = make(Vars, len(*in))
143-
for i := range *in {
144-
if (*in)[i] != nil {
145-
in, out := &(*in)[i], &(*out)[i]
146-
*out = make([]StringOrSlice, len(*in))
147-
for i := range *in {
148-
(*in)[i].DeepCopyInto(&(*out)[i])
149-
}
150-
}
151-
}
152-
}
153-
if in.Uris != nil {
154-
in, out := &in.Uris, &out.Uris
155-
*out = make([]string, len(*in))
156-
copy(*out, *in)
157-
}
158-
if in.Methods != nil {
159-
in, out := &in.Methods, &out.Methods
160-
*out = make([]string, len(*in))
161-
copy(*out, *in)
162-
}
163-
if in.RemoteAddrs != nil {
164-
in, out := &in.RemoteAddrs, &out.RemoteAddrs
165-
*out = make([]string, len(*in))
166-
copy(*out, *in)
167-
}
168-
in.Plugins.DeepCopyInto(&out.Plugins)
169-
}
170-
171126
// Vars represents the route match expressions of APISIX.
172127
type Vars [][]StringOrSlice
173128

@@ -232,12 +187,12 @@ func (p *Plugins) DeepCopyInto(out *Plugins) {
232187
_ = json.Unmarshal(b, out)
233188
}
234189

235-
func (p *Plugins) DeepCopy() *Plugins {
190+
func (p Plugins) DeepCopy() Plugins {
236191
if p == nil {
237192
return nil
238193
}
239-
out := new(Plugins)
240-
p.DeepCopyInto(out)
194+
out := make(Plugins)
195+
p.DeepCopyInto(&out)
241196
return out
242197
}
243198

@@ -532,37 +487,13 @@ type StreamRoute struct {
532487
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
533488
}
534489

535-
func (in *StreamRoute) DeepCopyInto(out *StreamRoute) {
536-
*out = *in
537-
out.Plugins = Plugins{}
538-
if in.Labels != nil {
539-
in, out := &in.Labels, &out.Labels
540-
*out = make(map[string]string, len(*in))
541-
for key, val := range *in {
542-
(*out)[key] = val
543-
}
544-
}
545-
if in.Upstream != nil {
546-
in, out := &in.Upstream, &out.Upstream
547-
*out = new(Upstream)
548-
(*in).DeepCopyInto(*out)
549-
}
550-
in.Plugins.DeepCopyInto(&out.Plugins)
551-
}
552-
553490
// GlobalRule represents the global_rule object in APISIX.
554491
// +k8s:deepcopy-gen=true
555492
type GlobalRule struct {
556493
ID string `json:"id" yaml:"id"`
557494
Plugins Plugins `json:"plugins" yaml:"plugins"`
558495
}
559496

560-
func (in *GlobalRule) DeepCopyInto(out *GlobalRule) {
561-
*out = *in
562-
out.Plugins = Plugins{}
563-
in.Plugins.DeepCopyInto(&out.Plugins)
564-
}
565-
566497
// Consumer represents the consumer object in APISIX.
567498
// +k8s:deepcopy-gen=true
568499
type Consumer struct {
@@ -572,33 +503,13 @@ type Consumer struct {
572503
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
573504
}
574505

575-
func (in *Consumer) DeepCopyInto(out *Consumer) {
576-
*out = *in
577-
out.Plugins = Plugins{}
578-
if in.Labels != nil {
579-
in, out := &in.Labels, &out.Labels
580-
*out = make(map[string]string, len(*in))
581-
for key, val := range *in {
582-
(*out)[key] = val
583-
}
584-
}
585-
in.Plugins.DeepCopyInto(&out.Plugins)
586-
}
587-
588506
// PluginConfig apisix plugin object
589507
// +k8s:deepcopy-gen=true
590508
type PluginConfig struct {
591509
Metadata `json:",inline" yaml:",inline"`
592510
Plugins Plugins `json:"plugins" yaml:"plugins"`
593511
}
594512

595-
func (in *PluginConfig) DeepCopyInto(out *PluginConfig) {
596-
*out = *in
597-
out.Plugins = Plugins{}
598-
in.Metadata.DeepCopyInto(&out.Metadata)
599-
in.Plugins.DeepCopyInto(&out.Plugins)
600-
}
601-
602513
type PluginMetadata struct {
603514
Name string
604515
Metadata map[string]any

0 commit comments

Comments
 (0)