@@ -117,6 +117,31 @@ func checkConsistency(project *types.Project) error {
117117 s .Deploy .Replicas = s .Scale
118118 }
119119
120+ if s .CPUS != 0 && s .Deploy != nil {
121+ if s .Deploy .Resources .Limits != nil && s .Deploy .Resources .Limits .NanoCPUs .Value () != s .CPUS {
122+ return fmt .Errorf ("services.%s: can't set distinct values on 'cpus' and 'deploy.resources.limits.cpus': %w" ,
123+ s .Name , errdefs .ErrInvalid )
124+ }
125+ }
126+ if s .MemLimit != 0 && s .Deploy != nil {
127+ if s .Deploy .Resources .Limits != nil && s .Deploy .Resources .Limits .MemoryBytes != s .MemLimit {
128+ return fmt .Errorf ("services.%s: can't set distinct values on 'mem_limit' and 'deploy.resources.limits.memory': %w" ,
129+ s .Name , errdefs .ErrInvalid )
130+ }
131+ }
132+ if s .MemReservation != 0 && s .Deploy != nil {
133+ if s .Deploy .Resources .Reservations != nil && s .Deploy .Resources .Reservations .MemoryBytes != s .MemReservation {
134+ return fmt .Errorf ("services.%s: can't set distinct values on 'mem_reservation' and 'deploy.resources.reservations.memory': %w" ,
135+ s .Name , errdefs .ErrInvalid )
136+ }
137+ }
138+ if s .PidsLimit != 0 && s .Deploy != nil {
139+ if s .Deploy .Resources .Limits != nil && s .Deploy .Resources .Limits .Pids != s .PidsLimit {
140+ return fmt .Errorf ("services.%s: can't set distinct values on 'pids_limit' and 'deploy.resources.limits.pids': %w" ,
141+ s .Name , errdefs .ErrInvalid )
142+ }
143+ }
144+
120145 if s .ContainerName != "" {
121146 if existing , ok := containerNames [s .ContainerName ]; ok {
122147 return fmt .Errorf (`"services.%s": container name "%s" is already in use by "services.%s": %w` , s .Name , s .ContainerName , existing , errdefs .ErrInvalid )
0 commit comments