@@ -294,10 +294,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
294294 // but apply to the containers with the prefixed name
295295 s .SeccompProfilePath = opts .SeccompPaths .FindForContainer (opts .Container .Name )
296296
297- err = setupContainerResources (s , opts .Container )
298- if err != nil {
299- return nil , fmt .Errorf ("failed to configure container resources: %w" , err )
300- }
297+ setupContainerResources (s , opts .Container )
301298
302299 err = setupContainerDevices (s , opts .Container )
303300 if err != nil {
@@ -881,7 +878,7 @@ func makeHealthCheck(inCmd string, interval int32, retries int32, timeout int32,
881878 return & hc , nil
882879}
883880
884- func setupContainerResources (s * specgen.SpecGenerator , containerYAML v1.Container ) error {
881+ func setupContainerResources (s * specgen.SpecGenerator , containerYAML v1.Container ) {
885882 s .ResourceLimits = & spec.LinuxResources {}
886883 milliCPU := containerYAML .Resources .Limits .Cpu ().MilliValue ()
887884 if milliCPU > 0 {
@@ -892,15 +889,9 @@ func setupContainerResources(s *specgen.SpecGenerator, containerYAML v1.Containe
892889 }
893890 }
894891
895- limit , err := quantityToInt64 (containerYAML .Resources .Limits .Memory ())
896- if err != nil {
897- return fmt .Errorf ("failed to set memory limit: %w" , err )
898- }
892+ limit := quantityToInt64 (containerYAML .Resources .Limits .Memory ())
899893
900- memoryRes , err := quantityToInt64 (containerYAML .Resources .Requests .Memory ())
901- if err != nil {
902- return fmt .Errorf ("failed to set memory reservation: %w" , err )
903- }
894+ memoryRes := quantityToInt64 (containerYAML .Resources .Requests .Memory ())
904895
905896 if limit > 0 || memoryRes > 0 {
906897 s .ResourceLimits .Memory = & spec.LinuxMemory {}
@@ -913,8 +904,6 @@ func setupContainerResources(s *specgen.SpecGenerator, containerYAML v1.Containe
913904 if memoryRes > 0 {
914905 s .ResourceLimits .Memory .Reservation = & memoryRes
915906 }
916-
917- return nil
918907}
919908
920909const PodmanDeviceResourcePrefix = "io.podman/device"
@@ -1036,16 +1025,14 @@ func setupSecurityContext(s *specgen.SpecGenerator, securityContext *v1.Security
10361025 }
10371026}
10381027
1039- func quantityToInt64 (quantity * resource.Quantity ) ( int64 , error ) {
1028+ func quantityToInt64 (quantity * resource.Quantity ) int64 {
10401029 if i , ok := quantity .AsInt64 (); ok {
1041- return i , nil
1042- }
1043-
1044- if i , ok := quantity .AsDec ().Unscaled (); ok {
1045- return i , nil
1030+ return i
10461031 }
10471032
1048- return 0 , fmt .Errorf ("quantity cannot be represented as int64: %v" , quantity )
1033+ // Value() properly accounts for the decimal scale, unlike
1034+ // AsDec().Unscaled() which silently drops it.
1035+ return quantity .Value ()
10491036}
10501037
10511038// read a k8s secret in JSON/YAML format from the secret manager
0 commit comments