Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: optimize routes status unnecessary deepcopy. #4527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 124 additions & 60 deletions internal/provider/kubernetes/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1.HTTPRoute),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 69 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L69

Added line #L69 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API is for mutating obects but is now returning a bool ? this doesnt seem right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this api to boolean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the new definition for the mutator function

h, ok := obj.(*gwapiv1.HTTPRoute)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
hCopy := h.DeepCopy()
hCopy.Status.Parents = val.Parents
return hCopy

if isStatusEqual(h.Status.Parents, val.Parents) {
return true
}

Check warning on line 79 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L77-L79

Added lines #L77 - L79 were not covered by tests

h.Status.Parents = val.Parents
return false

Check warning on line 82 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L81-L82

Added lines #L81 - L82 were not covered by tests
}),
})
},
Expand All @@ -96,16 +100,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1.GRPCRoute),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 103 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L103

Added line #L103 was not covered by tests
h, ok := obj.(*gwapiv1.GRPCRoute)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
hCopy := h.DeepCopy()
hCopy.Status.Parents = val.Parents
return hCopy

if isStatusEqual(h.Status.Parents, val.Parents) {
return true
}

Check warning on line 113 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L111-L113

Added lines #L111 - L113 were not covered by tests

h.Status.Parents = val.Parents
return false

Check warning on line 116 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L115-L116

Added lines #L115 - L116 were not covered by tests
}),
})
},
Expand All @@ -128,16 +136,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1a2.TLSRoute),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 139 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L139

Added line #L139 was not covered by tests
t, ok := obj.(*gwapiv1a2.TLSRoute)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status.Parents = val.Parents
return tCopy

if isStatusEqual(t.Status.Parents, val.Parents) {
return true
}

Check warning on line 149 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L147-L149

Added lines #L147 - L149 were not covered by tests

t.Status.Parents = val.Parents
return false

Check warning on line 152 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L151-L152

Added lines #L151 - L152 were not covered by tests
}),
})
},
Expand All @@ -160,16 +172,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1a2.TCPRoute),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 175 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L175

Added line #L175 was not covered by tests
t, ok := obj.(*gwapiv1a2.TCPRoute)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status.Parents = val.Parents
return tCopy

if isStatusEqual(t.Status.Parents, val.Parents) {
return true
}

Check warning on line 185 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L183-L185

Added lines #L183 - L185 were not covered by tests

t.Status.Parents = val.Parents
return false

Check warning on line 188 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L187-L188

Added lines #L187 - L188 were not covered by tests
}),
})
},
Expand All @@ -192,16 +208,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1a2.UDPRoute),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 211 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L211

Added line #L211 was not covered by tests
t, ok := obj.(*gwapiv1a2.UDPRoute)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status.Parents = val.Parents
return tCopy

if isStatusEqual(t.Status.Parents, val.Parents) {
return true
}

Check warning on line 221 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L219-L221

Added lines #L219 - L221 were not covered by tests

t.Status.Parents = val.Parents
return false

Check warning on line 224 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L223-L224

Added lines #L223 - L224 were not covered by tests
}),
})
},
Expand All @@ -224,16 +244,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.EnvoyPatchPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 247 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L247

Added line #L247 was not covered by tests
t, ok := obj.(*egv1a1.EnvoyPatchPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 257 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L255-L257

Added lines #L255 - L257 were not covered by tests

t.Status = *val
return false

Check warning on line 260 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L259-L260

Added lines #L259 - L260 were not covered by tests
}),
})
},
Expand All @@ -256,16 +280,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.ClientTrafficPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 283 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L283

Added line #L283 was not covered by tests
t, ok := obj.(*egv1a1.ClientTrafficPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 293 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L291-L293

Added lines #L291 - L293 were not covered by tests

t.Status = *val
return false

Check warning on line 296 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L295-L296

Added lines #L295 - L296 were not covered by tests
}),
})
},
Expand All @@ -288,16 +316,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.BackendTrafficPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 319 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L319

Added line #L319 was not covered by tests
t, ok := obj.(*egv1a1.BackendTrafficPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 329 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L327-L329

Added lines #L327 - L329 were not covered by tests

t.Status = *val
return false

Check warning on line 332 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L331-L332

Added lines #L331 - L332 were not covered by tests
}),
})
},
Expand All @@ -320,16 +352,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.SecurityPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 355 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L355

