Refactor extraction of ingress pod details
This commit is contained in:
parent
b482b5dd32
commit
1389cc0e80
9 changed files with 99 additions and 68 deletions
|
|
@ -154,7 +154,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
|||
n.metricCollector.IncReloadErrorCount()
|
||||
n.metricCollector.ConfigSuccess(hash, false)
|
||||
klog.Errorf("Unexpected failure reloading the backend:\n%v", err)
|
||||
n.recorder.Eventf(k8s.IngressNGINXPod, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
|
||||
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeWarning, "RELOAD", fmt.Sprintf("Error reloading NGINX: %v", err))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ func (n *NGINXController) syncIngress(interface{}) error {
|
|||
n.metricCollector.ConfigSuccess(hash, true)
|
||||
n.metricCollector.IncReloadCount()
|
||||
|
||||
n.recorder.Eventf(k8s.IngressNGINXPod, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
|
||||
n.recorder.Eventf(k8s.IngressPodDetails, apiv1.EventTypeNormal, "RELOAD", "NGINX reload triggered due to a change in configuration")
|
||||
}
|
||||
|
||||
isFirstSync := n.runningConfig.Equal(&ingress.Configuration{})
|
||||
|
|
|
|||
|
|
@ -1671,7 +1671,7 @@ func newNGINXController(t *testing.T) *NGINXController {
|
|||
t.Fatalf("error creating the configuration map: %v", err)
|
||||
}
|
||||
|
||||
k8s.IngressNGINXPod = &v1.Pod{
|
||||
k8s.IngressPodDetails = &k8s.PodInfo{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "testpod",
|
||||
Namespace: ns,
|
||||
|
|
@ -1729,7 +1729,7 @@ func newDynamicNginxController(t *testing.T, setConfigMap func(string) *v1.Confi
|
|||
t.Fatalf("error creating the configuration map: %v", err)
|
||||
}
|
||||
|
||||
k8s.IngressNGINXPod = &v1.Pod{
|
||||
k8s.IngressPodDetails = &k8s.PodInfo{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "testpod",
|
||||
Namespace: ns,
|
||||
|
|
|
|||
|
|
@ -93,23 +93,18 @@ func setupLeaderElection(config *leaderElectionConfig) {
|
|||
Host: hostname,
|
||||
})
|
||||
|
||||
ingressPod, err := k8s.GetPodDetails()
|
||||
if err != nil {
|
||||
klog.Fatalf("unexpected error starting leader election: %v", err)
|
||||
}
|
||||
|
||||
lock := resourcelock.ConfigMapLock{
|
||||
ConfigMapMeta: metav1.ObjectMeta{Namespace: ingressPod.Namespace, Name: config.ElectionID},
|
||||
ConfigMapMeta: metav1.ObjectMeta{Namespace: k8s.IngressPodDetails.Namespace, Name: config.ElectionID},
|
||||
Client: config.Client.CoreV1(),
|
||||
LockConfig: resourcelock.ResourceLockConfig{
|
||||
Identity: ingressPod.Name,
|
||||
Identity: k8s.IngressPodDetails.Name,
|
||||
EventRecorder: recorder,
|
||||
},
|
||||
}
|
||||
|
||||
ttl := 30 * time.Second
|
||||
|
||||
elector, err = leaderelection.NewLeaderElector(leaderelection.LeaderElectionConfig{
|
||||
elector, err := leaderelection.NewLeaderElector(leaderelection.LeaderElectionConfig{
|
||||
Lock: &lock,
|
||||
LeaseDuration: ttl,
|
||||
RenewDeadline: ttl / 2,
|
||||
|
|
|
|||
|
|
@ -172,14 +172,9 @@ func (s *statusSync) runningAddresses() ([]string, error) {
|
|||
return statusAddressFromService(s.PublishService, s.Client)
|
||||
}
|
||||
|
||||
ingressPod, err := k8s.GetPodDetails()
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
// get information about all the pods running the ingress controller
|
||||
pods, err := s.Client.CoreV1().Pods(ingressPod.Namespace).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(ingressPod.Labels).String(),
|
||||
pods, err := s.Client.CoreV1().Pods(k8s.IngressPodDetails.Namespace).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(k8s.IngressPodDetails.Labels).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -216,13 +211,8 @@ func (s *statusSync) runningAddresses() ([]string, error) {
|
|||
}
|
||||
|
||||
func (s *statusSync) isRunningMultiplePods() bool {
|
||||
ingressPod, err := k8s.GetPodDetails()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
pods, err := s.Client.CoreV1().Pods(ingressPod.Namespace).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(ingressPod.Labels).String(),
|
||||
pods, err := s.Client.CoreV1().Pods(k8s.IngressPodDetails.Namespace).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(k8s.IngressPodDetails.Labels).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"time"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
testclient "k8s.io/client-go/kubernetes/fake"
|
||||
|
|
@ -297,7 +296,7 @@ func TestStatusActions(t *testing.T) {
|
|||
UpdateStatusOnShutdown: true,
|
||||
}
|
||||
|
||||
k8s.IngressNGINXPod = &v1.Pod{
|
||||
k8s.IngressPodDetails = &k8s.PodInfo{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo_base_pod",
|
||||
Namespace: apiv1.NamespaceDefault,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue