https://pulumi.com logo
#kubernetes
Title
# kubernetes
c

crooked-helicopter-55521

03/26/2020, 8:05 PM
I've got a configmap I've made by hand and am trying to figure out how to reproduce it with the
core.v1.ConfigMap
object. Having a bit of trouble, curious if anyone has any ideas (threading the details)
I've got this file as an example:
Copy code
{
  "kind": "Policy",
  "apiVersion": "v1",
  "metadata": {
    "name": "scheduler-policy-config",
    "namespace": "kube-system"
  },
  "predicates": [
    {
      "name": "PodFitsHostPorts"
    },
    {
      "name": "PodFitsResources"
    },
    {
      "name": "NoDiskConflict"
    },
    {
      "name": "NoVolumeZoneConflict"
    },
    {
      "name": "PodToleratesNodeTaints"
    },
    {
      "name": "MatchNodeSelector"
    },
    {
      "name": "HostName"
    }
  ],
  "priorities": [
    {
      "name": "LeastRequestedPriority",
      "weight": 1
    },
    {
      "name": "BalancedResourceAllocation",
      "weight": 1
    },
    {
      "name": "SelectorSpreadPriority",
      "weight": 10
    },
    {
      "name": "ServiceSpreadingPriority",
      "weight": 1
    },
    {
      "name": "EqualPriority",
      "weight": 1
    }
  ]
}
then I run
kubectl create configmap scheduler-policy-config --from-file=./policy.cfg
which gives me a config map that looks like this:
Copy code
Data
====
policy.cfg:
----
{
"kind" : "Policy",
"apiVersion" : "v1",
"metadata" : {
    "name": "scheduler-policy-config",
    "namespace": "kube-system"
    },
"predicates" : [
        {"name" : "PodFitsHostPorts"},
        ...
        ],
"priorities" : [
        {"name" : "LeastRequestedPriority", "weight" : 1},
      ....
  ]
}
So I'm trying to recreate that ^ configmap via pulumi, and it doesn't seem to know about the predicates / priorities stuff. Any tips on how I could pull this off? Thanks!
b

billowy-army-68599

03/26/2020, 8:10 PM
Unless I'm mistaken, the configmap you're creating is just embedding JSON in the data field. You should be able to use
JSON.stringify
on an object, for example
Copy code
const policy = {
  "kind": "Policy"
  // insert rest of JSON here
}

const scheduler-policy-config = new k8s.core.v1.ConfigMap("scheduler-policy-config", {
    metadata: { namespace: "kube-system" },
    data: {
        "policy.cfg": JSON.stringify(policy)
    },
});
Another option would be to read the config from a file
c

crooked-helicopter-55521

03/26/2020, 8:12 PM
interesting, I'll give that a shot
thanks Jaxxstorm
7 Views