https://pulumi.com logo
Title
m

microscopic-cpu-38113

12/15/2022, 8:38 AM
hello, we have a use case in which the configmap has been set to auto naming and deleteBeforeReplace is also set to false, AND the value of the data is retrieved from pulumi.all and not sure if it is for this reason, Pulumi would think that there's a change in the data of the configmap and it always delete the old configmap and create a new one. As such, it creates a cascading effect like force replacement of the kubernetes job or deployment that rely on the configmap. Is there a way to avoid Pulumi from thinking that there's change in data when we use pulumi.all to retrieve the values?
a

ancient-policeman-24615

12/15/2022, 1:36 PM
I’m not a kubernetes expert, but using an output combinator like
pulumi.all
should have no effect on if a resource needs to be updated/replaced. If you could show some example code, I’d be happy to help diagnose the problem, or escalate to someone more familiar with the area.
m

microscopic-cpu-38113

12/15/2022, 2:31 PM
const dNSRecordSet = new GoogleDnsRecordSetComponent('app', {
            gcpProjectName: props.gcpProjectName,
        },{
            parent: this,
        });

        const appConfig = pulumi
        .all([
            dNSRecordSet.cdnAddress,
        ])
        .apply(
            ([
                cdnAddress,
            ]) =>
                JSON.stringify({
                    key: {
                        value1: cdnAddress,
                        value2: String(new Date().getTime()),
                    }
                })
        );


        const jobConfigmapData = {};
		jobConfigmapData[`config.${props.environment}.json`] = appConfig;

		const jobConfigmap = new k8s.core.v1.ConfigMap(
			'job-configmap',
			{
				metadata: {
					namespace: props.namespace,
				},
				data: jobConfigmapData,
			},
			{
				parent: this,
				provider: props.clusterProvider,
				deleteBeforeReplace: false,
			}
		);
something like this, I think the problem is the data is depending on the current date time, each time when Pulumi run the plan, the configmap data will then be updated. I thought configmap data can be updated on the fly in Kubernetes without deleting and recreating it
a

ancient-policeman-24615

12/15/2022, 3:15 PM
Yeah, if
appConfig
depends on the current time, then everything that depends on it will require an update each time you run
pulumi up
. Its up to
k8s.core.v1.ConfigMap
to decide if that change can be done in place (update) or needs a replacement. P.S. From the example you have, you don’t need the
pulumi.all
. You can just apply on the
dNSRecordSet.cdnAddress
.
m

microscopic-cpu-38113

12/15/2022, 3:22 PM
noted, is there a way to avoid the configmap from being recreated?
a

ancient-policeman-24615

12/15/2022, 3:23 PM
There is a provider option in beta called
<https://www.pulumi.com/registry/packages/kubernetes/api-docs/provider/#enableconfigmapmutable_yaml|enableConfigMapMutable>
.
m

microscopic-cpu-38113

12/15/2022, 3:29 PM
so just add that environment variable in the runtime?
a

ancient-policeman-24615

12/15/2022, 3:30 PM
That should do it.
m

microscopic-cpu-38113

12/15/2022, 3:33 PM
can I set the name of the configmap? or it has to be auto rename?
b

billowy-army-68599

12/15/2022, 3:51 PM
can you show a diff of when this replace happens?
m

microscopic-cpu-38113

12/15/2022, 3:53 PM
currently I have it auto rename and set deleteBeforeReplace to false and enabled the new environment variable PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE in my runtime, but the latest plan is still trying to delete and recreate the configmap
the difference is still in the data, which takes the value of the current time at runtime
b

billowy-army-68599

12/15/2022, 3:54 PM
Pulumi would think that there’s a change in the data of the configmap and it always delete the old configmap and create a new one
i’d like to see what Pulumi thinks is changing. If the data is changing, it will obviously replace the config map
m

microscopic-cpu-38113

12/15/2022, 3:57 PM
~ data: {
              ~ config.staging.json: (json) {
                  ~ key: {
                        value*****: "34.*****60.84.6"
                      ~ value2: "*****67***************[38;5;*****m8005567" => "*****67***************9766826"
                    }
                }
            }
@ previewing update....
some of the value is masked but basically they are just timestamp
b

billowy-army-68599

12/15/2022, 3:59 PM
ah, so you’re trying to use the
enableConfigMapMutable
option, now I understand
can you file an issue please? looks like that isn’t working as expected
m

microscopic-cpu-38113

12/15/2022, 4:01 PM
does it intend to work for configmap without auto naming (aka fix name)?