@@ -7,9 +7,11 @@ import (
77 "os"
88 "path/filepath"
99
10+ "github.com/containerd/platforms"
1011 "github.com/docker/docker/api/types/container"
1112 "github.com/docker/docker/api/types/mount"
1213 "github.com/docker/go-connections/nat"
14+ v1 "github.com/opencontainers/image-spec/specs-go/v1"
1315 "gopkg.in/yaml.v3"
1416
1517 "github.com/testcontainers/testcontainers-go"
@@ -180,15 +182,20 @@ func unmarshal(bytes []byte) (*KubeConfigValue, error) {
180182}
181183
182184func (c * K3sContainer ) LoadImages (ctx context.Context , images ... string ) error {
183- return c .LoadImagesWithOpts (ctx , images )
185+ return c .LoadImagesWithPlatform (ctx , images , nil )
184186}
185187
186- func (c * K3sContainer ) LoadImagesWithOpts (ctx context.Context , images []string , opts ... testcontainers. SaveImageOption ) error {
188+ func (c * K3sContainer ) LoadImagesWithPlatform (ctx context.Context , images []string , platform * v1. Platform ) error {
187189 provider , err := testcontainers .ProviderDocker .GetProvider ()
188190 if err != nil {
189191 return fmt .Errorf ("getting docker provider %w" , err )
190192 }
191193
194+ opts := []testcontainers.SaveImageOption {}
195+ if platform != nil {
196+ opts = append (opts , testcontainers .SaveDockerImageWithPlatforms (* platform ))
197+ }
198+
192199 // save image
193200 imagesTar , err := os .CreateTemp (os .TempDir (), "images*.tar" )
194201 if err != nil {
@@ -209,7 +216,15 @@ func (c *K3sContainer) LoadImagesWithOpts(ctx context.Context, images []string,
209216 return fmt .Errorf ("copying image to container %w" , err )
210217 }
211218
212- exit , reader , err := c .Exec (ctx , []string {"ctr" , "-n=k8s.io" , "images" , "import" , "--all-platforms" , containerPath })
219+ cmd := []string {"ctr" , "-n=k8s.io" , "images" , "import" }
220+
221+ if platform != nil {
222+ cmd = append (cmd , "--platform" , platforms .Format (* platform ))
223+ }
224+
225+ cmd = append (cmd , containerPath )
226+
227+ exit , reader , err := c .Exec (ctx , cmd )
213228 if err != nil {
214229 return fmt .Errorf ("importing image %w" , err )
215230 }
0 commit comments