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

cmd: Introduce runtime and k8s columns #2056

Merged
merged 3 commits into from
Sep 22, 2023
Merged

Conversation

mqasimsarfraz
Copy link
Member

@mqasimsarfraz mqasimsarfraz commented Sep 18, 2023

#1702 added support for k8s metadata in JSON/YAML but the support for columns was still missing. This PR allows the same information to be available as columns as well.

Related: #737
Fixes: #2066

Idea

  • Before this change both ig and kubectl-gadget would filter k8s and runtime columns respectively rather then hiding. So we will switch to marking them hidden as needed by each client.
  • The hidden columns can be displayed using -o columns as needed by the user.
  • list-containers needs an extra work but k8s metadata can also be displayed using -o custom-columns

Tesing done

$ make minikube-start-containerd
$ make ig
$ docker cp ig minikube-containerd:/bin/ig
$ docker exec -it minikube-containerd bash
$ ig list-containers # same as before
RUNTIME.RUNTIMENAME RUNTIME.CONTAINERID                                              RUNTIME.CONTAINERNAME   RUNTIME.CONTAINERIMAGENAME                                 
containerd          0a9cbc23a8409cf015e389fa71f2422f28dbea1129e66a40e38685fb67424ef6 coredns                 k8s.gcr.io/coredns/coredns:v1.8.6                          
containerd          5e48d5e717d89f2237eb0b364d9c8b6265f949e5600f642d55420e1a4922e2e2 etcd                    k8s.gcr.io/etcd:3.5.3-0 
$ ig list-containers -o custom-columns=runtime.containerid,runtime.containername,k8s.pod,k8s.namespace
RUNTIME.CONTAINERID                                              RUNTIME.CONTAINERNAME   K8S.POD                                     K8S.NAMESPACE
0a9cbc23a8409cf015e389fa71f2422f28dbea1129e66a40e38685fb67424ef6 coredns                 coredns-6d4b75cb6d-94hkg                    kube-system  
5e48d5e717d89f2237eb0b364d9c8b6265f949e5600f642d55420e1a4922e2e2 etcd                    etcd-minikube-containerd                    kube-system

$ ig trace open -o columns=runtime.containername,k8s.pod,k8s.namespace,pid,comm
RUNTIME.CONTAINERNAME                                                K8S.POD                                                             K8S.NAMESPACE                                                       PID        COMM            
gadget                                                               gadget-p4kvb                                                        gadget                                                              448891     runc:[2:INIT]   
gadget                                                               gadget-p4kvb                                                        gadget                                                              448891     runc:[2:INIT]   

@mqasimsarfraz mqasimsarfraz force-pushed the qasim/k8s-columns branch 5 times, most recently from fc522e2 to 74e8146 Compare September 19, 2023 08:33
@mqasimsarfraz mqasimsarfraz changed the base branch from main to mauricio/linux-die-net September 19, 2023 08:42
Base automatically changed from mauricio/linux-die-net to main September 19, 2023 12:30
@mqasimsarfraz mqasimsarfraz force-pushed the qasim/k8s-columns branch 2 times, most recently from ebdb5df to 0d5ed51 Compare September 19, 2023 15:13
@mqasimsarfraz mqasimsarfraz marked this pull request as ready for review September 19, 2023 15:29
Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great. I don't know if having the K8s. prefix in kubectl-gadget has been discussed, IMO that's good:

$ ./kubectl-gadget trace open
INFO[0000] Experimental features enabled                
K8S.NODE                  K8S.NAMESPACE             K8S.POD                  K8S.CONTAINER            PID        COMM         FD ERR P

I didn't find anything to be fixed in the code, only some things that are missing:

  • It's missing to update all gadgets guides (sorry, I now it's to annoying to do it, perhaps a good regexp to replace can help)
  • Prometheus documentation should be updated as well
    labels:
    - namespace
    - pod
    - container

    (other places in same file)

btw, this will also fix #2066.

pkg/container-collection/containers.go Outdated Show resolved Hide resolved
Copy link
Member

@eiffel-fl eiffel-fl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it works well, so thank you for this contribution:

