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

chore/get-external-ip-for-svc #336

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mosheavni
Copy link
Contributor

perhaps there are other things that give this field the value but for my clusters, all I could find is status.loadBalancer.ingress[1].hostname

@Ramilito
Copy link
Owner

This is how the ingresses work, could it be the same?

local function get_address(row)
  local addresses = {}
  if row.status and row.status.loadBalancer and row.status.loadBalancer.ingress then
    for _, ingress in ipairs(row.status.loadBalancer.ingress) do
      if ingress.hostname then
        table.insert(addresses, ingress.hostname)
      elseif ingress.ip then
        table.insert(addresses, ingress.ip)
      end
    end
  end

  return table.concat(addresses, ", ")
end

@mosheavni
Copy link
Contributor Author

This is how the ingresses work, could it be the same?

local function get_address(row)
  local addresses = {}
  if row.status and row.status.loadBalancer and row.status.loadBalancer.ingress then
    for _, ingress in ipairs(row.status.loadBalancer.ingress) do
      if ingress.hostname then
        table.insert(addresses, ingress.hostname)
      elseif ingress.ip then
        table.insert(addresses, ingress.ip)
      end
    end
  end

  return table.concat(addresses, ", ")
end

I'm not familiar with a case where a kind: Service can have multiple addresses but maybe I'm wrong

@Ramilito
Copy link
Owner

Ramilito commented Sep 22, 2024

Tbh I'm not sure I nailed it in the ingresses resource either but took a look at k9s implementation and it looks like this:

From: https://github.com/derailed/k9s/blob/2492402ba3311ab6618f58d692ad15518c54cac6/internal/render/svc.go#L83

func getSvcExtIPS(svc *v1.Service) []string {
	results := []string{}

	switch svc.Spec.Type {
	case v1.ServiceTypeClusterIP:
		fallthrough
	case v1.ServiceTypeNodePort:
		return svc.Spec.ExternalIPs
	case v1.ServiceTypeLoadBalancer:
		lbIps := lbIngressIP(svc.Status.LoadBalancer)
		if len(svc.Spec.ExternalIPs) > 0 {
			if len(lbIps) > 0 {
				results = append(results, lbIps)
			}
			return append(results, svc.Spec.ExternalIPs...)
		}
		if len(lbIps) > 0 {
			results = append(results, lbIps)
		}
	case v1.ServiceTypeExternalName:
		results = append(results, svc.Spec.ExternalName)
	}

	return results
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants