apisix-ingress-controller icon indicating copy to clipboard operation
apisix-ingress-controller copied to clipboard

request help: error when ingress_publish_service is null

Open xiangtianyu opened this issue 2 years ago • 6 comments

Issue description

I update our ingress controller to 1.5.0-rc1 right now, and met a strange error

{"level":"error","time":"2022-08-31T18:58:37.882741632+08:00","caller":"ingress/status.go:280","message":"failed to get APISIX gateway external IPs","error":"resource name may not be empty"}

I trace the error and found if ingress_publish_service is "" in the config, the code in IngressPublishAddresses will analyze namespace and name to "", so it will cause "resource name may not be empty"

func IngressPublishAddresses(ingressPublishService string, ingressStatusAddress []string, kubeClient kubernetes.Interface) ([]string, error) {
	addrs := []string{}

	// if ingressStatusAddress is specified, it will be used first
	if len(ingressStatusAddress) > 0 {
		addrs = append(addrs, ingressStatusAddress...)
		return addrs, nil
	}

	namespace, name, err := cache.SplitMetaNamespaceKey(ingressPublishService)
	if err != nil {
		log.Errorf("invalid ingressPublishService %s: %s", ingressPublishService, err)
		return nil, err
	}

	svc, err := kubeClient.CoreV1().Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
	if err != nil {
		return nil, err
	}

	switch svc.Spec.Type {
	case apiv1.ServiceTypeLoadBalancer:
		if len(svc.Status.LoadBalancer.Ingress) < 1 {
			return addrs, fmt.Errorf("%s", _gatewayLBNotReadyMessage)
		}

		for _, ip := range svc.Status.LoadBalancer.Ingress {
			if ip.IP == "" {
				// typically AWS load-balancers
				addrs = append(addrs, ip.Hostname)
			} else {
				addrs = append(addrs, ip.IP)
			}
		}

		addrs = append(addrs, svc.Spec.ExternalIPs...)
		return addrs, nil
	default:
		return addrs, nil
	}

}

Is this a bug?

Environment

  • your apisix-ingress-controller version (output of apisix-ingress-controller version --long): 1.5.0-rc1
  • your Kubernetes cluster version (output of kubectl version):
  • if you run apisix-ingress-controller in Bare-metal environment, also show your OS version (uname -a):

xiangtianyu avatar Aug 31 '22 11:08 xiangtianyu

thanks,it's expected behavior

tao12345666333 avatar Aug 31 '22 11:08 tao12345666333

thanks,it's expected behavior

So that means we MUST set "ingress_publish_service" ?

xiangtianyu avatar Aug 31 '22 11:08 xiangtianyu

Is it must set apisix gateway's namespace and svc name? apisix gateway's namespace is not the same to biz's namespace.

xuminwlt avatar Aug 31 '22 11:08 xuminwlt

thanks,it's expected behavior

So that means we MUST set "ingress_publish_service" ?

Not required. But it is recommended to set.

Some platforms display Ingress status and other information based on this information (e.g. rancher

tao12345666333 avatar Sep 01 '22 01:09 tao12345666333

Is it must set apisix gateway's namespace and svc name?

apisix gateway's namespace is not the same to biz's namespace.

please refer to https://github.com/apache/apisix-ingress-controller/blob/master/conf/config-default.yaml

tao12345666333 avatar Sep 01 '22 01:09 tao12345666333

thanks,it's expected behavior

So that means we MUST set "ingress_publish_service" ?

Not required. But it is recommended to set.

Some platforms display Ingress status and other information based on this information (e.g. rancher

But if we did not set this value, it will continuously output error

xiangtianyu avatar Sep 01 '22 01:09 xiangtianyu

So what is the solution when do I need to set it and to what value?

tharwan avatar Nov 07 '22 19:11 tharwan

just change this

https://github.com/apache/apisix-ingress-controller/blob/38b12fb4a5a2169eb3585e5b7e2f78c8ce447862/conf/config-default.yaml#L40-L49

tao12345666333 avatar Nov 08 '22 01:11 tao12345666333

If your cluster has LoadBalancer, you can set ingress_publish_service otherwise, use theingress_status_address

tao12345666333 avatar Nov 08 '22 01:11 tao12345666333

Alright, I set the ingress_status_adress to the IP of my node, but I still can not reach the ingress from my host.

tharwan avatar Nov 08 '22 07:11 tharwan

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Feb 07 '23 01:02 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Mar 09 '23 01:03 github-actions[bot]