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

Check for existing ingress when appending to status #89

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

UnstoppableMango
Copy link
Contributor

Check for an existing ingress matching the hostname before blindly appending it to the status.
Should resolve #88
Is it worthwhile to remove duplicates for anyone that may have been affected by this?

Copy link
Owner

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

Hi @UnstoppableMango , thanks for your contribution! PTAL

Comment on lines 102 to 118
origin.Status.LoadBalancer.Ingress = append(origin.Status.LoadBalancer.Ingress,
networkingv1.IngressLoadBalancerIngress{
Hostname: i.tunnelClient.TunnelDomain(),
Ports: []networkingv1.IngressPortStatus{{
Protocol: v1.ProtocolTCP,
Port: 443,
}},
},
)
hostname := i.tunnelClient.TunnelDomain()
matchesHostname := func(ingress networkingv1.IngressLoadBalancerIngress) bool {
return ingress.Hostname == hostname
}
if !slices.ContainsFunc(origin.Status.LoadBalancer.Ingress, matchesHostname) {
origin.Status.LoadBalancer.Ingress = append(origin.Status.LoadBalancer.Ingress,
networkingv1.IngressLoadBalancerIngress{
Hostname: hostname,
Ports: []networkingv1.IngressPortStatus{{
Protocol: v1.ProtocolTCP,
Port: 443,
}},
},
)
}
Copy link
Owner

Choose a reason for hiding this comment

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

the kubernetes controller / operator works as a observe -> reconcile -> update status pattern, so it's better to regenerate Ingress array every time, instead of append to the origin slice.

also, there are other best practices (which are picky) like:

  • always deep copy the oiring object before call the .Update method
  • only update Status subresource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok awesome, I think I've got it. Does that look better? I really appreciate your patience!

Copy link
Owner

@STRRL STRRL Jun 2, 2024

Choose a reason for hiding this comment

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

one more step, please call DeepCopy before change the value of Ingress field

rest looks good to me! Thanks!

@STRRL STRRL merged commit f8d799d into STRRL:master Jun 3, 2024
3 checks passed
@UnstoppableMango UnstoppableMango deleted the duplicate-status branch June 3, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate records repeatedly added to Ingress.status.loadBalancer.ingress
2 participants