Skip to content

Commit

Permalink
Forward to leader via its pod ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Apr 13, 2023
1 parent 175e17b commit 4818cd3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/sapcc/maintenance-controller/cache"
"github.com/sapcc/maintenance-controller/constants"
coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -167,7 +168,13 @@ func (s *Server) fetchInfo(w http.ResponseWriter) {
}
holder := *lease.Spec.HolderIdentity
leader := strings.Split(holder, "_")[0]
addr := net.JoinHostPort(leader, "8080")
var pod corev1.Pod
err = s.Client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: leader}, &pod)
if err != nil {
s.writeError(err, w)
return
}
addr := net.JoinHostPort(pod.Status.PodIP, "8080")
url := fmt.Sprintf("http://%s/api/v1/info", addr)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down

0 comments on commit 4818cd3

Please sign in to comment.