kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

Issues with minikube #197

Closed swhoro closed 11 months ago

swhoro commented 11 months ago

When I use this c lib on minikube, CoreV1API_listNamespacedEndpoints (and some other apis) will print error:

curl_easy_perform() failed

URL: https://192.168.49.2:8443/api/v1/namespaces/default/endpoints?allowWatchBookmarks=0&limit=0&sendInitialEvents=0&timeoutSeconds=0&watch=0
IP: 192.168.49.2
PORT: 8443
SCHEME: HTTPS
StrERROR: SSL peer certificate or SSH remote key was not OK
The return code of HTTP request=0
Cannot get any service.

It seems when load_kube_config, the apiKeys cannot parse correctly (maybe it is because there is no api token in my ~/.kube/config ?)

But the golang lib runs normally.

minikube version:

minikube version: v1.30.1
commit: 08896fd1dc362c097c925146c4a0d0dac715ace0

kubectl version:

clientVersion:
  buildDate: "2023-05-17T14:20:07Z"
  compiler: gc
  gitCommit: 7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647
  gitTreeState: clean
  gitVersion: v1.27.2
  goVersion: go1.20.4
  major: "1"
  minor: "27"
  platform: linux/amd64
kustomizeVersion: v5.0.1
serverVersion:
  buildDate: "2023-03-15T13:33:12Z"
  compiler: gc
  gitCommit: 9e644106593f3f4aa98f8a84b23db5fa378900bd
  gitTreeState: clean
  gitVersion: v1.26.3
  goVersion: go1.19.7
  major: "1"
  minor: "26"
  platform: linux/amd64
brendandburns commented 11 months ago

What does your kube config file look like? It should be in $HOME/.kube/config Please paste it into this issue, but please make sure to redact any secret data (e.g. certificates) first.

swhoro commented 11 months ago

What does your kube config file look like? It should be in $HOME/.kube/config Please paste it into this issue, but please make sure to redact any secret data (e.g. certificates) first.

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/***/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Sat, 15 Jul 2023 21:04:32 CST
        provider: minikube.sigs.k8s.io
        version: v1.30.1
      name: cluster_info
    server: https://192.168.49.2:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Sat, 15 Jul 2023 21:04:32 CST
        provider: minikube.sigs.k8s.io
        version: v1.30.1
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/***/.minikube/profiles/minikube/client.crt
    client-key: /home/***/.minikube/profiles/minikube/client.key
brendandburns commented 11 months ago

Looking at the code, we don't currently support loading from cetificate authorities from files outside of the kubeconfig file:

It wouldn't be hard to add support for this, we'd welcome a PR if you want to send it, the relevant code is here:

https://github.com/kubernetes-client/c/blob/master/kubernetes/config/kube_config_yaml.c#L215

swhoro commented 11 months ago

Thanks.

In fact, I am a noob of c, so I am not sure if I can do this.

I will try to fix this.

brendandburns commented 11 months ago

You'll want to do something similar to this which loads client keys:

https://github.com/kubernetes-client/c/blob/master/kubernetes/config/kube_config_yaml.c#L225

swhoro commented 11 months ago

You'll want to do something similar to this which loads client keys:

https://github.com/kubernetes-client/c/blob/master/kubernetes/config/kube_config_yaml.c#L225

Thanks for your hint, I have tested my modification and create a PR: #198

And I have another question: what does progress_func do.

In this example: https://github.com/kubernetes-client/c/blob/master/examples/multi_thread/watch_pod.c

There are two functions in apiClient named data_callback_func and progress_func

I think the data_callback_func will be called when the watched resources are changed (notified by k8s api server) . The program(thread) will be paused on CoreV1API_listNamespacedPod, resumed when notification comes and execute data_callback_func, and paused until next notification comes, keep looping like this.

But I do not know what does progress_func do and when will this function be called? I searched in Google but nothing related found.

So here is my question: did I understand data_callback_func correctly and what does progress_func do and when will it be triggered?

ityuhui commented 11 months ago

data_callback_func is called when new data is received by the C client library from API server. https://github.com/kubernetes-client/c/blob/c223563bda143b3ca9e38cbee5782b37cad040a3/kubernetes/src/apiClient.c#L470-L471

progress_func is called by libcurl while transmitting: https://github.com/kubernetes-client/c/blob/c223563bda143b3ca9e38cbee5782b37cad040a3/kubernetes/src/apiClient.c#L392-L393

https://curl.se/libcurl/c/CURLOPT_XFERINFOFUNCTION.html

Generally you don't need provide your progress_func, The example uses progress_func to exit watching and avoid memory leak.

swhoro commented 11 months ago

data_callback_func is called when new data is received by the C client library from API server.

https://github.com/kubernetes-client/c/blob/c223563bda143b3ca9e38cbee5782b37cad040a3/kubernetes/src/apiClient.c#L470-L471

progress_func is called by libcurl while transmitting:

https://github.com/kubernetes-client/c/blob/c223563bda143b3ca9e38cbee5782b37cad040a3/kubernetes/src/apiClient.c#L392-L393

https://curl.se/libcurl/c/CURLOPT_XFERINFOFUNCTION.html

Generally you don't need provide your progress_func, The example uses progress_func to exit watching and avoid memory leak.

Thank you

ityuhui commented 11 months ago

Close this issue as it is resovled by https://github.com/kubernetes-client/c/pull/198 Thanks @swhoro