Added line #L355 was not covered by tests
t, ok := obj.(*egv1a1.SecurityPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 365 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L363-L365

Added lines #L363 - L365 were not covered by tests

t.Status = *val
return false

Check warning on line 368 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L367-L368

Added lines #L367 - L368 were not covered by tests
}),
})
},
Expand All @@ -350,16 +386,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1a3.BackendTLSPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 389 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L389

Added line #L389 was not covered by tests
t, ok := obj.(*gwapiv1a3.BackendTLSPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 399 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L397-L399

Added lines #L397 - L399 were not covered by tests

t.Status = *val
return false

Check warning on line 402 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L401-L402

Added lines #L401 - L402 were not covered by tests
}),
})
},
Expand All @@ -382,16 +422,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.EnvoyExtensionPolicy),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 425 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L425

Added line #L425 was not covered by tests
t, ok := obj.(*egv1a1.EnvoyExtensionPolicy)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 435 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L433-L435

Added lines #L433 - L435 were not covered by tests

t.Status = *val
return false

Check warning on line 438 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L437-L438

Added lines #L437 - L438 were not covered by tests
}),
})
},
Expand All @@ -414,16 +458,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(egv1a1.Backend),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 461 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L461

Added line #L461 was not covered by tests
t, ok := obj.(*egv1a1.Backend)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Status = *val
return tCopy

if isStatusEqual(t.Status, *val) {
return true
}

Check warning on line 471 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L469-L471

Added lines #L469 - L471 were not covered by tests

t.Status = *val
return false

Check warning on line 474 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L473-L474

Added lines #L473 - L474 were not covered by tests
}),
})
},
Expand All @@ -450,16 +498,20 @@
r.statusUpdater.Send(Update{
NamespacedName: key.NamespacedName,
Resource: &obj,
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {

Check warning on line 501 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L501

Added line #L501 was not covered by tests
t, ok := obj.(*unstructured.Unstructured)
if !ok {
err := fmt.Errorf("unsupported object type %T", obj)
errChan <- err
panic(err)
}
tCopy := t.DeepCopy()
tCopy.Object["status"] = *val
return tCopy

if isStatusEqual(t.Object["status"], *val) {
return true
}

Check warning on line 511 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L509-L511

Added lines #L509 - L511 were not covered by tests

t.Object["status"] = *val
return false

Check warning on line 514 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L513-L514

Added lines #L513 - L514 were not covered by tests
}),
})
},
Expand Down Expand Up @@ -499,16 +551,22 @@
r.statusUpdater.Send(Update{
NamespacedName: key,
Resource: new(gwapiv1.Gateway),
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {
g, ok := obj.(*gwapiv1.Gateway)
if !ok {
panic(fmt.Sprintf("unsupported object type %T", obj))
}
gCopy := g.DeepCopy()
gCopy.Status.Conditions = gtw.Status.Conditions
gCopy.Status.Addresses = gtw.Status.Addresses
gCopy.Status.Listeners = gtw.Status.Listeners
return gCopy

if isStatusEqual(g.Status.Conditions, gtw.Status.Conditions) &&
isStatusEqual(g.Status.Addresses, gtw.Status.Addresses) &&
isStatusEqual(g.Status.Listeners, gtw.Status.Listeners) {
return true
}

Check warning on line 564 in internal/provider/kubernetes/status.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/status.go#L563-L564

Added lines #L563 - L564 were not covered by tests

g.Status.Conditions = gtw.Status.Conditions
g.Status.Addresses = gtw.Status.Addresses
g.Status.Listeners = gtw.Status.Listeners
return false
}),
})
}
Expand All @@ -524,13 +582,19 @@
r.statusUpdater.Send(Update{
NamespacedName: types.NamespacedName{Name: gc.Name},
Resource: &gwapiv1.GatewayClass{},
Mutator: MutatorFunc(func(obj client.Object) client.Object {
Mutator: MutatorFunc(func(obj client.Object) bool {
gc, ok := obj.(*gwapiv1.GatewayClass)
if !ok {
panic(fmt.Sprintf("unsupported object type %T", obj))
}

return status.SetGatewayClassAccepted(gc.DeepCopy(), accepted, reason, msg)
gcp := status.SetGatewayClassAccepted(gc.DeepCopy(), accepted, reason, msg)
if isStatusEqual(gcp.Status, gc.Status) {
return true
}

gc.Status = gcp.Status
return false
}),
})
} else {
Expand Down
Loading