kubernetes-sigs / kind

Kubernetes IN Docker - local clusters for testing Kubernetes
https://kind.sigs.k8s.io/
Apache License 2.0
13.28k stars 1.54k forks source link

Allow adding container labels for kind nodes #3068

Open hellt opened 1 year ago

hellt commented 1 year ago

Hi @aojea @BenTheElder I would like to see if you consider the enhancement request to be able to provide container metadata via container labels a feasible request.

In containerlab (containerlab.dev) we would like to add support for spinning up kind clusters as part of a more extensive containerlab lab. In containerlab, the containers that are "orchestrated" by it, tagged accordingly so that additional tools around containerlab can filter containers and provide some automation around it.

When looking into kind API we didn't find a way to add metadata to kind containers (these are worker and master nodes). Is is possible to enhance API and allow providing tags to kind containers?

aojea commented 1 year ago

If by container metadata via container labels you refer to the kindnode containers, they already have information necessary to identify them

            "Labels": {
                "io.x-k8s.kind.cluster": "kind",
                "io.x-k8s.kind.role": "control-plane"
            },

does it work for you?

hellt commented 1 year ago

@aojea, the enhancement request is about being able to assign custom labels to the ones you do by default.

aojea commented 1 year ago

I can see how that can be difficult to support with docker/podman duality Do you have time next week and we talk over this, this way I can use the opportunity to learn more about the project

hellt commented 1 year ago

@aojea yes, we can sync up in twitter DMs to choose some time for a sync

BenTheElder commented 1 year ago

@aojea what came of this?

Previously we've rejected this feature. We're trying to keep the options to minimal essential ones as the project is tricky enough to maintain already and there's existing labels for identifying nodes from any particular kind cluster, as well as exported APIs and commands for listing nodes which can then be interacted with via docker/podman.

logikone commented 1 year ago

I have a use case where we're creating multiple kind clusters in a CI container for testing. The CI container has the hosts docker.sock mounted in the container. Sometimes when something fails and the job exits you can end up having some dangling kind clusters remaining on the CI host. The job containers that are created by the runner have a bunch of labels on them identifying which repo, job, etc the container belongs to. I'd like to be able to put some of those same labels on the containers that kind creates so I can better identify dangling containers.

I'd be happy to contribute in my free time if this is a feature that you'd like to see added. Thanks!

BenTheElder commented 1 year ago

can you use a computed cluster name instead? (container names are computed from cluster name and are stable + predictable and labeled with the cluster name already)

logikone commented 1 year ago

Ya, that's what I'm doing currently 👍

icefed commented 2 months ago

this feature has been rejected, try my commit if you really want this, https://github.com/icefed/kind/tree/container-label