https://pulumi.com logo
#dotnet
Title
# dotnet
b

bumpy-motorcycle-53357

05/25/2021, 4:42 PM
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

worried-city-86458

05/25/2021, 11:57 PM
Eek. Would deserializing a json string to a dictionary be a suitable hack?
b

bumpy-motorcycle-53357

05/26/2021, 1:43 PM
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

worried-city-86458

05/26/2021, 7:07 PM
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

bumpy-motorcycle-53357

05/27/2021, 2:01 PM
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.