garethr / kubernetes-json-schema

A set of JSON schemas for various Kubernetes versions, extracted from the OpenAPI definitions
Other
253 stars 61 forks source link

Dynamic create config map #29

Closed s0n00im closed 2 years ago

s0n00im commented 2 years ago

I looked at the api to dynamically create/updatte deployments. https://github.com/kubernetes/client-go/blob/master/examples/dynamic-create-update-delete-deployment/main.go

I am trying to create a configmap using the dynamic api. I want the configmap to support the declarative 'apply' (server side apply) instead of imperative create. Can you tell me how to do the same?

When I use: configmapRes := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmap"} I get an error saying: panic: the server could not find the requested resource

s0n00im commented 2 years ago
configmapRes := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"}
deployment := &unstructured.Unstructured{
        Object: map[string]interface{}{
            "apiVersion": "v1",
            "kind":       "ConfigMap",
            "metadata": map[string]interface{}{
                "name": "test-dashboard-config",
                "namespace": "abc",
                "labels": map[string]interface{}{
                    "abc": "test",
                },
            },
            "data": map[string]interface{}{
                "title": "test",
            },
        },
    }

    result, err := client.Resource(configmapRes).Namespace(namespace).Create(context.TODO(), deployment, metav1.CreateOptions{})