root@minikube-containerd:/# ig list-containers -o custom-columns=runtime.containerid,runtime.containername,k8s.pod,k8s.namespace
RUNTIME.CONTAINE… RUNTIME.CONTAINERNAME                   K8S.POD                                 K8S.NAMESPACE                          
0dbc2b236492024a… coredns                                 coredns-6d4b75cb6d-6fz8w                kube-system                            
d316f9ad44642ad2… etcd                                    etcd-minikube-containerd                kube-system                            
ceec8a2150ffb369… kindnet-cni                             kindnet-t7z5q                           kube-system                            
c90e7729f491ff46… kube-apiserver                          kube-apiserver-minikube-containerd      kube-system                            
b9270e09b88d70ad… kube-controller-manager                 kube-controller-man…minikube-containerd kube-system                            
22f4ffe5fda3dfb7… kube-proxy                              kube-proxy-l8lvs                        kube-system                            
77ad2368722885b8… kube-scheduler                          kube-scheduler-minikube-containerd      kube-system                            
fa55550caeb0b391… storage-provisioner                     storage-provisioner                     kube-system                            
root@minikube-containerd:/# ig trace open -o columns=runtime.containername,k8s.pod,k8s.namespace,pid,comm | head
RUNTIME.CONTAINERNAME          K8S.POD                        K8S.NAMESPACE                  PID              COMM            
coredns                        coredns-6d4b75cb6d-6fz8w       kube-system                    22878            coredns         
storage-provisioner            storage-provisioner            kube-system                    23048            storage-provisi 
coredns                        coredns-6d4b75cb6d-6fz8w       kube-system                    22878            coredns         
coredns                        coredns-6d4b75cb6d-6fz8w       kube-system                    22878            coredns         
coredns                        coredns-6d4b75cb6d-6fz8w       kube-system                    22878            coredns         
kube-proxy                     kube-proxy-l8lvs               kube-system                    22562            kube-proxy      
kube-proxy                     kube-proxy-l8lvs               kube-system                    22562            kube-proxy      
kube-proxy                     kube-proxy-l8lvs               kube-system                    23370            iptables        
kube-proxy                     kube-proxy-l8lvs               kube-system                    23370            iptables        

I do not have a lot of comments, just address Mauricio comment and you can merge it.

cmd/common/registry.go Show resolved Hide resolved
cmd/common/utils/parser.go Show resolved Hide resolved
Copy link
Member

@blanquicet blanquicet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach of hiding the columns instead of filtering them. It should also make the implementation of the --k8s and --runtime flags easier. BTW, given that you will add that in a second PR, this one is not fully fixing #737.

LGTM after managing the comments.

cmd/common/registry.go Outdated Show resolved Hide resolved
cmd/common/registry.go Show resolved Hide resolved
@mauriciovasquezbernal
Copy link
Member

It should also make the implementation of the --k8s and --runtime flags

I'm wondering about what's the idea there. Provide independent flags to enable the runtime and k8s columns? IMO we should avoid adding so many flags, what about having something like -o columns=runtime? (we can try to find a different syntax for making it obvious it's for the full "kind" of columns.)

@mqasimsarfraz
Copy link
Member Author

It's missing to update all gadgets guides (sorry, I now it's to annoying to do it, perhaps a good regexp to replace can help)

Done. Agreed, it wasn't fun to do but I realized we were missing RUNTIME columns for ig in docs as well so thanks for catching it!

@blanquicet
Copy link
Member

It should also make the implementation of the --k8s and --runtime flags

I'm wondering about what's the idea there. Provide independent flags to enable the runtime and k8s columns? IMO we should avoid adding so many flags, what about having something like -o columns=runtime? (we can try to find a different syntax for making it obvious it's for the full "kind" of columns.)

My initial idea was to add --k8s only to ig and --runtime only to kubectl-gadget, but it was just my proposal, we can ask for opinions in the slack channel 🙂.

@mqasimsarfraz
Copy link
Member Author

BTW, given that you will add that in a second PR, this one is not fully fixing #737.

I changed the linked issue from "Fixes" to "Related" to make sure we do follow up PR.

but it was just my proposal, we can ask for opinions in the slack channel 🙂.

Good idea. Let me start a discussion in the slack around this!

Currently we are filtering 'k8s' columns for ig and 'runtime'
columns for kubectl-gadget. This change makes the columns hidden
rather then filtered to allow user to be able to apply filters
and use them in custom column format with '-o columns='

Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
@mqasimsarfraz
Copy link
Member Author

Thanks for the reviews!

@mqasimsarfraz mqasimsarfraz merged commit dbacb01 into main Sep 22, 2023
49 checks passed
@mqasimsarfraz mqasimsarfraz deleted the qasim/k8s-columns branch September 22, 2023 15:56
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.

containerized-gadgets: K8s fields aren't grouped in its own object when using json
4 participants