@@ -115,6 +115,13 @@ def serialize_namedtuple(obj):
115
115
return obj
116
116
117
117
try :
118
+ # NOTE: you'll notice that there's a lot of get() accesses of state_data for
119
+ # pretty common fields - this is because ActionCommandConfig is used by more
120
+ # than one type of ActionRun (Kubernetes, Mesos, SSH) and these generally look
121
+ # different. Alternatively, some of these fields are used by KubernetesActionRun
122
+ # but are relatively new and older runs do not have data for them.
123
+ # Once we get rid of the SSH and Mesos code as well as older runs in DynamoDB,
124
+ # we'll likely be able to clean this up.
118
125
return json .dumps (
119
126
{
120
127
"command" : state_data ["command" ],
@@ -124,30 +131,35 @@ def serialize_namedtuple(obj):
124
131
"cap_add" : state_data ["cap_add" ],
125
132
"cap_drop" : state_data ["cap_drop" ],
126
133
"constraints" : [
127
- serialize_namedtuple (constraint ) for constraint in state_data [ "constraints" ]
134
+ serialize_namedtuple (constraint ) for constraint in state_data . get ( "constraints" , [])
128
135
], # convert each ConfigConstraint to dictionary, so it would be a list of dicts
129
136
"docker_image" : state_data ["docker_image" ],
130
137
"docker_parameters" : [
131
- serialize_namedtuple (parameter ) for parameter in state_data [ "docker_parameters" ]
138
+ serialize_namedtuple (parameter ) for parameter in state_data . get ( "docker_parameters" , [])
132
139
],
133
- "env" : state_data ["env" ],
134
- "secret_env" : {key : serialize_namedtuple (val ) for key , val in state_data ["secret_env" ].items ()},
135
- "secret_volumes" : [serialize_namedtuple (volume ) for volume in state_data ["secret_volumes" ]],
140
+ "env" : state_data .get ("env" , {}),
141
+ "secret_env" : {
142
+ key : serialize_namedtuple (val ) for key , val in state_data .get ("secret_env" , {}).items ()
143
+ },
144
+ "secret_volumes" : [serialize_namedtuple (volume ) for volume in state_data .get ("secret_volumes" , [])],
136
145
"projected_sa_volumes" : [
137
- serialize_namedtuple (volume ) for volume in state_data [ "projected_sa_volumes" ]
146
+ serialize_namedtuple (volume ) for volume in state_data . get ( "projected_sa_volumes" , [])
138
147
],
139
148
"field_selector_env" : {
140
- key : serialize_namedtuple (val ) for key , val in state_data [ "field_selector_env" ] .items ()
149
+ key : serialize_namedtuple (val ) for key , val in state_data . get ( "field_selector_env" , {}) .items ()
141
150
},
142
- "extra_volumes" : [serialize_namedtuple (volume ) for volume in state_data ["extra_volumes" ]],
143
- "node_selectors" : state_data ["node_selectors" ],
144
- "node_affinities" : [serialize_namedtuple (affinity ) for affinity in state_data ["node_affinities" ]],
145
- "labels" : state_data ["labels" ],
146
- "annotations" : state_data ["annotations" ],
147
- "service_account_name" : state_data ["service_account_name" ],
148
- "ports" : state_data ["ports" ],
151
+ "extra_volumes" : [serialize_namedtuple (volume ) for volume in state_data .get ("extra_volumes" , [])],
152
+ "node_selectors" : state_data .get ("node_selectors" , {}),
153
+ "node_affinities" : [
154
+ serialize_namedtuple (affinity ) for affinity in state_data .get ("node_affinities" , [])
155
+ ],
156
+ "labels" : state_data .get ("labels" , {}),
157
+ "annotations" : state_data .get ("annotations" , {}),
158
+ "service_account_name" : state_data .get ("service_account_name" ),
159
+ "ports" : state_data .get ("ports" , []),
149
160
"topology_spread_constraints" : [
150
- serialize_namedtuple (constraint ) for constraint in state_data ["topology_spread_constraints" ]
161
+ serialize_namedtuple (constraint )
162
+ for constraint in state_data .get ("topology_spread_constraints" , [])
151
163
],
152
164
}
153
165
)
0 commit comments