From ff213e71d3aa0ba6ba3167dfe1fa24f31ef58741 Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Fri, 22 Aug 2025 17:25:28 +1000 Subject: [PATCH] fix: unmarshaling of ServiceSpec in ServiceContainer struct --- pkg/api/container.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/api/container.go b/pkg/api/container.go index 9452644e..3f023794 100644 --- a/pkg/api/container.go +++ b/pkg/api/container.go @@ -30,7 +30,7 @@ type Container struct { // CreatedTime returns the time when the container was created parsed from the Created field. func (c *Container) CreatedTime() time.Time { - if c.created.IsZero() { + if c.created.IsZero() && c.Created != "" { created, err := time.Parse(time.RFC3339Nano, c.Created) if err != nil { return time.Time{} @@ -213,3 +213,24 @@ func (c *ServiceContainer) ConflictingServicePorts(ports []PortSpec) ([]PortSpec return conflicting, nil } + +// UnmarshalJSON implements custom unmarshalling for ServiceContainer to override the custom unmarshaler +// of the embedded Container field. +func (c *ServiceContainer) UnmarshalJSON(data []byte) error { + // Unmarshal everything except Container into a temporary struct. Keep this in sync with ServiceContainer. + var temp struct { + ServiceSpec ServiceSpec + } + if err := json.Unmarshal(data, &temp); err != nil { + return err + } + + // Let Container's UnmarshalJSON handle its part. + if err := json.Unmarshal(data, &c.Container); err != nil { + return err + } + + c.ServiceSpec = temp.ServiceSpec + + return nil +}