Fix selector for shutting down Pods (#7727)

* Fix selector for shutting down Pods

* Add autogenerated labels for daemonset in exception

Co-authored-by: Jintao Zhang <tao12345666333@163.com>

Co-authored-by: Jintao Zhang <tao12345666333@163.com>
This commit is contained in:
Ricardo Katz 2021-09-30 01:10:09 -03:00 committed by GitHub
parent 3224e7192f
commit 37ab9991e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -226,8 +226,21 @@ func (s *statusSync) runningAddresses() ([]apiv1.LoadBalancerIngress, error) {
} }
func (s *statusSync) isRunningMultiplePods() bool { func (s *statusSync) isRunningMultiplePods() bool {
// As a standard, app.kubernetes.io are "reserved well-known" labels.
// In our case, we add those labels as identifiers of the Ingress
// deployment in this namespace, so we can select it as a set of Ingress instances.
// As those labels are also generated as part of a HELM deployment, we can be "safe" they
// cover 95% of the cases
podLabel := make(map[string]string)
for k, v := range k8s.IngressPodDetails.Labels {
if k != "pod-template-hash" && k != "controller-revision-hash" && k != "pod-template-generation" {
podLabel[k] = v
}
}
pods, err := s.Client.CoreV1().Pods(k8s.IngressPodDetails.Namespace).List(context.TODO(), metav1.ListOptions{ pods, err := s.Client.CoreV1().Pods(k8s.IngressPodDetails.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(k8s.IngressPodDetails.Labels).String(), LabelSelector: labels.SelectorFromSet(podLabel).String(),
}) })
if err != nil { if err != nil {
return false return false