Commit 58b58d36 authored by Jens Langhammer's avatar Jens Langhammer

tier0: correctly lookup GRPC ClusterIP

parent 571c247d
Pipeline #3874 passed with stage
in 1 minute and 58 seconds
......@@ -23,19 +23,19 @@ func main() {
log.SetLevel(log.DebugLevel)
log.Debugf("Starting p2-tier0 Version %s", internal.Version)
k8sc, err := k8s.NewKubernetesContext()
webClusterIP := "localhost"
grpcClusterIP := "localhost"
if err != nil {
log.Warning(err)
} else {
webClusterIP, err = k8sc.WebClusterIP()
grpcClusterIP, err = k8sc.GetGRPCClusterIP()
if err != nil {
log.Warning(err)
log.Debugf("Falling back to default Web ClusterIP %s", webClusterIP)
log.Debugf("Falling back to default GRPC ClusterIP %s", grpcClusterIP)
}
}
// Central stopping channel
stop := make(chan struct{})
upstream := p2.NewGRPCUpstream(fmt.Sprintf("%s:50051", webClusterIP))
upstream := p2.NewGRPCUpstream(fmt.Sprintf("%s:50051", grpcClusterIP))
localCache := cache.NewCache(upstream)
localCache.SetPeersFromKubernetes(k8sc)
// Update Cache Peers by watching k8s
......
......@@ -60,9 +60,9 @@ func (k8sc *KubernetesContext) PodsForComponent(component string) *v1.PodList {
return pods
}
// WebClusterIP Get ClusterIP to access p2 server
func (k8sc *KubernetesContext) WebClusterIP() (string, error) {
labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{"k8s.p2.io/component": "web"}}
// GetGRPCClusterIP Get ClusterIP to access p2 server
func (k8sc *KubernetesContext) GetGRPCClusterIP() (string, error) {
labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{"k8s.p2.io/component": "grpc"}}
services, err := k8sc.CoreV1().Services(k8sc.Namespace).List(metav1.ListOptions{
LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
})
......@@ -75,6 +75,6 @@ func (k8sc *KubernetesContext) WebClusterIP() (string, error) {
k8sc.Logger.Warning(err)
return "", err
}
k8sc.Logger.Debugf("Found p2 web ClusterIP: %s", services.Items[0].Spec.ClusterIP)
k8sc.Logger.Debugf("Found p2 GRPC ClusterIP: %s", services.Items[0].Spec.ClusterIP)
return services.Items[0].Spec.ClusterIP, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment