Skip to content

Commit ff213e7

Browse files
committed
fix: unmarshaling of ServiceSpec in ServiceContainer struct
1 parent 3cda5cc commit ff213e7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pkg/api/container.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Container struct {
3030

3131
// CreatedTime returns the time when the container was created parsed from the Created field.
3232
func (c *Container) CreatedTime() time.Time {
33-
if c.created.IsZero() {
33+
if c.created.IsZero() && c.Created != "" {
3434
created, err := time.Parse(time.RFC3339Nano, c.Created)
3535
if err != nil {
3636
return time.Time{}
@@ -213,3 +213,24 @@ func (c *ServiceContainer) ConflictingServicePorts(ports []PortSpec) ([]PortSpec
213213

214214
return conflicting, nil
215215
}
216+
217+
// UnmarshalJSON implements custom unmarshalling for ServiceContainer to override the custom unmarshaler
218+
// of the embedded Container field.
219+
func (c *ServiceContainer) UnmarshalJSON(data []byte) error {
220+
// Unmarshal everything except Container into a temporary struct. Keep this in sync with ServiceContainer.
221+
var temp struct {
222+
ServiceSpec ServiceSpec
223+
}
224+
if err := json.Unmarshal(data, &temp); err != nil {
225+
return err
226+
}
227+
228+
// Let Container's UnmarshalJSON handle its part.
229+
if err := json.Unmarshal(data, &c.Container); err != nil {
230+
return err
231+
}
232+
233+
c.ServiceSpec = temp.ServiceSpec
234+
235+
return nil
236+
}

0 commit comments

Comments
 (0)