This message was deleted.
# general
s
This message was deleted.
s
I also had this question, but never found the answer. I ended up using
kustomize
overlays w/ the Kubernetes provider to accomplish what I needed.
g
Transformations allow you to modify resources definitions, but not make arbitrary edits to the YAML. For example, you can change the annotations for a Pod defined in YAML/Helm/Kustomize, but you couldn’t use transformations to define a new resource or section of YAML. If you have particular use cases in mind that aren’t supported, you’re welcome to open an issue on the pulumi-kubernetes repo.
s
Thanks, Levi. What is the best way, then, to add values to a YAML file that contains K8s resources? Say, to add labels to a Pod, for example?
g
There are a few examples in the API docs here: https://www.pulumi.com/docs/reference/pkg/kubernetes/yaml/configgroup/#yaml-with-transformations For Pod labels, it should be something like (untested):
Copy code
func(state map[string]interface{}, opts ...pulumi.ResourceOption) {
                        if state["kind"] == "Pod" {
                            metadata := state["metadata"].(map[string]interface{})
                            metadata["labels"] = map[string]interface{}{"foo": pulumi.String("bar")}
                        }
                    },
b
Hello @gorgeous-egg-16927 thank you for example, what about a bit more difficult case, for example I need to change a value of configmap which contains json, e.g
kind: ConfigMap
metadata:
name: cwagentconfig
namespace: amazon-cloudwatch
data:
cwagentconfig.json: |
{
"agent": {
"region": "{{region_name}}"
},
"logs": {
"metrics_collected": {
"kubernetes": {
"cluster_name": "{{cluster_name}}",
"metrics_collection_interval": 60
}
},
"force_flush_interval": 5
}
}
and I need to change cluster_name, if I put something like this:
if kind, ok := state["kind"]; ok && kind == "ConfigMap" && state["metadata"].(map[string]interface{})["name"] == "cwagentconfig" {
data := state["data"].(map[string]interface{})
data["kubernetes"] = map[string]interface{}{"cluster_name": "MYCLUSTER"}
}
An error will come: ReadString: expects " or n, but found {, error found in #10 byte of ...|ernetes" apparently due to block with kubernetes starts with {