-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
There was a problem hiding this 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
pkg/controller/ingress-controller.go
Outdated
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, | ||
}}, | ||
}, | ||
) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
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?