How to set up environment for fabric8-cdi

199 views Asked by At

I'm trying to use fabric8-cdi described here: https://fabric8.io/guide/cdi.html

I'm using minikube while developing, I start a rc and a service named mev-rserve here's the service running:

$kubectl get services
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
kubernetes   10.0.0.1     <none>        443/TCP          2d
mev-rserve   10.0.0.19    <pending>     6311:31744/TCP   49m

In my webapp I have this bean producer:

@Produces
static RConnection r (@ServiceName ("mev-rserve") String endpoint) { /* ... */ }

Which works fine if I declare MEV_RSERVE_SERVICE_HOST and MEV_RSERVE_SERVICE_PORT env variables as described in the doc I linked, but I want the library to look it up from kube api that's not happening. Here's my configuration:

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /Users/levkuznetsov/.minikube/ca.crt
    server: https://192.168.99.101:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /Users/levkuznetsov/.minikube/apiserver.crt
    client-key: /Users/levkuznetsov/.minikube/apiserver.key

From that I've setup the environment as follows:

KUBERNETES_MASTER="https://192.168.99.101:8443"
KUBERNETES_API_VERSION="v1"
KUBERNETES_CERTS_CA_FILE="/Users/levkuznetsov/.minikube/ca.crt"
KUBERNETES_CERTS_CLIENT_FILE="/Users/levkuznetsov/.minikube/apiserver.crt"
KUBERNETES_CERTS_CLIENT_KEY_FILE="/Users/levkuznetsov/.minikube/apiserver.key"

Which results in this exception:

Caused by: java.lang.IllegalArgumentException: No kubernetes service could be found for name: mev-rserve in namespace: null
at io.fabric8.kubernetes.api.KubernetesHelper.getServiceURL(KubernetesHelper.java:1347)
at io.fabric8.cdi.Services.toServiceUrl(Services.java:38)
at io.fabric8.cdi.producers.ServiceUrlProducer.produce(ServiceUrlProducer.java:47)
at io.fabric8.cdi.producers.ServiceUrlProducer.produce(ServiceUrlProducer.java:26)
at io.fabric8.cdi.bean.ProducerBean.create(ProducerBean.java:43)
...

Thanks in advance

1

There are 1 answers

0
Lev Kuznetsov On BEST ANSWER

In case anyone else is struggling with this, I traced this down to the lack of namespace definition. I do not declare a KubernetesClient bean so I don't set the default namespace which turns out to be null. I don't want to declare one in the app since in production the environment variables will take precedence anyway, this is for development only. I found it cleaner to set up the environment accordingly.