Open LS80 opened 1 year ago
This issue has not received any attention in 1 year and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.
@iliapolo is this something for the upstream https://github.com/aws/jsii to fix or can it be fixed here?
Interesting. This however does work:
from constructs import Construct
from cdk8s import App, Chart
from imports import k8s
class MyChart(Chart):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)
k8s.KubePod(self, "pod",
metadata=k8s.ObjectMeta(name="pod-affinity"),
spec=k8s.PodSpec(
affinity=k8s.Affinity(
pod_anti_affinity=dict(
preferred_during_scheduling_ignored_during_execution=[
dict(
weight=100,
podAffinityTerm=dict(
labelSelector=dict(match_labels=dict(foo="bar")),
topologyKey="topology.kubernetes.io/zone"
)
)
]
)
),
containers=[
k8s.Container(
name="pod-affinity",
image="registry.k8s.io/pause:2.0"
)
],
)
)
app = App()
MyChart(app, "pod")
app.synth()
(Note the casing of properties inside the dict
)
It looks like case conversion doesn't happen for literal dictionaries. It kind of makes sense because there's no apparent reason a literal dictionary should go through case conversion. jsii would have to detect that dictionary is being in lieu of a struct, right now it just passes it through. Definitely a jsii issue, i'll check with the team and update here.
Thanks for reporting!
The following example produces a valid pod manifest
But using a dictionary in place of
k8s.WeightedPodAffinityTerm
produces an errorMissing required properties for k8s.WeightedPodAffinityTerm: 'podAffinityTerm'
.I assume it's an example of the issue discussed in https://github.com/aws/jsii/issues/1919 (Passing dicts in lieu of jsii structs does not consistently work).