https://pulumi.com logo
#general
Title
# general
w

worried-city-86458

09/17/2019, 6:34 PM
If I update a k8s configmap will Pulumi restart any pods using it?
c

cool-egg-852

09/17/2019, 6:35 PM
If the deployment references it, yes.
w

worried-city-86458

09/17/2019, 6:35 PM
Cool, that's a nice touch as you don't normally get that in k8s.
I just tried a test with a daemon set and the pods didn't restart after I updated their config map with
pulumi up
c

cool-egg-852

09/20/2019, 5:06 PM
It depends on how you write the code.
If the daemon set depends upon the configmap, it will restart them as the daemonset pod spec will have changed
w

worried-city-86458

09/20/2019, 7:41 PM
Interesting. I used
k8s.yaml.ConfigFile
with pre-existing yaml.
Pulumi clearly parses the yaml to show the tree but ds didn’t depend on cm IIRC
I posted the yaml in a separate issue (https://github.com/pulumi/pulumi-kubernetes/issues/812)
The ds does reference the cm in there, so Pulumi could be smarter about how it builds the tree.
Thoughts @white-balloon-205 ?
w

white-balloon-205

09/20/2019, 7:51 PM
This will only work if there is an explicit dependency between the two. I expect if you are doing this in YAML, the resources are unrelated and just both mention the same string name. You could use
transforms
on the
ConfigFile
to rewrite the dependency between the two.
w

worried-city-86458

09/20/2019, 8:04 PM
I’ll try that later, but if the ds references the cm by name, and it’s in the same yaml, this could happen automatically.
This particular scenario with a cm dependee would be really nice to have
w

white-balloon-205

09/20/2019, 8:09 PM
Pulumi doesn’t understand that the string “foo” one place is associated with the string “foo” in another place. Dependencies are established by passing a reference to one resource (or output of that resource) into another. It would be nice if the former could work somehow, but it’s nearly impossible to imagine a general enough mechanism for this. To get full benefits of Pulumi here - you do need to move things into the lore expressive Pulumi source code. If folks have concrete ideas on what we could do to go further here - would love to hear them in github issues though.
w

worried-city-86458

09/21/2019, 10:43 PM
@white-balloon-205 It looks like transformations are per object without access to the object tree, so I can't see how to use
transforms
to rewrite the dependency between the daemonset and configmap.
Copy code
let configMap: any;

function setParent(obj: any, opts: pulumi.CustomResourceOptions) {
    if (obj.kind == "ConfigMap") {
        configMap = obj;
    }
    else if (obj.kind == "DaemonSet") {
        opts.parent = configMap;
    }
}

const fluentBit = new k8s.yaml.ConfigFile("fluent-bit.yml", { transformations: [ setParent ] }, { parent: cluster, provider: cluster.provider });
Trying to assign and then set over separate calls nearly works but fails with an unhandled exception:
Copy code
Diagnostics:
  pulumi:pulumi:Stack (k8s-infra-dev):
    error: Running program '/workspaces/workspace/k8s-infra' failed with an unhandled exception:
    Error: Resource parent is not a valid Resource: [object Object]
        at new Resource (/workspaces/workspace/k8s-infra/node_modules/@pulumi/pulumi/resource.js:92:19)
        at new CustomResource (/workspaces/workspace/k8s-infra/node_modules/@pulumi/pulumi/resource.js:265:9)
        at new DaemonSet (/workspaces/workspace/k8s-infra/node_modules/@pulumi/kubernetes/apps/v1/DaemonSet.js:31:9)
        at /workspaces/workspace/k8s-infra/node_modules/@pulumi/kubernetes/yaml/yaml.js:395:31
        at OutputImpl.<anonymous> (/workspaces/workspace/k8s-infra/node_modules/@pulumi/pulumi/output.js:110:47)
        at Generator.next (<anonymous>)
        at fulfilled (/workspaces/workspace/k8s-infra/node_modules/@pulumi/pulumi/output.js:18:58)
I think this happens because the
transformations
are called on the raw object, before it's instantiated as a `pulumi.Resource`: https://github.com/pulumi/pulumi-kubernetes/blob/master/sdk/nodejs/yaml/yaml.ts#L2569 https://github.com/pulumi/pulumi-kubernetes/blob/master/sdk/nodejs/yaml/yaml.ts#L2587
It seems to me that these yaml transformations should be left as they are, purely for "text templating" functionality, and the kind of transform I need for re-parenting is best handled by a more generic escape hatch that works with pulumi resources; i.e. https://github.com/pulumi/pulumi/issues/2068
It could still be useful, maybe in both cases, to callback to a transform with the whole tree of objects / resources, so that these sorts of manipulations across multiple objects would be possible.