Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
More efficient app endpoints retrieval. (#952) (#1869)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Tkachenko <[email protected]>
  • Loading branch information
Sergei Antipov and r0mant authored Jul 15, 2020
1 parent c822d66 commit dec4cf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lib/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ const (

// KubeSystemNamespace is a k8s namespace
KubeSystemNamespace = "kube-system"
// AllNamespaces is the filter to search across all namespaces
AllNamespaces = ""

// GrafanaContextCookie hold the name of the cluster used in
// certain web handlers to determine the currently selected domain without including it
Expand Down
27 changes: 8 additions & 19 deletions lib/ops/opsservice/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
"github.com/gravitational/gravity/lib/ops"
"github.com/gravitational/gravity/lib/utils"

"github.com/gravitational/rigging"
"github.com/gravitational/trace"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -71,11 +72,7 @@ func (o *Operator) GetApplicationEndpoints(key ops.SiteKey) ([]ops.Endpoint, err
}

// query for nodes, we might need them later on
nodeList, err := client.Core().Nodes().List(metav1.ListOptions{})
if err != nil {
return nil, trace.Wrap(err)
}
namespaceList, err := client.Core().Namespaces().List(metav1.ListOptions{})
nodeList, err := client.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return nil, trace.Wrap(err)
}
Expand All @@ -86,19 +83,11 @@ func (o *Operator) GetApplicationEndpoints(key ops.SiteKey) ([]ops.Endpoint, err
continue
}

var serviceList *v1.ServiceList
for _, ns := range namespaceList.Items {
services, err := client.Core().Services(ns.Name).List(metav1.ListOptions{
LabelSelector: utils.MakeSelector(e.Selector).String(),
})
if err != nil {
return nil, trace.Wrap(err)
}
if serviceList == nil {
serviceList = services
} else {
serviceList.Items = append(serviceList.Items, services.Items...)
}
serviceList, err := client.CoreV1().Services(constants.AllNamespaces).List(metav1.ListOptions{
LabelSelector: utils.MakeSelector(e.Selector).String(),
})
if err != nil {
return nil, rigging.ConvertError(err)
}

if serviceList == nil {
Expand Down

0 comments on commit dec4cf8

Please sign in to comment.