Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port name to service struct used in minikube service #4011

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions pkg/minikube/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,36 @@ func printURLsForService(c corev1.CoreV1Interface, ip, service, namespace string
if err != nil {
return nil, errors.Wrapf(err, "service '%s' could not be found running", service)
}
var nodePorts []int32
if len(svc.Spec.Ports) > 0 {
for _, port := range svc.Spec.Ports {
if port.NodePort > 0 {
nodePorts = append(nodePorts, port.NodePort)

e := c.Endpoints(namespace)
endpoints, err := e.Get(service, metav1.GetOptions{})
m := make(map[int32]string)
if endpoints != nil && len(endpoints.Subsets) > 0 {
for _, ept := range endpoints.Subsets {
for _, p := range ept.Ports {
m[int32(p.Port)] = p.Name
}
}
}

urls := []string{}
for _, port := range nodePorts {
var doc bytes.Buffer
err = t.Execute(&doc, struct {
IP string
Port int32
}{
ip,
port,
})
if err != nil {
return nil, err
for _, port := range svc.Spec.Ports {
if port.NodePort > 0 {
var doc bytes.Buffer
err = t.Execute(&doc, struct {
IP string
Port int32
Name string
}{
ip,
port.NodePort,
m[port.TargetPort.IntVal],
})
if err != nil {
return nil, err
}
urls = append(urls, doc.String())
}

urls = append(urls, doc.String())
}
return urls, nil
}
Expand Down