Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.32k stars 433 forks source link

No resources found in azure-functions namespace. #2822

Open doggy8088 opened 3 years ago

doggy8088 commented 3 years ago

I'm using Azure Functions Core Tools v3.

  1. I deploy my function app to my local kubernetes.

    func kubernetes deploy --namespace azure-functions --name funapp1 --registry username --service-type NodePort

    I can deploy my function app to my local kubernetes successfully.

  2. I tried to show logs for my function

    func logs --name funapp1 --platform kubernetes

    It's always show No resources found in azure-functions namespace.

    Function logs:
    No resources found in azure-functions namespace.
  3. I actually can retrieve logs using kubectl command.

    kubectl logs deploy/funapp1-http --namespace=azure-functions
    kubectl logs -l app=funapp1-http  -n azure-functions

    I can show logs using the following command too.

    kubectl logs -l app=funapp1-http  -n azure-functions

I have no clue how to use func logs command. Is it a bug? Or what should I do? I never have a chance to see logs using func logs command.

Here is my current info:

G:\Projects\funapp1>kubectl get all --namespace=azure-functions --show-labels=true
NAME                                READY   STATUS    RESTARTS   AGE   LABELS
pod/funapp1-http-76d8759f49-j7tkz   1/1     Running   0          17m   app=funapp1-http,pod-template-hash=76d8759f49

NAME                   TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE   LABELS
service/funapp1-http   NodePort   10.102.244.169   <none>        80:32362/TCP   17m   <none>

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE   LABELS
deployment.apps/funapp1-http   1/1     1            1           17m   app=funapp1-http

NAME                                      DESIRED   CURRENT   READY   AGE   LABELS
replicaset.apps/funapp1-http-76d8759f49   1         1         1       17m   app=funapp1-http,pod-template-hash=76d8759f49
doggy8088 commented 3 years ago

I tried to run a wrong command:

func logs --platform kubernetes --name a/b

I can see errors finally with some meaningful message:

Function logs:
Error from server (BadRequest): Unable to find "/v1, Resource=pods" that match label selector "app=a/b-deployment", field selector "": unable to parse requirement: values[0][app]: Invalid value: "a/b-deployment": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
Error running kubectl logs -l app=a/b-deployment -n azure-functions.
output: Error from server (BadRequest): Unable to find "/v1, Resource=pods" that match label selector "app=a/b-deployment", field selector "": unable to parse requirement: values[0][app]: Invalid value: "a/b-deployment": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

So this is the actual command behind the scene:

 kubectl logs -l app=FUNCTIONNAME-deployment -n azure-functions

It's obvious that the label of the deployment is wrong. My actual label is app=funapp1-http. So func logs --platform kubernetes --name funapp1 is actually query for app=funapp1-deployment which is wrong.