kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
148 stars 49 forks source link

How to get label key and value? #215

Closed swhoro closed 10 months ago

swhoro commented 10 months ago

for example:

auto pods = CoreV1API_listNamespacedPod(apiClient,
                                            const_cast<char *>("default"),
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr,
                                            nullptr);

listEntry_t *entry;
list_ForEach(entry, pods->items) {
    v1_pod_t *pod = static_cast<v1_pod_t *>(entry->data);
    std::cout << pod->metadata->name << std::endl;

    listEntry_t *labelEntry;
    list_ForEach(labelEntry, pod->metadata->labels) {
        // how to write code to get this pod label key and value?
    }
}
ityuhui commented 10 months ago

https://github.com/kubernetes-client/c/blob/ea7f644c26611c7820b7030fb5f1aa170cfaf607/examples/configmap/main.c#L103C26-L103C36

I think this helps.

swhoro commented 10 months ago

https://github.com/kubernetes-client/c/blob/ea7f644c26611c7820b7030fb5f1aa170cfaf607/examples/configmap/main.c#L103C26-L103C36

I think this helps.

Thank you

brendandburns commented 10 months ago

Closing this since I think the question is answered.