I'm using Pulumi to deploy a helm chart, which acc...
# dotnet
b
I'm using Pulumi to deploy a helm chart, which accepts Affinity as a Value. I need to start using that to control where the pods are deployed, but I can't figure out how to configure it using the ChartArgs.Values property. Are there any examples out there for this?
I figured out how to do it, but it's very verbose. Is there any way to do this in a more clean, maintainable way?
Copy code
Values = new Dictionary<string, object>
{
    ...

    { "affinity", new Dictionary<string, object>() 
        {
            { "nodeAffinity", new Dictionary<string,  object>()
                {
                    { "requiredDuringSchedulingIgnoredDuringExecution", new Dictionary<string, object>()
                        {
                            { "nodeSelectorTerms", new object[]
                                {
                                    new Dictionary<string, object>()
                                    {
                                        { "matchExpressions", new object[] 
                                            {
                                                new Dictionary<string, object>()
                                                {
                                                    { "key", "<http://eks.amazonaws.com/capacityType|eks.amazonaws.com/capacityType>" },
                                                    { "operator", "NotIn" },
                                                    { "values", new object[] 
                                                        {
                                                            "SPOT"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } 
            }
        }
    }
}
w
Eek. Would deserializing a json string to a dictionary be a suitable hack?
b
Not a bad idea. Works pretty well:
Going to try it in Yaml as well.
yaml doesn't work so well. Pulumi works with JsonElements fine, but YamlDotNet deserializes to Dictionary<object,object>. Pulumi wants Dictionary<string,object> and crashes.
w
Just do
.ToDictionary(x => (string)x, x => x)
?
Would this work?
Copy code
using YamlDotNet.Serialization;

public static class StringExtensions
{
    public static IDictionary<string, object> DeserializeYaml(this string yaml) => new DeserializerBuilder().Build().Deserialize<IDictionary<string, object>>(yaml);
}
@bumpy-motorcycle-53357 did a quick test and it worked for me
b
That's what I did. And while I can specify that the root dictionary object should be a <string, object> the child dictionary objections where still Dictionary<object, object> and pulumi still crashed.